public static void main(String args[]){ JFrame f=new JFrame("JFrame Example"); Container c=f.getContentPane(); c.setLayout( new FlowLayout()); c.add(new JLabel("这是一个JFrame的一般示例!")); f.setSize(300,70); f.show();
f.addWindowLister(new WindowAdapter(){
public void windowClosing(WindowEvent e){ System.exit(0); }
});
} }
编译结果如下: FrameTester.java:1: package javax.Swing does not exist import javax.Swing.*; ^ FrameTester.java:8: cannot resolve symbol symbol : class JFrame location: class FrameTester JFrame f=new JFrame("JFrame Example"); ^ FrameTester.java:8: cannot resolve symbol symbol : class JFrame location: class FrameTester JFrame f=new JFrame("JFrame Example"); ^ FrameTester.java:11: cannot resolve symbol symbol : class JLabel location: class FrameTester c.add(new JLabel("这是一个JFrame的一般示例!")); ^ 4 errors