package test;
import java.awt.BorderLayout; import java.awt.Component; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException;
import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel;
public class ExeTest {
/** * @param args */ public static void main(String[] args) throws IOException { // Process process = Runtime.getRuntime().exec("cmd /E:ON /c start notepad.exe"); //"C:\Program Files\MSN Messenger\msnmsgr.exe" JFrameE jfe = new JFrameE(); jfe.setSize(250,100); jfe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jfe.setVisible(true); setCenter(jfe); } public static void setCenter(Component com) { Dimension dd = Toolkit.getDefaultToolkit().getScreenSize(); double width = dd.getWidth(); double height = dd.getHeight(); int left = ((int)width - com.getWidth())/2; int top = ((int)height-com.getHeight())/2; com.setLocation(left, top); }
}
class JFrameE extends JFrame { JButton jb_note = new JButton("记事本"); JButton jb_qq = new JButton("QQ"); JButton jb_msn = new JButton("MSN"); Process process; public JFrameE() { JPanel jp = new JPanel(); jp.setLayout(new GridLayout(1,3)); jb_note.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { try{ process = Runtime.getRuntime().exec("cmd /E:ON /C start notepad.exe"); }catch(IOException ee) { e.paramString(); } } }); jb_qq.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { try{ process = Runtime.getRuntime().exec("cmd /E:ON /C start c:\\\"Program Files\\Tencent\\QQ\\QQ.exe"); }catch(IOException ee) { e.paramString(); } } }); jb_msn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { try{ process = Runtime.getRuntime().exec("cmd /E:ON /C start c:\\\"Program Files\\MSN Messenger\\msnmsgr.exe"); }catch(IOException ee) { e.paramString(); } } }); jp.add(jb_note); jp.add(jb_qq); jp.add(jb_msn); getContentPane().add(jp); } }
|
评论