it tells me I cannot set a static reference to a non static method dispose
Sounds like there may be trouble with a static modifier somewhere.
I would want to look at the exact exception wording.
If I mistakenly capitalized the "frame" reference, viz,
Frame.dispose(); then I'd get this compile error:
C:\jexp>javac test.java
test.java:12: non-static method dispose() cannot be referenced from a static context
Frame.dispose();
^
1 error
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test {
JFrame frame;
public Test() {
JButton button = new JButton("exit");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
frame.dispose();
}
});
JPanel panel = new JPanel();
panel.add(button);
frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(panel);
frame.pack();
frame.setLocation(200,200);
frame.setVisible(true);
}
public static void main(String[] args) {
new Test();
}
}