shiyan7_1.java

来自「java例子」· Java 代码 · 共 62 行

JAVA
62
字号

import java.awt.*;
import java.awt.event.*;
public class Shiyan7_1
{
	public static void main(String[] args) 
	{
		myframe my=new myframe();
		my.setVisible(true);
	}
}
class myframe extends Frame implements ActionListener
{
	private Button But1,But2;
	public Label Lab1;
	int button=0;
	
	public myframe()
	{
		super("我的窗口");
		setSize(500,500);
		But1=new Button("按钮1");
		But2=new Button("按钮2");
		Lab1=new Label("                         ");
		setLayout(new FlowLayout());
		add(But1);
		add(But2);
		add(Lab1);
		
		
		But1.addActionListener(this);
		But2.addActionListener(this);
		//setVisible(true);
		
	}
	
	public void paint(Graphics g)
	{
		if(button==1)
			Lab1.setText("您按了按扭一");
			else if (button==2)
				Lab1.setText("您按了按扭二");
			

			
	}




	public void actionPerformed(ActionEvent e)
	{
		if(e.getActionCommand().equals("按钮1"))
		button=1;
		if(e.getActionCommand().equals("按钮2"))
		button=2;
		repaint();
	}

}

⌨️ 快捷键说明

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