Hi all,
I am trying to learn java here, and having some difficulties with a very simple program that I am working on in an attempt to get a feel for what the language can do. This is my code so far:
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test extends JFrame{
public static void main(String[] args){
JFrame box = new JFrame();
box.setTitle("Week1 test");
box.setSize(240,240);
box.setVisible(true);
box.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel label = new JLabel("Hello World");
label.setSize(160,160);
label.setVisible(true);
box.add(label);
JButton B1 = new JButton("Exit");
B1.setVisible(true);
box.add(B1);
box.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.Exit(0);}
});}}
Unfortunately, whenever I try to compile this in the Windows 7 command prompt, it comes back with a confusing error messages claiming that it cannot find symbol. The exact errors I am getting is:
Test.java:22: error: cannot find symbol
> System.Exit();}
> ^
> symbol: method Exit(int)
> location: class System
>
> Test.java:20: error: cannot find symbol
> box.addActionListener(new ActionListener(){
> ^
> symbol: method addActionListener((anonymous ActionListener))
> location: variable box of type JFrame
> I was under the impression that both of these, System.Exit(), and addActionListener(), were imported with javax.swing.*;
Was I mistaken in that assumption?? Please explain what is wrong here to me, so I can continue to get more understanding of java, and thanks in advance!!