?? sample27_1.java
字號:
package wyf.jc;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//定義該類繼承自JFrame
public class Sample27_1 extends JFrame implements ActionListener
{
//創建按扭
JButton jb=new JButton("按扭");
//創建文本框
JTextField jtf=new JTextField("點擊按扭執行事件處理代碼");
public Sample27_1()
{
//為按扭注冊監聽器
jb.addActionListener(this);
//設置文本框的可編輯性
jtf.setEditable(false);
//將按扭與文本框添加進窗體
this.add(jtf,BorderLayout.NORTH);
this.add(jb);
//設置窗體的關閉動作、標題、大小位置以及可見性
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("存在問題的程序");
this.setBounds(100,100,500,200);
this.setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{
//執行大業務量的計算
for(long i=0;i<10000000000L;i++)
{
Math.sqrt(i);
}
//設置文本框顯示的內容
jtf.setText("按扭觸發的事件處理代碼執行完畢");
}
public static void main(String[] args)
{
//創建Sample27_1窗體對象
new Sample27_1();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -