⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shiyan7_1.java

📁 java例子
💻 JAVA
字号:

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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -