zoukankan      html  css  js  c++  java
  • Java GUI 点击按钮退出

    import java.awt.*;
    import java.awt.event.*;
    
    public class TestFrameTwo implements ActionListener
    {
        Frame f = new Frame("((((99999");
        
        public static void main(String[] args)
        {
            TestFrameTwo tf = new TestFrameTwo();
            tf.init();
        }
        
        public void init()
        {
            Button btn = new Button("退出");
            btn.addActionListener(this);
            f.add(btn);
            f.setSize(300,300);
            f.setVisible(true);
        }
        
        public void actionPerformed(ActionEvent e)
        {
            f.setVisible(false);
            f.dispose();
            System.exit(0);
        }
    }

     使用匿名对象版~

    import java.awt.*;
    import java.awt.event.*;
    
    public class TestFrameThree {
        Frame f = new Frame("AAAA");
        public static void main(String[] args)
        {
            new TestFrameThree().init();
        }
        
        public void init()
        {
            Button btn = new Button("退出");
            btn.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    f.setVisible(false);
                    f.dispose();
                    System.exit(0);
                }
            });
            f.add(btn);
            f.setSize(300,300);
            f.setVisible(true);
        }
    }

    确实简洁了很多。。Go Go Go ~

  • 相关阅读:
    01
    商城管理系统
    10
    09
    08
    07(3)
    07(2)
    07
    06
    jsp第一次作业
  • 原文地址:https://www.cnblogs.com/tanglimei/p/6904225.html
Copyright © 2011-2022 走看看