关于进程问题
在JAVA中 进程终止后,怎么可以再让他进行!下面是代码:
package cwjTest;
import javax.swing.SwingUtilities;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.Rectangle;
import javax.swing.JLabel;
import java.util.Timer;
import java.util.TimerTask;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Calendar;
public class Window extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JButton jButton = null;
private JButton jButton1 = null;
private JLabel jLabel = null;
private Calendar objc1;
private Calendar objc2;
private String str;
private Timer timer = new Timer();
private MyTask a = new MyTask();
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new Rectangle(50, 90, 60, 30));
jButton.setText("启动");
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
objc1 = Calendar.getInstance();
timer.schedule(a,0,1000);
}
});
}
return jButton;
}
/**
* This method initializes jButton1
*
* @return javax.swing.JButton
*/
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setBounds(new Rectangle(170, 90, 60, 30));
jButton1.setText("停止");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
timer.cancel();
int s = objc2.get(Calendar.SECOND) - objc1.get(Calendar.SECOND);
String ss = Integer.toString(s);
int h = objc2.get(Calendar.HOUR) - objc1.get(Calendar.HOUR);
String hh = Integer.toString(h);
int m = objc2.get(Calendar.MINUTE) - objc1.get(Calendar.MINUTE);
String mm = Integer.toString(m);
if (s < 10){
ss = "0" + ss;
}
if (h < 10){
hh = "0" + hh;
}
if (m < 10){
mm = "0";
}
jLabel.setText(hh + ":" + mm + ":" + ss);
}
});
}
return jButton1;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Window thisClass = new Window();
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
thisClass.setVisible(true);
}
});
}
/**
* This is the default constructor
*/
public Window() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(300, 200);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(60, 20, 160, 30));
jLabel.setText("");
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getJButton(), null);
jContentPane.add(getJButton1(), null);
jContentPane.add(jLabel, null);
}
return jContentPane;
}
class MyTask extends TimerTask{
public MyTask(){
}
public void run(){
objc2 = Calendar.getInstance();
Date objd = new Date();
SimpleDateFormat objs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss" );
str = objs.format(objd);
jLabel.setText(str);
}
}
}