【发布时间】:2015-07-05 14:36:49
【问题描述】:
在过去的一两天里,我已经用不同的措辞搜索了这个问题,但我无法解决它:/,
我在屏幕上弹出一个看起来像命令提示符的窗口,有两个按钮运行和停止。无论如何,一旦你按下开始,我在屏幕上就会开始“扫描文件”它说“扫描 1-1900 的东西”计数到 1900,然后说扫描完成,之后我想要文本在现有文本下 例如,写多行文字来惹我的朋友。
{
Scan Completed
"wait time inbetween each line of text"
Hack initialized
"wait time inbetween each line of text"
Hack installing...
"wait time inbetween each line of text"
Hack installed
ECT
}
希望有人可以帮助我,我看到的每个人都无法使用我的代码:/ 我也是编码新手,所以...
在此先谢谢你,我的代码不会太长:P。
public static void main(String[] args) throws IOException {
JFrame frame = new JFrame("Happy Monday v0.05");
Container contentPane = frame.getContentPane();
JTextPane jta = new JTextPane();
JButton button = new JButton("Run");
JButton buttonstop = new JButton("Stop");
contentPane.add(button);
contentPane.add(buttonstop);
button.setBounds(-1,283,465,40);
buttonstop.setBounds(465,283,469,40);
frame.add(jta).setBackground(Color.black);
console(jta);
//Window
frame.setSize(950, 650 / 16 * 9);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
button.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
new SwingWorker<Void, Object>(){
@Override
protected Void doInBackground() throws Exception {
outputTest("Scanning...");
return null;
}}.execute();
}});
}
//Testing OUTPUTS:/
public static void outputTest(String msg){
for(int i=0;i<1969;i++){
System.out.println(i+" "+msg);
try {
Thread.sleep(01);
System.out.println("Scan Complete");
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
public static void console(final JTextPane area) throws IOException {
area.setContentType("text/html");
final PipedInputStream outPipe = new PipedInputStream();
System.setOut(new PrintStream(new PipedOutputStream(outPipe), true));
new SwingWorker<Void, String>() {
@Override
protected Void doInBackground() throws Exception {
Scanner s = new Scanner(outPipe);
while (s.hasNextLine()){
String line = s.nextLine();
publish(line + "\n");
}
return null;
}
@Override
protected void process(List<String> chunks) {
for (String line : chunks){
area.setText("<font size=\"5\" color=\"green\">"+line+"</font>");
}
}
}.execute();
}
}
【问题讨论】:
-
请添加您的代码现在所做的详细信息。另请阅读stackoverflow.com/help/mcve
标签: java user-interface text window jtextpane