红色部分:第一次运行时不动 第二次运行时 红色部分修改为 private Labell=new Label();观察结果 (比较 点下File时的变化。)
import java.awt.*;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
public class Java_frist extends JFrame {
private JMenuBar mb = new JMenuBar();
private JMenu mm = new JMenu("File");
private JMenuItem mi1 = new JMenuItem("复制");
private JMenuItem mi2 = new JMenuItem("粘贴");
private JLabel l = new JLabel();
public Java_frist() {
this.setLayout(null);
mm.add(mi1);
mm.add(mi2);
mb.add(mm);
this.setJMenuBar(mb);
l.setText("werwe");
l.setBounds(10, 10, 450, 30);
this.add(l);
this.setBounds(330, 250, 500, 150);
this.setVisible(true);
}
public static void main(String args[]) {
Java_frist java_frist = new Java_frist();
}
import java.awt.*;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
public class Java_frist extends JFrame {
private JMenuBar mb = new JMenuBar();
private JMenu mm = new JMenu("File");
private JMenuItem mi1 = new JMenuItem("复制");
private JMenuItem mi2 = new JMenuItem("粘贴");
private JLabel l = new JLabel();
public Java_frist() {
this.setLayout(null);
mm.add(mi1);
mm.add(mi2);
mb.add(mm);
this.setJMenuBar(mb);
l.setText("werwe");
l.setBounds(10, 10, 450, 30);
this.add(l);
this.setBounds(330, 250, 500, 150);
this.setVisible(true);
}
public static void main(String args[]) {
Java_frist java_frist = new Java_frist();
}
}
AWT是Swing的基础 Swing是建立在AWT1.1的基础上的。
Swing比AWT提供的控件数量丰富