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

📄 actioneventdemo.java

📁 学习参考,java基本语法练习,包括一些常用的技巧
💻 JAVA
字号:
//动作事件演示程序
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
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("按钮1不可见!");
			}
			
		if (ae.getSource()==btnSecond)
			{
				btnFirst.setVisible(true);
				btnSecond.setEnabled(false);
				lblInfo.setText("按钮2不可用!");
			}
	}
	public static void main(String []args)
	{
		ActionEventDemo ad=new ActionEventDemo();
	}
}

⌨️ 快捷键说明

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