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() );
}
}
}