如何将输出流设置为TextArea
我正在尝试为程序创建GUI面板,我想要通常打印到我的命令提示符的所有内容,以打印到TextArea对象。我的GUI面板大部分都是格式化的,我无法将文本打印到TextArea,这里是我的文件:
package guipanel;import javax.swing.*;import java.awt.*;import java.io.*;/** * * @author Dan */public class GUIPanel extends JFrame { public GUIPanel() { initComponents(); } private void setOutputStream(boolean catchErrors) { System.setOut(aPrintStream); setVisible(true); requestFocus(); if (catchErrors) { System.setErr(aPrintStream); } } private void addTabs(JTabbedPane jTabbedPane1) { JPanel jPanel1 = new JPanel(); JPanel jPanel2 = new JPanel(); JPanel jPanel3 = new JPanel(); JPanel jPanel4 = new JPanel(); jTabbedPane1.add("Main", textArea1); jTabbedPane1.add("Commands", jPanel); jTabbedPane1.add("Rules", jPanel1); jTabbedPane1.add("Links", jPanel2); jTabbedPane1.add("Information", jPanel3); jTabbedPane1.add("Shutdown", jPanel4); setOutputStream(true); } @SuppressWarnings("unchecked") private void initComponents() { textArea1 = new java.awt.TextArea(); jTabbedPane1 = new javax.swing.JTabbedPane(); jMenuBar1 = new javax.swing.JMenuBar(); jMenu1 = new javax.swing.JMenu(); jMenu2 = new javax.swing.JMenu(); textArea1.setPreferredSize(new java.awt.Dimension(432, 343)); textArea1.getAccessibleContext().setAccessibleParent(jTabbedPane1); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Evolution-X 639"); setBounds(new java.awt.Rectangle(0, 0, 400, 450)); setResizable(false); getContentPane().setLayout(new java.awt.FlowLayout()); addTabs(jTabbedPane1); getContentPane().add(jTabbedPane1); jMenu1.setText("File"); jMenuBar1.add(jMenu1); jMenu2.setText("Edit"); jMenuBar1.add(jMenu2); setJMenuBar(jMenuBar1); pack(); }
饮歌长啸
拉风的咖菲猫
相关分类