piyrunner.java
字号:
package piy;
import java.io.*;
import javax.swing.UIManager;
import java.util.*;
import java.util.jar.*;
import java.util.zip.*;
/**
* Runs a PIY Application Object. The object will be loaded from a file specified in
* the arguments sent to the main method. Note: If it's possible for the PIYRunner to
* know the identity of the Jar file it is loaded from, we could set this up to
* automatically run the application object.
* @author David Vivash
* @version 1.0.1, 21/04/01
*/
public class PIYRunner implements Observer {
public static void main(String[] args) {
if (args.length == 0) {
System.out.println("Runs a PIY Application Object.");
System.out.println("Usage java -jar <filename> <filename>");
System.out.println("Type 'java -jar <filename> <filename> -lf System' to get the system look and feel");
System.out.println("Example 1: java -jar MyApp.jar MyApp.jar");
System.out.println("Example 2: java -jar Notepad.jar Notepad.jar -lf system");
} else {
//Use the system look and feel
if (args.length == 3) {
if (args[1].equalsIgnoreCase("-lf") && args[2].equalsIgnoreCase("System"))
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
//carry on regardless - ie. use standard look and feel
}
}
try{
System.setErr(new PrintStream(new FileOutputStream("Error.log")));
} catch (Exception e) {
//carry on regardless - ie. use standard error output
}
new PIYRunner().runApplication(args[0]);
}
}
/**
* Load and run the Application with the specified filename. The filename should be a valid
* jar archive containing an application object named "Compiled".
* @param filename the string representation of the filename of the application to load and run
*/
public void runApplication(String filename) {
try{
JarFile file = new JarFile(filename);
ZipEntry appEntry = file.getEntry("Compiled");
ObjectInputStream ois = new ObjectInputStream(file.getInputStream(appEntry));
Application app = (Application)ois.readObject();
ois.close();
//tell the application manager about our application, then run it
ApplicationManager.getInstance().setApplication(app);
app.start();
//monitor the application so we can be told when it wishes to terminate
new Thread(new ApplicationMonitor(app, (Observer)this)).start();
} catch (Exception e) {
System.out.println("Error loading application - " + filename);
e.printStackTrace();
}
}
//called when the application wishes to terminate
public void update(Observable o, Object arg) {
System.exit(0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -