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

📄 firstapplet.java

📁 国外的数据结构与算法分析用书
💻 JAVA
字号:
import java.awt.*; // graphical classes
import java.awt.event.*; // event classes

/**	An applet that contains two buttons and a text field.  When the buttons
	on the screen are clicked, the value in the text field changes accordingly. */
public class FirstApplet extends java.applet.Applet implements ActionListener
{
	Button countBtn, resetBtn;
	int counter = 0;
	TextField counterFld;

	public void init()
	{
		setLayout(new FlowLayout(FlowLayout.CENTER)); // how items will be laid out
		countBtn = new Button("Click Me!");
		resetBtn = new Button("Reset");
		counterFld = new TextField("0", 4);
		
		/*	Indicate who will handle events. */
		countBtn.addActionListener(this);
		resetBtn.addActionListener(this);

		/*	Add components to display. */
		add(countBtn);
		add(counterFld);
		add(resetBtn);
	}

	/**	This method is what is called when the buttons are clicked. */ 
	public void actionPerformed(ActionEvent ae)
	{
		if(ae.getSource() == countBtn) // count button clicked
			counter++;
		else
			counter = 0;
		counterFld.setText(counter + ""); // update text field
	}
}

⌨️ 快捷键说明

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