?? 4092446de45d001d1f9a82ee101a6d03
字號:
package notepad;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.*;
import javax.swing.*;
import java.util.*;
public class ThreadDemo extends JFrame implements ActionListener,Runnable {
JPanel pnlMain;
JButton btnStart,btnSleep,btnSuspend,btnExit;
JLabel lblTime;
Date date;
Thread thread;
GregorianCalendar gcCalendar;
public ThreadDemo()
{
thread=new Thread();
pnlMain=new JPanel(new FlowLayout());
btnStart=new JButton("開始");
btnSleep=new JButton("睡眠");
btnSuspend=new JButton("掛起");
btnExit=new JButton("結(jié)束");
lblTime=new JLabel("");
lblTime.setFont(new Font("宋體",Font.PLAIN,25));
lblTime.setForeground(Color.red);
date=new Date();
gcCalendar=new GregorianCalendar();
gcCalendar.setTime(date);
setContentPane(pnlMain);
pnlMain.add(lblTime);
pnlMain.add(btnStart);
pnlMain.add(btnSleep);
pnlMain.add(btnSuspend);
pnlMain.add(btnExit);
this.setSize(200,150);
this.setVisible(true);
this.setResizable(false);
this.setDefaultCloseOperation(2);
//組件事件
btnStart.addActionListener(this);
btnSleep.addActionListener(this);
btnSuspend.addActionListener(this);
btnExit.addActionListener(this);
}
public void run()
{
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
Object o=e.getSource();
if(o==btnStart)
{
thread.start();
}
if(o==btnSleep)
{
while(thread!=null)
{
try
{
thread.sleep(1000);
}
catch(InterruptedException ie)
{
JOptionPane.showMessageDialog(null, "線程出錯(cuò)");
}
}
}
if(o==btnSuspend)
{
thread.suspend();
}
if(o==btmExit)
thread.stop();
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -