myfirstframe.java

来自「是一个综合开发程序,可以做为系统研究人员的参考」· Java 代码 · 共 42 行

JAVA
42
字号
import java.awt.*;
import java.awt.event.*;
public class myfirstframe {
	static Frame frm = new Frame("this is my first Frame");
   static Button but = new Button("Exit");
    static Button but1 = new Button("o k");
	public static void main(String[] args){


	Panel pel= new Panel();
	Panel pel2 =new Panel();
		FlowLayout flow =new FlowLayout(FlowLayout.LEFT);
		frm.setLayout(flow);
		frm.setSize(300,300);
		Label lab =new Label("liang");
		Label lab2 =new Label("myfirstframe");
		Label lab3=new Label("my name is liangdingshi");
		frm.add(lab3);
		pel.setLayout(flow);
		pel2.setLayout(flow);
		pel.add(but);
		pel.add(lab);
		pel2.add(but1);
		pel2.add(lab2);
		frm.add(pel);
		frm.add(pel2);
		but.addActionListener(new actionl());
		but1.addActionListener(new actionl());
		frm.setVisible(true);
	}
 static class actionl implements ActionListener{
		public void actionPerformed(ActionEvent e){
			Button but3 =(Button)e.getSource();
			if (but3==but)
		System.exit(0);
			else
		frm.setBackground(Color.yellow);
	}

}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?