晚上好,我将获取一个程序的输出并在一个简单的文本区域 GUI 中显示它。我尝试遵循某些教程,但输出仍显示在 NetBean 控制台上,但不在 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 (})
对于图形用户界面
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();
}
主要的
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGui();
}
});
}
}//这里是最后一个大括号(})
如何在文本区域 GUI 上显示输出?需要一些提示和指导,谢谢^^"