日期:2014-05-20 浏览次数:20989 次
class Test {
public static void main(String[] args) {
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
Runtime.getRuntime().exec("java Test");
//Test.main(new String[0]); //或者这样试试看
}
});
System.exit(0);
}
}
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Main {
public static void main(final String[] args) {
java.awt.EventQueue.invokeLater(new Runnable(){
public void run(){
final JFrame frame = new JFrame("Main");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setPreferredSize(new Dimension(400,300));
final JButton restart = new JButton("Restart");
restart.addActionListener(new ActionListener(){
@Override public void actionPerformed(ActionEvent e){
Runtime.getRuntime().addShutdownHook(new Thread(){
@Override public void run(){
try {
new ProcessBuilder("java","Main").start();
} catch (IOException e) {
}
}
});