| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 728 人关注过本帖
标题:定时启动软件问题
取消只看楼主 加入收藏
hf8813264
Rank: 1
等 级:新手上路
帖 子:22
专家分:5
注 册:2009-6-2
结帖率:33.33%
收藏
 问题点数:0 回复次数:0 
定时启动软件问题
想通过java编写一个用户界面,通过设置具体的时间,来运行文件选择器里选定的文件,可是始终无法实现某些功能,现在有几个疑问:如何动态的获取系统的时间,以及如何真正的实现系统时间如自己设定时间的比较,还有就是如何在设定的时间运行选择的exe文件,基本代码在下面,麻烦大家看看
package ch10;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import *;
import java.util.*;
import java.text.*;
import
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.filechooser.*;
import javax.swing.event.*;
import java.util.Date;
import java.util.Calendar;

public class Timing extends JFrame implements ActionListener {
   

    JPanel jp = new JPanel();

    JButton jb1 = new JButton("浏览");

    JButton jb2 = new JButton("确定");

    JLabel jl1 = new JLabel("运行时间");

    JLabel jl2 = new JLabel("时");

    JLabel jl3 = new JLabel("分");

    JLabel jl4 = new JLabel("秒");

    JLabel jl[] = new JLabel[] { jl1, jl2, jl3, jl4 };

    JTextArea jta1 = new JTextArea();

    JTextArea jta2 = new JTextArea();

    JTextArea jta3 = new JTextArea();

    JTextArea jta4 = new JTextArea();

    JTextArea jta[] = new JTextArea[] { jta1, jta2, jta3, jta4 };

    JFileChooser fileChooser = new JFileChooser("E:\\");

    public Timing() {
        // TODO Auto-generated constructor stub
        jp.setLayout(null);
        jp.add(jb1);
        jp.add(jb2);
        jb1.addActionListener(this);
        jb2.addActionListener(this);
        for (int i = 0; i < jl.length; i++) {
            jp.add(jl[i]);
            jp.add(jta[i]);
            jta[i].setEditable(true);
        }
        jl1.setBounds(10, 10, 60, 20);
        jta1.setBounds(80, 10, 40, 20);
        jl2.setBounds(130, 10, 20, 20);
        jta2.setBounds(160, 10, 40, 20);
        jl3.setBounds(210, 10, 20, 20);
        jta3.setBounds(240, 10, 40, 20);
        jl4.setBounds(290, 10, 20, 20);
        jta4.setBounds(10, 40, 300, 20);
        jb1.setBounds(320, 40, 80, 20);
        jb2.setBounds(10, 70, 80, 20);
        fileChooser.removeChoosableFileFilter(fileChooser
                .getChoosableFileFilters()[0]);
        fileChooser.addChoosableFileFilter(new FileNameExtensionFilter(".exe",
                "exe"));
        this.add(jp);
        this.setTitle("定时启动器");
        this.setBounds(110, 110, 500, 150);
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }

    public void actionPerformed(ActionEvent e) {

        if (e.getSource() == jb1) {
            fileChooser.showOpenDialog(this);
            String path = fileChooser.getSelectedFile().getPath().toString();
            // path.replace("\\","");
            jta4.setText(path);

        }
        if (e.getSource() == jb2) {
            if (jta1.getText().equals("") || jta2.getText().equals("")
                    || jta3.getText().equals("") || jta4.getText().equals("")) {
                JOptionPane.showMessageDialog(this, "请输入完整的信息", "错误",
                        JOptionPane.INFORMATION_MESSAGE);
            } else {
                while (true) {
                    Calendar cal = Calendar.getInstance();
                    if (cal.HOUR_OF_DAY == Integer.parseInt(jta1.getText())
                            && cal.MINUTE == Integer.parseInt(jta2.getText())) {
                        String strCommand = fileChooser.getSelectedFile()
                                .getPath().toString();
                        try {
                            Runtime.getRuntime().exec(strCommand);

                        }

                        catch (IOException ex) {
                            ex.printStackTrace();
                        }
                        break;
                    }
                }
            }
        }
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        new Timing();
    }

}
搜索更多相关主题的帖子: java 软件 时间 用户 
2011-01-10 16:30
快速回复:定时启动软件问题
数据加载中...
 
   



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

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