This is my code:
/*
* Console.java
*
* Created on November 5, 2007, 5:23 PM
*/
package javaapplication6;
import java.io.IOException;
import java.lang.String;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
/**
*
* @author root
*/
public class Console extends javax.swing.JFrame {
private LoadFirmware loadfirmware;
/** Creates new form Console */
public Console() {
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() {
jPanel1 = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenuItem2 = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
jMenuItem3 = new javax.swing.JMenuItem();
jMenuItem4 = new javax.swing.JMenuItem();
jMenuItem5 = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("append");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("Exit");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setText("Switch to Program Mode");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jButton4.setText("Switch to Run Mode");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.add(jButton1)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jButton3)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jButton4)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jButton2)
.addContainerGap(170, Short.MAX_VALUE))
.add(jPanel1Layout.createSequentialGroup()
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 622, Short.MAX_VALUE)
.add(20, 20, 20))
);
jPanel1Layout.linkSize(new java.awt.Component[] {jButton1, jButton2}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
jPanel1Layout.linkSize(new java.awt.Component[] {jButton3, jButton4}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 247, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 90, Short.MAX_VALUE)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jButton1)
.add(jButton3)
.add(jButton4)
.add(jButton2))
.add(98, 98, 98))
);
jMenu1.setText("File");
jMenuItem1.setText("New");
jMenu1.add(jMenuItem1);
jMenuItem2.setText("Open");
jMenu1.add(jMenuItem2);
jMenuBar1.add(jMenu1);
jMenu2.setText("Tool");
jMenuItem3.setText("Load Firmware");
jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
load_firmware(evt);
}
});
jMenu2.add(jMenuItem3);
jMenuItem4.setText("Start Console Service");
jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
StartService(evt);
}
});
jMenu2.add(jMenuItem4);
jMenuItem5.setText("Monitor");
jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem5ActionPerformed(evt);
}
});
jMenu2.add(jMenuItem5);
jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>
private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {
CmdHandle loadMon = new CmdHandle();
loadMon.main(null);
}
private void StartService(java.awt.event.ActionEvent evt) {
try {
//Process proc = Runtime.getRuntime().exec("java MyTest");
Runtime rt = Runtime.getRuntime();
String[] cmd={"cmd.exe" , "/c" , "start" ,"c:/cygwin/home/root/ugconsole/main.exe"};
//String[] cmd={"c:/cygwin/home/root/ugconsole/main.exe"};
rt.exec(cmd);
//System.out.println("***Executed java MyTest***");
} catch (IOException e) {e.printStackTrace();}
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
appendmsg("apn msg\n");
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
Tcp cmd = new Tcp();
cmd.PID_SwToRunMode();
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
Tcp cmd = new Tcp();
cmd.ProgramMode();
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void load_firmware(java.awt.event.ActionEvent evt) {
loadfirmware.main(null);
}
public static void PROGRAMPAGE(){
String command = "PROGRAMPAGE";
writer.print(command);
writer.flush();
// appendmsg(command);
try {
String response = reader.readLine();
System.out.println(response);
} catch (IOException ex) {
ex.printStackTrace();
}
}
public static void appendmsg(String msg){
// jTextArea1.append("but this ok le");
jTextArea1.append(msg);
System.out.println(msg);
}
public static void main(String args[])
throws IOException
{
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Console().setVisible(true);
}
});
final int DEST_PORT = 20000;
s = new Socket("localhost", DEST_PORT);
in = s.getInputStream();
out = s.getOutputStream();
reader = new BufferedReader(new InputStreamReader(in));
writer = new PrintWriter(out);
//String asd = "asd";
//writer.print(asd);
// writer.flush();
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JMenuItem jMenuItem3;
private javax.swing.JMenuItem jMenuItem4;
private javax.swing.JMenuItem jMenuItem5;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
public static javax.swing.JTextArea jTextArea1;
// End of variables declaration
private static Socket s;
private static InputStream in;
private static OutputStream out;
private static BufferedReader reader;
private static PrintWriter writer;
}
After PROGRAMPAGE() is call, appendmsg() won't work anymore.
anyone can help ? thank!
Edited by: mjava on Nov 15, 2007 7:26 PM