📄 guiframe.java
字号:
import java.awt.*;
import java.awt.event.*;
public class GUIFrame extends Frame implements ActionListener
{
Label label;
Button redButton;
Button greenButton;
public GUIFrame(String strTitle)
{
super(strTitle);
setLayout(new FlowLayout());
label=new Label("please choice one button.");
redButton=new Button("red");
greenButton=new Button("green");
add(label);
add(redButton);
add(greenButton);
redButton.addActionListener(this);
greenButton.addActionListener(this);
pack();
show();
}
public static void main(String args[])
{
GUIFrame frameDemo=new GUIFrame("This is the first GUI application program.");
frameDemo.addWindowListener(new WindowAdapter(){
public void windowsClosing(WindowEvent e)
{
System.exit(0);}
});
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==redButton){label.setText("you have press the red button");}
else{label.setText("you have press the green button");}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -