• Post Reply Bookmark Topic Watch Topic
  • New Topic

How To Handle events for a list  RSS feed

 
Conrad McLaughlin
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm new to java. not sure if this should be in beginners section.

How do you handle events for a list? If I have for example two items in a list and I want a system output for the item I have selected how do I do that?

This is part of the code that compiles and I see the list in Jframe:





How do I write code so it says "Message 1 selected" or "Message 2"?
Do I use Action events? How?
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using Swing or the old AWT? (You mention JFrame but them use java.awt.List instead of javax.swing.JList.) In the Swing case, you may find this part of the Swing tutorial helpful:

http://java.sun.com/docs/books/tutorial/uiswing/events/listselectionlistener.html
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!