thred.rar

  • PUDN用户
    了解作者
  • Java
    开发工具
  • 12KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 2
    下载次数
  • 2008-12-12 07:58
    上传日期
关于java的县城源代码,提款机模拟,生产者与消费者原理
thred.rar
  • thred
  • 线程
  • Compare_Mythread.java
    684B
  • .project
    382B
  • Mythread.class
    825B
  • UseATM.java
    2.1KB
  • UseThreadPrio.class
    616B
  • UseThreadPrio.java
    538B
  • Mypanel$PushButton.class
    1.2KB
  • UserA.class
    1.4KB
  • RamdomGet.class
    830B
  • Compare_Mythread.class
    734B
  • UserB.class
    1.4KB
  • R.class
    788B
  • RamdomGet.java
    2.5KB
  • MyThread1.class
    828B
  • .classpath
    291B
  • Accounts.class
    831B
  • Mypanel$My_th.class
    1.3KB
  • Mypanel.class
    1.5KB
  • UseATM.class
    636B
  • www.pudn.com.txt
    218B
内容介绍
import java.awt.*; import java.io.*; import javax.swing.*; import java.awt.event.*; class Mypanel extends JFrame { int NameNumber=2; static boolean key=true; JButton jb1=new JButton(); JButton jb2=new JButton(); JPanel jp=new JPanel(); JPanel jp2=new JPanel(); JTextField jtf=new JTextField(); public Mypanel() {jtf.setEnabled(false); jb1.setText("开始"); jb2.setText("结束"); jp=(JPanel)this.getContentPane(); jtf.setSize(300, 300); jp.setLayout(new BorderLayout()); jp.add("Center",jtf); jp2.add(jb1); jp2.add(jb2); jp.add("South",jp2); jb1.addActionListener(new PushButton()); jb2.addActionListener(new PushButton()); } class My_th implements Runnable { public void setkey(boolean b) {key=b;} public void run() { try{ FileReader fr=new FileReader("123.txt"); BufferedReader brf=new BufferedReader(fr); String str=""; while(key) {Thread.sleep(50); //for(int i=0;i<NameNumber;i++) str=brf.readLine(); jtf.setText(str); if( str==null) {fr=new FileReader("G:\\java\\my java\\我的作业\\作业\\线程作业\\随机抽取学生(选做)\\123.txt"); brf=new BufferedReader(fr); }} } catch(InterruptedException IE) {} catch(IOException e) {} } } class PushButton implements ActionListener { My_th mt=new My_th(); Thread th=new Thread(mt); public void actionPerformed(ActionEvent e) { if(e.getSource()==jb1) { if(key==true) //mt.setkey(true); //int sleeptime=(int)(Math.random()*1000); { jtf.setText(""); th.start(); } else{ key=true; jtf.setText(""); th.start();} } if(e.getSource()==jb2) { th.interrupt(); //th.yield(); //Thread th=new Thread(mt); key=false; } } } } public class RamdomGet extends WindowAdapter{ public static void main(String args[]) { Mypanel mp=new Mypanel(); mp.setVisible(true); mp.setLocation(300,300); mp.pack(); //mp.setSize(200,200); } public void processWindowEvent(WindowEvent e) { if(e.getID()==WindowEvent.WINDOW_CLOSING) System.exit(0); } }
评论
    相关推荐