| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 543 人关注过本帖
标题:关于进程问题
只看楼主 加入收藏
cwj1988829
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-12-6
收藏
 问题点数:0 回复次数:0 
关于进程问题
在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);
  }
 }
}
搜索更多相关主题的帖子: 进程 
2007-12-06 16:50
快速回复:关于进程问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.032533 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved