珠沙落吧 关注:86贴子:8,475
  • 2回复贴,共1


1楼2008-01-07 13:48回复
    import java.awt.Container; 
    import java.awt.GridLayout; 
    import java.awt.event.ActionEvent; 
    import java.awt.event.ActionListener; 
    import java.io.IOException; 

    import javax.swing.JButton; 
    import javax.swing.JFrame; 
    public class ShowGridLayout extends JFrame { 
    public ShowGridLayout() { 
    Container container = getContentPane(); 
    container.setLayout(new GridLayout(3, 3, 4, 4)); 
    JButton regeditButton = new JButton("regedit.exe----注册表"); 
    regeditButton.addActionListener(new ActionListener(){ 
    public void actionPerformed(ActionEvent arg0) { 
    try { 
    String cmdStr = "regedit"; 
    Runtime.getRuntime().exec(cmdStr); 
    } catch (IOException e) { 



    }); 
    container.add(regeditButton); 

    JButton winmsdButton = new JButton("winmsd-------系统信息"); 
    winmsdButton.addActionListener(new ActionListener(){ 
    public void actionPerformed(ActionEvent arg0) { 
    try { 
    String cmdStr = "winmsd"; 
    Runtime.getRuntime().exec(cmdStr); 
    } catch (IOException e) { 



    }); 
    container.add(winmsdButton); 

    JButton calcButton = new JButton("calc-------启动计算器"); 
    calcButton.addActionListener(new ActionListener(){ 
    public void actionPerformed(ActionEvent arg0) { 
    try { 
    String cmdStr = "calc"; 
    Runtime.getRuntime().exec(cmdStr); 
    } catch (IOException e) { 



    }); 
    container.add(calcButton); 

    JButton notepadButton = new JButton("notepad----打开记事本"); 
    notepadButton.addActionListener(new ActionListener(){ 
    public void actionPerformed(ActionEvent arg0) { 
    try { 
    String cmdStr = "notepad"; 
    Runtime.getRuntime().exec(cmdStr); 
    } catch (IOException e) { 



    }); 
    container.add(notepadButton); 

    JButton progButton = new JButton("progman----程序管理器"); 
    progButton.addActionListener(new ActionListener(){ 
    public void actionPerformed(ActionEvent arg0) { 
    try { 
    String cmdStr = "progman"; 
    Runtime.getRuntime().exec(cmdStr); 
    } catch (IOException e) { 



    }); 
    container.add(progButton); 

    JButton shutdownButton = new JButton("tsshutdn-----关机命令"); 
    progButton.addActionListener(new ActionListener(){ 
    public void actionPerformed(ActionEvent arg0) { 
    try { 
    String cmdStr = "rononce /c -p"; 
    Runtime.getRuntime().exec(cmdStr); 
    } catch (IOException e) { 



    }); 
    container.add(shutdownButton); 


    public static void main(String[] args) { 
    ShowGridLayout frame = new ShowGridLayout(); 
    frame.setTitle("快速命令1.0"); 
    frame.setSize(400, 400); 
    frame.setVisible(true); 
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 

    }


    2楼2008-01-07 14:15
    回复
      2025-08-11 18:58:39
      广告
      不感兴趣
      开通SVIP免广告
      • 60.176.120.*
      控制生成的java的界面的位置

      如界面名为frame,则可以根据这个语法来设置:

      frame.setBounds(100,100,200,300);

      意思是设置frame的大小为100*100,左边距为200,上边距为300.

      //获得屏幕的分辨率
      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

      //获得当前frame的大小
      Dimension frameSize = loginFrame.getSize();

      //设置居于屏幕正中央
      loginFrame.setLocation( (screenSize.width - frameSize.width) /2,(screenSize.height - frameSize.height) / 2);

      *******************************************

      import java.awt.FlowLayout;
      import java.awt.event.*;
      import javax.swing.*;

      class SumTest {
      private int x;
      private int y;

      public SumTest() {
      setXY();
      }

      private void setXY() {
      this.x = (int) (Math.random() * 100);
      this.y = (int) (Math.random() * 100);
      }
      public int getX() {
      return x;
      }
      public int getY() {
      return y;
      }
      public String display() {
      return "X :" + getX() + " Y :" + getY();
      }

      }

      public class Panel extends JFrame {

      private static final long serialVersionUID = 1L;
      private JLabel labelDisplay;
      private JLabel labelSum;
      private JLabel labelError;
      private JTextField textFieldSum;
      private JButton submitButton;
      private JButton cancelButton;
      private SumTest st;
      private int x;
      private int y;

      private Panel(){
      super("Add Check");
      st = new SumTest();
      x = st.getX();
      y = st.getY();
      }

      private void PanelMethod(){

      setDefaultCloseOperation(EXIT_ON_CLOSE);
      getContentPane().setLayout(new FlowLayout());

      labelSum = new JLabel("SumResult:");
      labelDisplay = new JLabel();
      labelDisplay.setText(st.display() + " ");
      textFieldSum = new JTextField(5);

      submitButton = new JButton("Sumbit");
      cancelButton = new JButton("Clear");

      labelError = new JLabel();

      class cleanB implements ActionListener {
      public void actionPerformed(ActionEvent arg0) {
      textFieldSum.setText("");
      }
      }

      class submitB implements ActionListener {

      public void actionPerformed(ActionEvent arg0){
      String sum = "";
      int sumResult = 0;
      sum = textFieldSum.getText();
      try {
      sumResult = Integer.parseInt(sum);
      } catch (NumberFormatException e) {
      e.printStackTrace();
      }
      if(x+y == sumResult) {
      labelError.setText("Right");
      } else {
      labelError.setText("Wrong!Input Again");
      }
      }
      }


      cancelButton.addActionListener(new cleanB());
      submitButton.addActionListener(new submitB());

      getContentPane().add(labelDisplay);
      getContentPane().add(labelSum);
      getContentPane().add(textFieldSum);
      getContentPane().add(submitButton);
      getContentPane().add(cancelButton);
      getContentPane().add(labelError);

      setSize(180, 160);
      }

      public static void main(String[] args){
      final Panel frame = new Panel();
      frame.PanelMethod();
      frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
      frame.setLocation(400, 400);
      frame.setResizable(false);
      frame.setVisible(true);
      }
      }


      3楼2008-01-08 11:15
      回复