Reputation: 306
Good Evening, I going to take the output of a program and show it in a simple Text Area GUI. I try to follow certain tutorials but the output still show on the NetBean console but not at the GUI.
public class PingAndTransmit extends JPanel{//This is the First brace({)
JTextArea audioData = new JTextArea();
JTextArea pingData = new JTextArea();
String audioLine;
String pingLine;
public PingAndTransmit() {
super(new BorderLayout());
while(...) {
if(...) {
audioLine = "\nI am handsome";
pingLine = "\nShe is pretty";
} else {
audioLine = "\nI am not handsome";
pingLine = "\nShe not pretty";
}
}
audioData.append(audioLine);
pingData.append(pingLine);
JPanel controls2 = new JPanel(new GridLayout(1, 2));
controls2.add(audioData);
controls2.add(pingData);
add(controls2, BorderLayout.CENTER);
}//this is not the last brace (})
For the GUI
public static void createAndShowGui() {
JFrame frame = new JFrame("Sender");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new PingAndTransmit());
frame.setSize(400, 200);
frame.setVisible(true);
frame.toFront();
}
Main
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGui();
}
});
}
}//Here is the last brace (})
How can I display the output on the Text Area GUI? Need some hints and guidelines, thanks^^"
Upvotes: 0
Views: 684
Reputation: 6479
what is PingAndTransmit()? does it extend a JComponent?
You need to add the textarea at some point in your frame.
Your createAndShowGui() method only creates a frame and tries to add that "PingAndTransmit()" object, but it looks like that object isn't really a Swing component.
Upvotes: 1