Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Urgent listener registration problem

807606May 17 2007 — edited May 17 2007
Hi all,
I'm trying to register listeners to a JCheckBox and a JButton, but for some reason neither of them respond, even though they're registered and their methods are implemented. I tried out a print statement, and they never even enter the methods. Please help ASAP! Thanks!

Jezzica85
Container mycontainer = frame.getContentPane();
		mycontainer.setLayout( new BorderLayout());
		JPanel panel1 = new JPanel();
		JPanel panel2 = new JPanel();
		JPanel panel3 = new JPanel( new GridLayout( 0,5 ));

		submit = new JTextField( 20 );
		choice = prompt;

		for( int i = 0; i < labels.size(); i++ ) {
			if( !labels.get( i ).equals( prompt ) ) {
				JCheckBox box = new JCheckBox( labels.get( i ) );
				box.addItemListener( new BoxListener() );
				panel3.add( box );
			}
		}

		JLabel inst = new JLabel();
		if( prompt.equals( "Probe Set ID" ) ) {
			inst = new JLabel( "Please enter the probe set and the desired information." );
		} else if ( prompt.equals( "Gene Symbol" ) ) {
			inst = new JLabel( "Please enter the gene symbol and the desired information." );
		}

		panel2.add( inst );
		panel2.add( submit );

		JButton submitb = new JButton("Submit");
		submitb.addActionListener( new ButtonListener() );
		panel1.add( submitb );

// These are internal classes, just here to show you the methods
class ButtonListener implements ActionListener {
		public ButtonListener() {}
		
		public void actionPerformed( ActionEvent e ) {
			String command = e.getActionCommand();

			if( command.equalsIgnoreCase( "submit" ) ) {
				Database.acquireKey( submit.getText() );
				Database.acquireOptions( options, choice );
				results = db.runQueries();
			}
		}
	}

	class BoxListener implements ItemListener {
		public BoxListener() {}
		
		public void itemStateChanged( ItemEvent i ) {
			Object source = i.getItemSelectable();
			if( i.getStateChange() == ItemEvent.SELECTED ) {
				options.add( ((JCheckBox)source).getText() );
				System.out.println( options );
			} else if( i.getStateChange() == ItemEvent.DESELECTED ) {
				options.remove( ((JCheckBox)source).getText() );
			}
		}
	}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 14 2007
Added on May 17 2007
17 comments
69 views