|
calling a perl script in Java(using a OK Button)
Hello,
Please help: Still new to Java and NetBean
Trying to accomplish: each time I click ok, I want a perl script name
ccsloc.pl should run. The path is D:\ccloc>ccsloc.pl. Basically
the directory will be change from C to D: FIRST
After it runs the report, it should print the report to notepad .
Below is the Program. The event handler button name is jButton2
* August1.java
*
* Created on November 14, 2007, 1:35 PM
*/
package august;
import java.awt.event.MouseEvent;
import java.io.*;
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
/**
*
* @author brucya00
*/
public class August1 extends javax.swing.JFrame {
private JLabel jLabel1;
private JLabel jLabel2;
private JTextField jTextField1;
private JLabel jLabel3;
private JTextField jTextField2;
private JButton jButton1;
private JLabel jLabel4;
private JComboBox jComboBox1;
private JRadioButton jRadioButton1;
private JLabel jLabel5;
private JScrollPane jScrollPane1;
private JList jList1;
private JLabel jLabel6;
private JLabel jLabel7;
private JTextField jTextField3;
private JComboBox jComboBox2;
private JLabel jLabel8;
private JTextField jTextField4;
private JComboBox jComboBox3;
private JLabel jLabel9;
private JLabel jLabel10;
private JTextField jTextField5;
private JLabel jLabel11;
private JTextField jTextField6;
private JButton jButton2;
private JButton jButton3;
private JButton jButton4;
private JPanel Hello;
private JTextArea jTextArea1;
private JButton jButton5;
private JButton jButton6;
private Runtime exec;
private JScrollPane jScrollPane2;
// private JTextField field;
/** Creates new form August1 */
public August1() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jScrollPane2 = new javax.swing.JScrollPane();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jTextField2 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jLabel4 = new javax.swing.JLabel();
jComboBox1 = new javax.swing.JComboBox();
jRadioButton1 = new javax.swing.JRadioButton();
jLabel5 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jList1 = new javax.swing.JList();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jTextField3 = new javax.swing.JTextField();
jComboBox2 = new javax.swing.JComboBox();
jLabel8 = new javax.swing.JLabel();
jTextField4 = new javax.swing.JTextField();
jComboBox3 = new javax.swing.JComboBox();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jTextField5 = new javax.swing.JTextField();
jLabel11 = new javax.swing.JLabel();
jTextField6 = new javax.swing.JTextField();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);
setTitle("Report");
setName("main");
jLabel1.setText(" Suneg Report");
jLabel2.setText(" View 1");
jTextField1.setText("cc_tnt_admin_From");
jLabel3.setText("View 2");
jTextField2.setText("cc_tnt_admin_TO");
jButton1.setText("Config");
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton1MouseClicked(evt);
}
});
jButton1.getAccessibleContext().setAccessibleParen t(jButton1);
jLabel4.setText("Vobs");
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "TNT","Claims", "RPT"}));
jComboBox1.setSelectedItem(jList1.getModel());
jComboBox1.setSelectedItem(jList1.getModel());
jComboBox1.getAccessibleContext().setAccessiblePar ent(jList1);
jRadioButton1.setText("NotePad");
jRadioButton1.setBorder(javax.swing.BorderFactory. createEmptyBorder(0, 0, 0, 0));
jRadioButton1.setMargin(new java.awt.Insets(0, 0, 0, 0));
jLabel5.setText("Sub Vob");
jList1.setModel(new javax.swing.AbstractListModel() {
String[] strings = { "TNT_ARCH", "TNT_UTIL", "TNT_APP", "SRN_Workflow", "TNT_Model", "DCUTL_Release", "TNT_RPT", "TNTRP_Model_Build", "TNT_MAL_APP" };
@Override
public int getSize() { return strings.length; }
@Override
public Object getElementAt(int i) { return strings[i]; }
});
jScrollPane1.setViewportView(jList1);
jLabel6.setText("Dates");
jLabel7.setText("From:");
jTextField3.setText("mm-dd-yyyy");
jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "AM", "PM" }));
jLabel8.setText("To:");
jTextField4.setText("mm-dd-yyyy");
jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "AM", "PM" }));
jLabel9.setText("Time");
jLabel10.setText("From:");
jTextField5.setText("00:00");
jLabel11.setText("To:");
jTextField6.setText("00:00");
jButton2.setText("Ok");
jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mouseClicked(java.awt.event.MouseEvent evt){
}
//trying to accomplish: each time I click ok, I want a perl script name
//name ccsloc.pl should run. The path is D:\ccloc>ccsloc.pl. Basically
// the directory will be change from C to D: FIRST
//After it runs the report, it should print the report to notepad .
private void jButton2MouseClicked(MouseEvent evt) throws IOException {
String [] cmdString = {"cmd.exe", "/c perl.exe -S ccsloc.pl", "notepad.exe"};
Process exec = Runtime.getRuntime().exec("cmdString");
}
});
jButton3.setText("Cancel");
jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton3MouseClicked(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(58, 58, 58)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addComponent(jLabel9)
.addComponent(jLabel6)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4)
.addComponent(jLabel7)
.addComponent(jLabel8)
.addComponent(jLabel10)
.addComponent(jLabel11)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING, false)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE)
.addComponent(jTextField2)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(23, 23, 23)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addComponent(jButton1)
.addComponent(jRadioButton1)))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.TRAILING, false)
.addComponent(jTextField3, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 88, Short.MAX_VALUE)
.addComponent(jTextField4, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField5, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField6, javax.swing.GroupLayout.Alignment.LEADING))
.addGap(29, 29, 29)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addComponent(jButton3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING, false)
.addComponent(jComboBox2, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jComboBox3, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))))))
.addGap(30, 30, 30))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(22, 22, 22)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.TRAILING)
.addComponent(jLabel2)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton1))))
.addGap(20, 20, 20)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3))
.addGap(21, 21, 21)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
.addComponent(jRadioButton1)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4))
.addGap(24, 24, 24)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addComponent(jLabel5)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(8, 8, 8)
.addComponent(jLabel6)
.addGap(28, 28, 28)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addComponent(jLabel7)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addComponent(jLabel8)
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(15, 15, 15)
.addComponent(jLabel9)
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
.addComponent(jLabel10)
.addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
.addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel11)
.addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED, 30, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
.addComponent(jButton2)
.addComponent(jButton3))
.addContainerGap())
);
pack();
}// </editor-fold>
//cancel button that clears the JTEXTField
private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText("");
jTextField6.setText("");
}
// private void runClearCase(String v1 , String v2, String d1, String d2)
//throws IOException
// {
//config button that brings up another Jframe
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
JFrame Frame = new JFrame("Config Spec");
GridBagLayout gridLayoutMgr = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
Hello = new JPanel();
//Hello
c.gridx =0;
c.gridy =1;
jTextArea1 = new JTextArea(12,24);
gridLayoutMgr.setConstraints(jTextArea1, c);
Hello.add(jTextArea1);
c.gridx = 2;
c.gridy = 8;
jButton4 = new JButton("OK");
gridLayoutMgr.setConstraints(jButton4, c);
Hello.add(jButton4);
c.gridx = 4;
c.gridy = 8;
jButton5 = new JButton("Apply");
gridLayoutMgr.setConstraints(jButton5, c);
Hello.add(jButton5);
c.gridx = 6;
c.gridy = 8;
jButton6 = new JButton("Edit");
gridLayoutMgr.setConstraints(jButton6, c);
Hello.add(jButton6);
JTabbedPane tabby = new JTabbedPane();
Frame.setContentPane(tabby);
tabby.addTab("Spec", Hello);
ButtonHandler fhandler = new ButtonHandler();
jButton4.addActionListener(fhandler);
LuttonHandler ushandler = new LuttonHandler();
jButton5.addActionListener(ushandler);
EuttonHandler phandler = new EuttonHandler();
jButton6.addActionListener(phandler);
Frame.setSize(275,320);
Frame.setVisible(true);
}
private class ButtonHandler implements ActionListener
{
@Override
public void actionPerformed (ActionEvent event)
{
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setVisible(true);
}
}
private class LuttonHandler implements ActionListener
{
private Color color;
@Override
public void actionPerformed(ActionEvent event){
color = Color.LIGHT_GRAY;
jTextArea1.setBackground(color);
}
}
private class EuttonHandler implements ActionListener
{
private Color color;
@Override
public void actionPerformed(ActionEvent event){
color = Color.WHITE;
jTextArea1.setBackground(color);
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new August1().setVisible(true);
}
});
}
}
|