?? threadwxy02.java
字號:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class threadwxy02 extends JFrame implements ActionListener
{
JPanel pnlmain;
JButton but1,but2,but3,buta,butb,butc;
static JTextField field1,field2,field3,field;
Current ct1,ct2,ct3;
public threadwxy02()
{
super("08許方清");
pnlmain=new JPanel();
setContentPane(pnlmain);
but1=new JButton("掛起");
but2=new JButton("掛起");
but3=new JButton("掛起");
buta=new JButton("死亡");
butb=new JButton("死亡");
butc=new JButton("死亡");
but1.addActionListener(this);
but2.addActionListener(this);
but3.addActionListener(this);
buta.addActionListener(this);
butb.addActionListener(this);
butc.addActionListener(this);
field1=new JTextField("開啟");
field2=new JTextField("開啟");
field3=new JTextField("開啟");
field=new JTextField(20);
pnlmain.add(field1);
pnlmain.add(but1);
pnlmain.add(buta);
pnlmain.add(field2);
pnlmain.add(but2);
pnlmain.add(butb);
pnlmain.add(field3);
pnlmain.add(but3);
pnlmain.add(butc);
pnlmain.add(field);
ct1=new Current("線程1","NO1");
ct2=new Current("線程2","NO2");
ct3=new Current("線程3","NO3");
ct1.start();
ct2.start();
ct3.start();
setSize(250,150);
setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==but1)
{
if(ae.getActionCommand()=="掛起")
{
but1.setText("重啟");
ct1.suspend();
field1.setText("掛起");
}
if(ae.getActionCommand()=="重啟")
{
but1.setText("掛起");
ct1.resume();
field1.setText("啟動");
}
}
if(ae.getSource()==buta)
{
ct1.stop();
}
if(ae.getSource()==but2)
{
if(ae.getActionCommand()=="掛起")
{
but2.setText("重啟");
ct2.suspend();
field2.setText("掛起");
}
if(ae.getActionCommand()=="重啟")
{
but2.setText("掛起");
ct2.resume();
field2.setText("啟動");
}
}
if(ae.getSource()==butb)
{
ct2.stop();
}
if(ae.getSource()==but3)
{
if(ae.getActionCommand()=="掛起")
{
but3.setText("重啟");
ct3.suspend();
field3.setText("掛起");
}
if(ae.getActionCommand()=="重啟")
{
but3.setText("掛起");
ct3.resume();
field3.setText("啟動");
}
}
if(ae.getSource()==butc)
{
ct3.stop();
}
}
public static void main(String args[])
{
threadwxy02 td=new threadwxy02();
}
}
class Current extends Thread
{
// int n=0;
String strmsg,n;
public Current(String message,String a)
{
this.strmsg = message;
this.n = a;
// for(int i=1;i<0;i++)
// n=n+1;
}
public void run()
{
while(true)
{
try
{
this.sleep(1000);
this.sleep(1000);
System.out.println(strmsg+":"+n);
}
catch(InterruptedException e)
{JOptionPane.showMessageDialog(null,"錯誤");}
}
}
//private void getText(String string) {
// TODO Auto-generated method stub
//}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -