I'm trying to create a GUI Panel for a program and I'd like everything, that would normally print to my command prompt, to print to a TextArea object. I have the GUI panel formatted for the most part, I can't get the text to print to the TextArea though, here's my file:
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();
}
public static void main(String args[]) {
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(GUIPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(GUIPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(GUIPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(GUIPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new GUIPanel().setVisible(true);
}
});
}
private JMenu jMenu1;
private JMenu jMenu2;
private JMenuBar jMenuBar1;
private JTabbedPane jTabbedPane1;
private TextArea textArea1;
private JPanel jPanel = new JPanel();
private PrintStream aPrintStream =
new PrintStream(
new FilterOutputStream(
new ByteArrayOutputStream()));
}
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…