I am having some difficulty understanding GUIs and why my program won\'t run properly. Is it because I have to extend to a JFrame class? Here is a code:
import j
Wow... OK, first, ActionListener
is spelled incorrectly as "ActionListner
." Look very closely at the spelling of those words. Simple typographical errors generate syntax errors.
The rest of your problems boil down to this very simple caveat: order matters. Your order should be as follows:
1) declare and create objects; 2) declare and create all dependent objects; 3) configure objects; 4) manipulate objects.
That means that your code:
frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
frame.setTitle("Richter Scale");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
JFrame frame = new JFrame();
Won't work because you're trying to mess with a frame that hasn't yet been created. Create it first, like so:
JFrame frame = new JFrame();
frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
frame.setTitle("Richter Scale");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
Same holds true for your label and your button.
JLabel rictherlabel = new JLabel ("Ricther: ");
needs to come before
panel.add(label);