Originally posted by Jeannette Lundstedt:
I have created a very nice looking gui but the buttons don't work.
At line E you are checking for equality with the variable at line A, however that variable is never set to anything.
At line B you create a button (and assign it to a local variable that has the same name as, but is different from, the one at line A) and add a listener to it. But you never add this button to a container.
At line C you create another button (with the same text as, but different from, the one at line B) and add it to a container. It is this button you are seeing in your GUI, but this is not the button you added the listener to.
If you change line B to "option1 = new JButton("7 yrs at 5.35%");" without the "JButton" at the beginning, and you change line C to "panelb.add(option1);" then your listener will be called when the user presses the button.
Unfortunately, at line D your listener is calling getActionCommand(), not getSource(), so it is comparing the wrong object with 'option1' at line E. Either change line D to "Object source = e.getSource();" or change line E to "if (source.equals("7 yrs at 5.35%")) {" [but then the variable name 'source' is misleading] and then the code at line F will actually run when the user presses the button.
----
While I'm here, let me make some other comments:
(1) Usually you would call frame.pack() or frame.setSize(w, h) but not both.
(2) What's with the windowActivated() / windowClosed() / windowClosing() / exit() methods? Something like that would work if you declared to implement WindowListener and called addWindowListener(), but that's the hard way. The easy way is to call "frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);".