




已阅读5页,还剩1页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
import java.awt.*;import java.awt.event.*;import javax.swing.*;public class CZFrame extends JFrame implements ActionListenerCZThread 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.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)tryif(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)tryif(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)elsetryif(thread3.st=0) thread3.suspend(); thread3.st=1; wait3.setText(执行); thread1.num-; else thread3.resume(); thread3.st=0; wait3.setText(等待); thread1.num+;catch(Exception e1)public static void main(String args)int n1=0,n2=1,n3=2;CZFrame frame=new CZFrame(n1,n2,n3);frame.setDefaultCloseOperation(EXIT_ON_CLOSE);frame.show();class CZThread extends ThreadCZPanel panel;int st=0;static int num=3;public CZThread(int n)panel=new CZPanel(n);panel.setBounds(0,130+n*100,380,60);public void S()public void run()trywhile(true)while(panel.m=20&panel.flag=1)panel.repaint();sleep(20*num); panel.m=20;panel.flag=0;catch(Exception e)private class CZPanel extends JPanel public CZPanel(int n)this.n=n;public void paintComponent(Graphics g)super.paintComponent(g);g.setColor(Color.white);g.fillRect(20,0,359,59);g
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025标准合同文本下载
- 2025职位聘用合同模板
- 电脑知识网络培训课件
- 药品继续教育考试题及答案-知识题库
- 电脑焊接专业知识培训班课件
- 电脑信息化知识培训课件
- 2025年云计算工程师考试专项训练试卷:云平台架构与运维解析
- 第二节 化学与材料研制说课稿-2025-2026学年初中化学鲁教版五四学制2013九年级全一册-鲁教版五四学制2012
- 区域经理腐败管理问题解决之道x
- 第二单元第10课六、《编写简单的代码》说课稿 2024-2025学年人教版初中信息技术八年级上册
- 普通高中体育与健康课程标准
- MOOC 理性思维实训-华南师范大学 中国大学慕课答案
- 《陆上风电场工程设计概算编制规定及费用标准》(NB-T 31011-2019)
- 腾讯组织管理手册
- 《燕麦片营养调查》课件
- 四川大学有机化学习题
- 中药饮片采购和验收和保管和调剂培训课件
- 网络运维从入门到精通29个实践项目详解
- 无人机驾驶员培训计划及大纲
- 手术室超声气压弹道碎石系统操作规程
- 换门施工方案
评论
0/150
提交评论