给按钮加监听啊。         JButton btn = new JButton("OK");
         btn.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                 //你的程序入口
             }
         });

解决方案 »

  1.   

    先谢过了
    JButton实现ActionListener接口我是知道的
    我不明白程序入口是什么意思,是不是main()函数 
    可我的main函数在我的一个class里面,怎么放到ActionPerformedli里面
    public class TestP()
    {
           public static void main(String [] args)
           {
                  TestPFrame frame = new TestPFrame();
                  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                  frame.show();
            }
    }    
      

  2.   


             JButton btn = new JButton("OK");
             btn.addActionListener(new ActionListener() {
                 public void actionPerformed(ActionEvent e) {
                  TestPFrame frame = new TestPFrame();
                  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                  frame.show();
            }
             });
      

  3.   

    可以使用relect方法:
      Class cls = Class.forName("TestPFrame");
      Method method = cls.getMethod("main", new Class[]{ String[].class });
      method.invoke(cls, new Object[]{new String[0]});OK?
      

  4.   

    当然,直接这样也可以:
       String[] arg = new String[0];
       TestPFrame.main(arg);
      

  5.   

    JButton btn = new JButton("do");
             btn.addActionListener(new ActionListener() {
                 public void actionPerformed(ActionEvent e) {             yourclasstype yourinstance= new yourclass();
                 yourinstance.yourmethod();          }
            } 
      

  6.   

    谢谢各位大虾的大力支持
    geyf(我在学java):你说的我有一点疑问,我要加的“确定”键 是想放在我的main函数frame里的
    内容窗阁中,此窗阁中还有其他的按钮,我现在不明白的是你的btn键是放在哪里的,好象少了在某个内容窗阁中的contentpane.add(btn);我再回去看看juhwali(华仔):你说的方法我还没见过,要回去查资料试试,:) 
      

  7.   

    btn就是放在frame的contentpane里呗,和其他按钮一样
    getContentPane().add(btn);