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

📄 ch11.java

📁 里面所含源码是本人平时做程序的一些实例
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class ch11 extends JFrame implements ActionListener,Runnable{
	JPanel pnlMain;
	JLabel lblThread1,lblThread2,lblThread3;
	JButton btnControl1,btnControl2,btnControl3;
	Thread thdDisplay1,thdDisplay2,thdDisplay3;
	public ch11(){
		super(" 接口Runnable类线程演示");
		pnlMain=new JPanel(new GridLayout(2,3));
		setContentPane(pnlMain);
		lblThread1=new JLabel("挂起");
		lblThread2=new JLabel("挂起");
		lblThread3=new JLabel("挂起");
		lblThread1.setForeground(Color.RED);
		lblThread2.setForeground(Color.RED);
		lblThread3.setForeground(Color.RED);
		btnControl1=new JButton("挂起");
		btnControl2=new JButton("挂起");
		btnControl3=new JButton("挂起");
		
		thdDisplay1=new Thread();
		thdDisplay2=new Thread();
		thdDisplay3=new Thread();
		btnControl1.addActionListener(this);
		btnControl2.addActionListener(this);
		btnControl3.addActionListener(this);
		pnlMain.add(lblThread1);
		pnlMain.add(lblThread2);
		pnlMain.add(lblThread3);
		pnlMain.add(btnControl1);
		pnlMain.add(btnControl2);
		pnlMain.add(btnControl3);
		thdDisplay1.start();
		thdDisplay2.start();
		thdDisplay3.start();
		setSize(300,250);
		setVisible(true);
		setResizable(false);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
	}
	public void actionPerformed(ActionEvent ae){
		try{
			if(ae.getSource()==btnControl1){
				if(ae.getActionCommand()=="挂起"){
					btnControl1.setText("重启");
					lblThread1.setText("重启");
					
					thdDisplay1.suspend();
				}
				if(ae.getActionCommand()=="重启"){
					btnControl1.setText("挂起");
					lblThread1.setText("挂起");
					thdDisplay1.resume();	
				}
			}
			if(ae.getSource()==btnControl2){
				if(ae.getActionCommand()=="挂起"){
					btnControl2.setText("重启");
					lblThread2.setText("重启");
					thdDisplay2.suspend();
				}
				if(ae.getActionCommand()=="重启"){
					btnControl2.setText("挂起");
					lblThread2.setText("挂起");
					thdDisplay2.resume();	
				}
			}
			if(ae.getSource()==btnControl3){
				if(ae.getActionCommand()=="挂起"){
					btnControl3.setText("重启");
					lblThread3.setText("重启");
					thdDisplay3.suspend();
				}
				if(ae.getActionCommand()=="重启"){
					btnControl3.setText("挂起");
					lblThread3.setText("挂起");
					thdDisplay3.resume();	
				}
			}
		}
		catch(Exception e){
			JOptionPane.showMessageDialog(null,"线程错误!");
		}
	}
	public static void main(String args[]){
		ch11 t=new ch11();
	}
	public void run(){}
}

⌨️ 快捷键说明

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