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

📄 actioneventdemo.java

📁 里面所含源码是本人平时做程序的一些实例
💻 JAVA
字号:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class ActionEventDemo extends JFrame implements ActionListener
{
	JButton btnFirst,btnSecond;
	JPanel pnlMain;
	JLabel lblInfo;
	public ActionEventDemo()
	{
		pnlMain=new JPanel();
		btnFirst=new JButton("隐藏按钮1");
		btnFirst.addActionListener(this);
		btnSecond=new JButton("禁用按钮2");
		btnSecond.addActionListener(this);
		lblInfo=new JLabel("");
		setContentPane(pnlMain);
		pnlMain.add(btnFirst);
		pnlMain.add(btnSecond);
		pnlMain.add(lblInfo);
		setSize(250,150);
		setTitle("动作事件演示");
		setVisible(true);
	} 
	public void actionPerformed(ActionEvent ae)
	{
		if(ae.getSource()==btnFirst)
		{
			btnFirst.setVisible(false);
			btnSecond.setEnabled(true);
			lblInfo.setText(ae.getActionCommand());
		}
		if(ae.getSource()==btnSecond)
		{
			btnFirst.setVisible(true);
			btnSecond.setEnabled(false);
			lblInfo.setText("按钮2不可用");
		}
	}
	public static void main(String args[])
	{
		new ActionEventDemo();
	}
}

⌨️ 快捷键说明

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