guiframe.java

来自「这是一个简单的java 程序。适合于刚开始接触java 编程的初学者看的程序。」· Java 代码 · 共 42 行

JAVA
42
字号
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 + =
减小字号Ctrl + -
显示快捷键?