aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes GUI buttons visible but not functional? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "GUI buttons visible but not functional?" Watch "GUI buttons visible but not functional?" New topic
Author

GUI buttons visible but not functional?

Rachel Barnes
Greenhorn

Joined: Oct 28, 2012
Posts: 11
Everything appears to be in place and with no errors while open in Eclipse. When I run the program though, it will only let me select ONE of the options on the checkbox buttons, and also the calculate and exit buttons are not working. Where exactly have I gone wrong with this? My instructor mentioned something about making the calculate/exit buttons NOT static, but if I do that, it won't even run and errors pop up everywhere, so I'm pretty confused. The following is the last point where I had no errors, yet had the button issue. All of my other attempts at trying different fixes kind of broke everything, so this is the functional version.



Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14269
    
  21

Your CalcButtonListener and ExitButtonListener are ItemListeners. Make these ActionListeners instead, if you want to do something when the buttons are clicked.

In lines 235 and 236, use addActionListener instead of addItemListener to add the listeners to the buttons.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Rachel Barnes
Greenhorn

Joined: Oct 28, 2012
Posts: 11
Jesper de Jong wrote:Your CalcButtonListener and ExitButtonListener are ItemListeners. Make these ActionListeners instead, if you want to do something when the buttons are clicked.

In lines 235 and 236, use addActionListener instead of addItemListener to add the listeners to the buttons.



I changed those and it's still performing no action when I try to click them.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39409
    
  28
Also I have removed some of the blank space from your code; too much blank space makes it difficult to read. Don’t use tabs. Have a look at our suggestions about indentation.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
you create your buttons in buildButtonPanel
calcButton = new JButton("Calculate");
exitButton = new JButton("Exit");
and add (now) actionListeners to them.

but then in the constructor of autoMaintenanceSvcCalc() you re-create the buttons
serviceCalculatorGUI.calcButton = new JButton("Calculate");
serviceCalculatorGUI.exitButton = new JButton("Exit");

these buttons do not have a listener added to them

comment out the lines
//serviceCalculatorGUI.calcButton = new JButton("Calculate");
//serviceCalculatorGUI.exitButton = new JButton("Exit");
and in the constructor of serviceCalculatorGUI() move
buildButtonPanel();
to before
mainPanel = new autoMaintenanceSvcCalc();

should work now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GUI buttons visible but not functional?