Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GUI buttons visible but not functional?

 
Rachel Barnes
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15288
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rachel Barnes
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48981
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic