i can assure that i get the output either from the first
Test class or the second JButtons one..
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class test {
public static void main(
String[] args) {
String str18 = "java JButtons";
String str20 = null;
Runtime Runtime1 = Runtime.getRuntime();
try {
Process Process1;
Process1 = Runtime1.exec(str18);
//This is the line where i am trying to get the output stream of the java
//program by getting its inputstream. I am right am i not or do i have
//to get its outputstream of the program instead
BufferedReader in = new BufferedReader(new InputStreamReader(Process1.getInputStream()));
while ((str20 = in.readLine()) != null)
{
System.out.println(str20);
}
Process1.waitFor();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
and
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class JButtons implements ActionListener
{
JFrame fr = new JFrame ("Frame");
JLabel Label1 = new JLabel("Label1 ",SwingConstants.RIGHT);
JButton Button1 = new JButton("Button 1");
JButton Button2 = new JButton("Button 2");
public void initialize ()
{
Container pane = fr.getContentPane();
pane.setLayout(new FlowLayout());
fr.setSize(250,300);
fr.setLocation(300,300);
fr.setBackground(Color.lightGray);
pane.add(Label1);
pane.add(Button1);
pane.add(Button2);
fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Button1.addActionListener(this);
Button2.addActionListener(this);
fr.pack();
fr.setVisible(true);
}
public void actionPerformed(ActionEvent event)
{
JComponent b = (JComponent)event.getSource();
if(b == Button1)
{
Label1.setText("Button 1 clicked");
System.out.println("You clicked Button 1");
}
else if(b == Button2)
{
Label1.setText("Button 2 clicked");
System.out.println("You clicked Button 2");
}
}
public static void main(String args[])
{
JButtons a = new JButtons();
a.initialize();
}
}
and i called at prompt
java test output is...
You clicked Button 2
You clicked Button 1
You clicked Button 2