* * Open File principle: Invoke cmd command to execute * * */import java.awt.BorderLayout;
Import Java.awt.EventQueue;
Import Javax.swing.JFrame;
Import Javax.swing.JPanel;
Import Javax.swing.border.EmptyBorder;
Import Javax.swing.JButton;
Import Java.awt.event.ActionListener;
Import java.awt.event.ActionEvent;
Import java.io.IOException;
public class SS extends JFrame {private JPanel contentpane; public static void Main (string[] args) {Eventqueue.invokelater (new Runnable () {public void run () {try {s
s frame = new SS ();
Frame.setvisible (TRUE);
catch (Exception e) {e.printstacktrace ();
}
}
});
Public SS () {setdefaultcloseoperation (jframe.exit_on_close);
SetBounds (100, 100, 450, 300);
ContentPane = new JPanel ();
Contentpane.setborder (New Emptyborder (5, 5, 5, 5));
Setcontentpane (ContentPane);
Contentpane.setlayout (NULL);
JButton Btnnewbutton = new JButton ("\u6253\u5f00\u8ba1\u7b97\u5668"); Btnnewbutton.addactionlistener (new ActionListener () {publicvoid actionperformed (ActionEvent e) {try {//Open calculator runtime.getruntime (). EXEC ("calc");
Use Notepad to open the local TXT file//runtime.getruntime (). EXEC ("notepad d:/help.txt");
catch (IOException E1) {e1.printstacktrace ();
}
}
});
Btnnewbutton.setbounds (79, 60, 137, 23);
Contentpane.add (Btnnewbutton);
JButton Btnexe = new JButton ("\u8fd0\u884c\u672c\u5730exe"); Btnexe.addactionlistener (new ActionListener () {public void actionperformed (ActionEvent e) {try {//open local EXE
Pieces can be absolute or relative path relative path in the engineering directory to create a folder Runtime.getruntime (). EXEC ("exe/registered patch");
catch (IOException E1) {e1.printstacktrace ();
}
}
});
Btnexe.setbounds (79, 166, 137, 23);
Contentpane.add (Btnexe); JButton btnnewbutton_1 = new JButton ("\u53ef\u6253\u5f00\u8fd0\u884c\u672c\u5730\u7684\u6587\u4ef6 \u4efb\u610f\
u683c\u5f0f "); Btnnewbutton_1.addactionlistener (new ActionListener () {public void actionperformed (ActionEvent e) {//Open any local file String cmd= "rundll32 url.dll fileprotocolhandler File://D:/mysqljdbc.png";
try {Process p = runtime.getruntime (). exec (CMD);
catch (IOException E1) {e1.printstacktrace ();
}
}
});
Btnnewbutton_1.setbounds (79, 117, 223, 23);
Contentpane.add (btnnewbutton_1);
JButton button = new JButton ("\u6253\u5f00\u7f51\u5740");
Button.addactionlistener (new ActionListener () {public void actionperformed (ActionEvent e) {try {//Open URL
Runtime.getruntime (). EXEC ("cmd/c start IExplore http://www.baidu.com");
catch (IOException E1) {e1.printstacktrace ();
}
}
});
Button.setbounds (81, 214, 93, 23);
Contentpane.add (button);
}
}