📄 console.java
字号:
package a.a.a.b;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.io.*;
import javax.swing.text.*;
public class Console extends JWindow implements Runnable {
public static final long serialVersionUID=1;
private JTextPane t;
private int textLen;
private PipedOutputStream pos;
private PipedInputStream pis;
private PipedOutputStream peos;
private PipedInputStream peis;
DefaultStyledDocument doc;
SimpleAttributeSet attr;
private byte[] buffer;
private int bufferLen;
private JPopupMenu popmenu;
private String version=e.getString("Version",e.TYPE_ABOUT)+e.Version+"\r\n"+e.getString("DLLVersion",e.TYPE_ABOUT)+"\r\n\r\n";
private boolean canRun;
public Console(Frame owner) {
super(owner);
canRun=true;
textLen=version.length();
t=new JTextPane();
doc=new DefaultStyledDocument();
t.setDocument(doc);
t.setBackground(Color.BLACK);
t.setForeground(Color.LIGHT_GRAY);
//t.setAutoscrolls(true);
t.setEditable(false);
/*JScrollPane p=new JScrollPane(t);
p.setBackground(t.getBackground());
MatteBorder border1=new BQMatteBorder(5,10,0,0,Color.GRAY);
TitledBorder border=new TitledBorder(border1, e.getString("Console",e.TYPE_OTHER));
p.setBorder(border);
this.getContentPane().add(p);*/
this.getContentPane().add(t);
try{
pis=new PipedInputStream();
pos=new PipedOutputStream(pis);
peis=new PipedInputStream();
peos=new PipedOutputStream(peis);
attr=new SimpleAttributeSet();
StyleConstants.setForeground(attr,Color.RED);
//StyleConstants.setBold(attr,true);
doc.insertString(0,version,null);
}catch(Exception exp){
exp.printStackTrace();
}
bufferLen=512;
buffer=new byte[bufferLen];
popmenu=new JPopupMenu();
JMenuItem jmi=new JMenuItem(e.getString("Clean",e.TYPE_OTHER));
jmi.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt2){
clean();
}
});
popmenu.add(jmi);
t.addMouseListener(new MouseAdapter(){
public void mousePressed(MouseEvent evt){
if((evt.getModifiers()&InputEvent.BUTTON3_MASK)!=0){
popmenu.show(t,evt.getX(),evt.getY());
}
}
});
t.setFocusable(false);
//p.setFocusable(false);
this.setFocusable(false);
}
public OutputStream getOutputStream(){
return pos;
}
public OutputStream getErrStream(){
return peos;
}
public void stopConsole(){
canRun=false;
}
synchronized public void clean(){
try{
textLen=version.length();
t.setText(version);
}catch(Exception exp){
exp.printStackTrace();
}
}
public void run() {
try{
while(canRun){
while(pis.available()>0){
int rd=pis.read(buffer);
//if(this.isVisible()){
//t.append(new String(buffer,0,rd));
//textLen+=rd;
//t.setCaretPosition(textLen);
//}
doc.insertString(textLen,new String(buffer,0,rd),null);
textLen+=rd;
}
while(peis.available()>0){
int rd=peis.read(buffer);
//if(this.isVisible()){
//t.append(new String(buffer,0,rd));
//textLen+=rd;
//t.setCaretPosition(textLen);
//}
doc.insertString(textLen,new String(buffer,0,rd),attr);
textLen+=rd;
}
Thread.sleep(100);
}
}catch(Exception exp){
exp.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -