Groovy Swing builder Flickr example


/ Published in: Groovy
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.