Java进程并发演示模型.docxVIP

  • 36
  • 0
  • 约3.36千字
  • 约 6页
  • 2016-12-21 发布于北京
  • 举报
进程并发演示模型一 实验截图二 代码import java.awt.*;import java.awt.event.*;import javax.swing.*;public class CZFrame extends JFrame implements ActionListener{CZThread thread1,thread2,thread3;JButton wait1=new JButton(等待),wait2=new JButton(等待),wait3=new JButton(等待 );JButton exit=new JButton(退出);JLabel name=new JLabel(作者:田毛毛);public CZFrame(int n1,int n2,int n3){setTitle(进程并发演示模型);setSize(500,550);setVisible(true);thread1=new CZThread(n1);thread2=new CZThread(n2);thread3=new CZThread(n3);Container container=getContentPane();container.setBackground(Color.pink);container.setLayout(null);container.add(thread1.panel);container.add(thread2.panel);container.add(thread3.panel);wait1.setBounds(400,150,70,30);wait2.setBounds(400,250,70,30);wait3.setBounds(400,350,70,30);exit.setBounds(200,450,70,30);container.add(wait1);container.add(wait2);container.add(wait3);container.add(exit);wait1.addActionListener(this);wait2.addActionListener(this);wait3.addActionListener(this);exit.addActionListener(this);JLabel label=new JLabel(进程并发演示模型);Font font=new Font(宋体,Font.BOLD,16);label.setFont(font);label.setBounds(175,20,180,50);container.add(label);name.setBounds(400,40,100,50);container.add(name);thread1.start();thread2.start();thread3.start();}public void actionPerformed(ActionEvent e){Object s=e.getSource();if(s==exit){/*thread1.suspend();thread2.suspend();thread3.suspend();*/int i=JOptionPane.showConfirmDialog(null,确认退出吗?,退出,JOptionPane.YES_NO_OPTION); if(i==0) System.exit(0); /*thread1.resume();thread2.resume();thread3.resume();*/}else if(s==wait1){try{if(thread1.st==0) { thread1.suspend(); thread1.st=1; wait1.setText(执行); thread1.num--; }else { thread1.resume(); thread1.st=0; wait1.setText(等待); thread1.num++;}}catch(Exception e1){}}else if(s==wait2){try{if(thread2.st==0) { thread2.suspend(); thread2.st=1; wait2.setText(执行); thread1.num--; }else { thread2.resume(); thread2.st=0; wait2.setText(等待); thread1.num++;}}catch(Exception e1){

文档评论(0)

1亿VIP精品文档

相关文档