Results 1 to 4 of 4
- 11-24-2008, 02:27 AM #1
Member
- Join Date
- Nov 2008
- Posts
- 4
- Rep Power
- 0
event handler not working properly
this is not all the code, theres about 7 different files to post so this wont compile on its own. However, the gui appeared properly with the list and the select button is next to the list like it should. However, when I press select it will not print out "U pressed the button". Why wont it work?Java Code:import java.awt.FlowLayout; import java.awt.*; import java.awt.event.*; import javax.swing.JFrame; import javax.swing.JList; import javax.swing.JButton; import javax.swing.JScrollPane; import javax.swing.ListSelectionModel; public class Hw4AtfDepartmentList extends JFrame { private JList names; private JButton selectJButton; private final String departmentNames[] = { "CSE", "EE", "Physics", "Biology" }; public Hw4AtfDepartmentList( Hw4AtfDepartment department ) { super( "Department Names" ); setLayout( new FlowLayout() ); names = new JList( departmentNames ); names.setVisibleRowCount( 4 ); names.setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); add( new JScrollPane( names ) ); selectJButton = new JButton( "Select" ); selectJButton.addActionListener( new ActionListener() { public void actionPerformed ( ActionEvent event ) { System.out.println( "U pressed the button" ); } } ); add(selectJButton); } }
-
You have a bug, but I don't see the bug in the code posted above. It makes me wonder when you pass an array of this class to itself in its constructor. Could you have multiple instances of this class in your program, one shadowing the other?
- 11-24-2008, 02:37 AM #3
Member
- Join Date
- Nov 2008
- Posts
- 4
- Rep Power
- 0
Its not passing it's self. The class names are different. One has list at the end.
-
Similar Threads
-
JList and JButton event handler not working
By H3rtaherta in forum AWT / SwingReplies: 3Last Post: 11-22-2008, 12:00 AM -
Menu item not working properly for mouse events
By Preethi in forum New To JavaReplies: 1Last Post: 09-23-2008, 08:56 AM -
My code is not working properly ..modify it
By Shyam Singh in forum New To JavaReplies: 14Last Post: 07-16-2008, 05:48 PM -
Log4j not working properly....
By prakash_dev in forum Advanced JavaReplies: 0Last Post: 03-17-2008, 12:13 PM -
Help with Handler
By baltimore in forum AWT / SwingReplies: 1Last Post: 08-04-2007, 09:42 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks