javaコンソールからjpanelまたはjTextAreaに私のメッセージを視覚化したい、私は2つのクラスを作成した。perlスクリプト "hello world! "そして、私は第二のクラスからのJButtonをクリックすると、他のクラスからの私のJTextAreaの中で、このメッセージを表示したい - >これは私のスクリプトjavaコンソールからjTextAreaまたはjLabelに出力メッセージをリダイレクト
package escudo;
import java.io.IOException;
import java.io.InputStream;
public class MediocreExecJavac {
public static void main(String[] args) {
try {
// Run the process
Process p = Runtime.getRuntime().exec("perl script\\hello.pl");
// Get the input stream
InputStream is = p.getInputStream();
// Read script execution results
int i = 0;
StringBuffer sb = new StringBuffer();
while ((i = is.read()) != -1)
sb.append((char)i);
System.out.println(sb.toString());
} catch (IOException e) {
e.printStackTrace();
}
}
}
の私の最初のクラスがあり、これはどこでハローを視覚化したいですGO Jボタンをクリックすると、このJtextareaの世界のメッセージ
package escudo;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextArea;
import javax.swing.JButton;
public class test extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
test frame = new test();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public test() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JTextArea textArea = new JTextArea();
textArea.setBounds(48, 71, 324, 180);
contentPane.add(textArea);
JButton btnGo = new JButton("go");
btnGo.setBounds(159, 23, 89, 23);
contentPane.add(btnGo);
}
}