Skip to Main Content

Java SE (Java Platform, Standard Edition)

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!

ActionListener / Event help

843806May 29 2007 — edited May 30 2007
Hi all, I'm a first year comp engineering major and am having some issues with a program I am writing. Hope someone can help....

I am writing a GUI program and need to catch the user action when a certain button is clicked. I have set up all the ActionListeners and ActionEvents however I am not sure how to write the "doButtonClicked" methods for them. I need help in creating such a method for both a JButton and a JComboBox.

Here is my code, can anyone please help. Thanks in advance.

Code for JButton (need help writing -
private void doIterateButtonClicked(int numIterations) method) :
JButton iterateOne = new JButton("Iterate Once"); //Iterate once button
    	  	iterateOne.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e){
    		doIterateButtonClicked(1);
    		}
    	});
Code for JComboBox
(need help writing - doThresholdChanged(JComboBox comboBox) method):
        JComboBox choices = new JComboBox(THRESHOLDS); //Thresholds selection box
    	choices.setSelectedIndex(0);
    	choices.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e){
    			doThresholdChanged((JComboBox)e.getSource());
    		}
    	});
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 27 2007
Added on May 29 2007
4 comments
114 views