import javax.swing.*;
import java.awt.*; // for BorderLayout
class Graphics04 {
public static void main(String[] args) {
SimpleFrame frame = new SimpleFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel pane = new JPanel();
JButton button1 = new JButton("Click Me!");
pane.add(button1);
JButton button2 = new JButton("Click Me Too!");
pane.add(button2);
frame.getContentPane().add(pane);
JLabel label = new JLabel("Hi there!");
frame.getContentPane().add(label,BorderLayout.SOUTH);
frame.show();
}
}
class SimpleFrame extends JFrame {
public SimpleFrame() {
setTitle("Graphics04");
setSize(300, 200);
}
}
javac Graphics04.java
结果有六个错误:
Graphics04.java:3: Can't find default package `javax.swing'. Check the CLASSPATH environment variable and the access to the archives
Graphics04.java:10: Type `JPanel' not found in the declaration of the local variable `pane'.
JPanel pane = new JPanel();
^
Graphics04.java:11: Type `JButton' not found in the declaration of the local variable `button1'.
JButton button1 = new JButton("Click Me!");
^
Graphics04.java:13: Type `JButton' not found in the declaration of the local variable `button2'.
JButton button2 = new JButton("Click Me Too!");
^
Graphics04.java:16: Type `JLabel' not found in the declaration of the local variable `label'.
JLabel label = new JLabel("Hi there!");
^
Graphics04.java:22: Superclass `JFrame' of class `SimpleFrame' not found.
class SimpleFrame extends JFrame {
^
6 errors