• Post Reply Bookmark Topic Watch Topic
  • New Topic

help in swing application

 
smith jhon
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to run shell script from java code the code which i have used is
import javax.swing.*;
import java.io.*;
import java.util.*;
class robinswing{
robinswing()
{
JFrame jfrm= new JFrame ("a simple swing application");
jfrm.setSize(275,100);
jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel jlab=new JLabel("aswing demo");
jfrm.add(jlab);
jfrm.setVisible(true);
}
void ExecuteScript()
{
ProcessBuilder pb = new ProcessBuilder("crtinv1.sh","-n");
pb.redirectErrorStream(true);
try{
Process shell = pb.start();

}
catch (Exception ignoreMe) {}
}


public static void main(String[] args)
{
SwingUtilities.invokeLater(new Runnable(){
public void run(){
robinswing a=new robinswing();
a.ExecuteScript();
}
});
}
The code is running fine.But i need to develop 4 buttons which onclicking will execute with option -a ,-n,-H,-h
the code which i tried n failed is
import javax.swing.*;
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
class robinswing{
JFrame jfrm= new JFrame ("a simple swing application");
JLabel jlab;
robinswing(){
jfrm.setSize(275,100);
jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jfrm.add(jlab);
jfrm.setVisible(true);
JButton alpha=new JButton("info");
alpha.addActionListener (new ActionListener(){
public void actionPerformed(ActionEvent ae){
jlab.setText("alapha was pressed");
}
});
jfrm.add(alpha);
}
public static void main(String[] args)
{
SwingUtilities.invokeLater(new Runnable(){
public void run(){
robinswing a=new robinswing();
}
});
}

}
The code is giving error .what modification should i make
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

1) Create 4 buttons for the 4 flags
2) Modify the executeScript() to accept a String parameter as an argument, the parameter being the flag (-a,-n,-H or -h)
3) Add actions listeners to the button. Based on which button was clicked, figure out what flag to pass to the executeScript and invoke it accordingly.

Also please http://faq.javaranch.com/java/UseCodeTags
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!