📄 consoledriver.java
字号:
/* * ConsoleDriver.java * * Created on 2006年3月18日, 下午2:59 * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */package os.iodevice;/** * * @author Vernkin */import javax.swing.*;import os.process.*;import os.cpu.Interrupt;import java.awt.event.*;public class ConsoleDriver implements Runnable,ActionListener{ final private String name = "[ConsoleDriver]"; IOGate ig; MyProcess currentPro; int in; //display area JLabel proInfo; JTextArea consoleOut; JTextField consoleIn; JButton enter; JTextArea commonOut; /** Creates a new instance of ConsoleDriver */ public ConsoleDriver(JLabel proInfo,JTextArea consoleOut,JTextField consoleIn,JButton enter,JTextArea commonOut){ ig = IOGate.getInstance("Console"); this.proInfo = proInfo; this.consoleOut = consoleOut; this.consoleIn = consoleIn; this.enter = enter; this.commonOut = commonOut; in = -1; init(); } private void init(){ enter.addActionListener(this); enter.setActionCommand("Enter"); consoleOut.append(name+" Activated"+"\n"); this.commonOut.append(name+" Detected"+"\n"); currentPro = null; } public void run(){ while(true){ if(ig.driverHaveTask()){ int interrupt_num = ig.getInterruptNum(); if(interrupt_num == Interrupt.ConsoleOut_INTERRUPT){ currentPro = ig.getProcess(); currentPro.setStatus("ConsoleOut"); proInfo.setText("Current Process Infomation(Out) : Name "+currentPro.getName()+" ID:"+currentPro.getID()); consoleOut.append(name+currentPro+"[Output]"+((char)ig.getData())+"\n"); commonOut.append(name+currentPro+"[console output......]"+"\n"); currentPro = null; ig.driverFinishWork(); } else if(interrupt_num == Interrupt.ConsoleIn_INTERRUPT){ if(currentPro == null){ currentPro = ig.getProcess(); currentPro.setStatus("ConsoleIn"); proInfo.setText("Current Process Infomation(In) : Name "+currentPro.getName()+" ID:"+currentPro.getID()); consoleOut.append(name+currentPro+"[waiting for input]"+"\n"); commonOut.append(name+currentPro+"[console input....]"+"\n"); } if(in >=0){ ig.driverSetData(in); in = -1; currentPro = null; ig.driverFinishWork(); }else ig.rest(500); }//end else if }else{ ig.rest(2000); }//end else }//end while } public void actionPerformed(ActionEvent e){ if(e.getActionCommand().equals("Enter") && currentPro != null){ String s = consoleIn.getText(); if(s.length()==0){ in = -1; consoleOut.append(name+"[You haven't input a character yet]"+"\n"); }else{ char tmp = s.charAt(0); consoleOut.append(name+currentPro+"[You input]"+tmp+"\n"); commonOut.append(name+currentPro+"[Input]"+tmp+"\n"); in = (int)tmp; } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -