|
Posted by Ike on 11/18/34 11:43
here is a little java applicaiton I wrote -- if you need the compiled files
I can send them - email me rvince99 at hotmail dot com. Anyhow, you merely
specify how many seconds you want to wait before re-invoking something. For
instance, if I want to execute test.php and it is in c:\x, my command would
be:
c:\php\php.exe c:\x\test.php
I wrote this so that php scripts, java pplications, etc., can be invoked
every X seconds without regard to platform.
/*
* JavaChron.java
*
* Created on March 17, 2006, 1:52 PM
*/
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
/**
*
* @author R. Vince
*/
public class JavaChron extends javax.swing.JFrame {
public javax.swing.Timer timer;
public int delayseconds;
public String commander;
Properties properties;
/** Creates new form JavaChron */
public JavaChron() {
// Read properties file.
initComponents();
show();
pack();
properties = new Properties();
try {
properties.load(new FileInputStream("JavaChron.properties"));
} catch (IOException ioe) {
}
jTextField2.setText(properties.getProperty("delayseconds"));
jTextField1.setText(properties.getProperty("commander"));
}
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jTextField2 = new javax.swing.JTextField();
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
jButton1.setText("Go");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPanel1.add(jButton1);
getContentPane().add(jPanel1, java.awt.BorderLayout.EAST);
jLabel1.setText("Command");
jPanel2.add(jLabel1);
jTextField1.setMinimumSize(new java.awt.Dimension(11, 40));
jTextField1.setPreferredSize(new java.awt.Dimension(200, 20));
jPanel2.add(jTextField1);
jLabel2.setText(" Seconds");
jPanel2.add(jLabel2);
jTextField2.setMinimumSize(new java.awt.Dimension(62, 20));
jTextField2.setPreferredSize(new java.awt.Dimension(62, 20));
jPanel2.add(jTextField2);
getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);
pack();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String s = jTextField2.getText();
delayseconds=Integer.parseInt(s);
commander=jTextField1.getText();
// Write properties file.
properties.setProperty("delayseconds", jTextField2.getText());
properties.setProperty("commander", jTextField1.getText());
try {
properties.store(new FileOutputStream("JavaChron.properties"), null);
} catch (IOException ioe2) {
}
jButton1.setEnabled(false);
jTextField2.setEnabled(false);
jTextField1.setEnabled(false);
timer = new javax.swing.Timer(1000*delayseconds, new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
try {
Process process = Runtime.getRuntime().exec(commander);
//process.waitFor();
} catch (Throwable ex) {
ex.printStackTrace();
}
}
});
timer.setInitialDelay(1000*delayseconds);
timer.start();
}
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
timer.stop();
System.exit(0);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
new JavaChron().show();
}
// Variables declaration
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
}
Navigation:
[Reply to this message]
|