We Recommend

Smarty PHP Template Programming And Applications Smarty PHP Template Programming And Applications
Smarty is a templating engine for PHP. Designers who are used to working with HTML files can work with Smarty templates, which are HTML files with simple tags while programmers work with the underlying PHP code. The Smarty engine brings the code and templates together. The result of all this is that designers can concentrate on designing, programmers can concentrate on programming, and they don't need to get in each others way so much.


Posted By

dima767 on 03/08/07


Tagged

flickr groovy


Versions (?)


Groovy Swing builder Flickr example


Published in: Groovy 


  1. // copyright Dierk Koenig 2006
  2.  
  3. import groovy.swing.SwingBuilder
  4. import javax.swing.*
  5.  
  6. key = 'your-flickr-key-here'
  7. counter = 1
  8.  
  9. def updateButton(button) {
  10. counter++
  11. def apiUrl = "http://www.flickr.com/services/rest/?" +
  12. "method=flickr.interestingness.getList&per_page=1&" +
  13. "page=$counter&api_key=$key"
  14. def rsp = new XmlParser().parse(apiUrl)
  15. def photo = rsp.photos.photo[0]
  16. def imageUrl = "http://static.flickr.com/" +
  17. "${photo.'@server'}/${photo.'@id'}_${photo.'@secret'}_m.jpg"
  18. button.icon = new ImageIcon(imageUrl.toURL())
  19. button.text = photo.'@title'
  20. return button
  21. }
  22.  
  23. def frame = new SwingBuilder().frame(
  24. title: 'Groovy Flickr Viewer',
  25. defaultCloseOperation: WindowConstants.EXIT_ON_CLOSE) {
  26. updateButton( button (
  27. horizontalTextPosition: SwingConstants.CENTER,
  28. verticalTextPosition: SwingConstants.BOTTOM,
  29. actionPerformed: { updateButton(it.source) }
  30. ))
  31. }
  32. frame.pack()
  33. frame.show()

Report this snippet 

You need to login to post a comment.