昆仑山:眼中无形心中有穴之穴人合一

夫君子之行,静以修身,俭以养德;非澹泊无以明志,非宁静无以致远。夫学须静也,才须学也;非学无以广才,非志无以成学。怠慢则不能励精,险躁则不能冶性。年与时驰,意与岁去,遂成枯落,多不接世。悲守穷庐,将复何及!

 

事件监听实现的套路

版本1

package com.uos.server;


import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;

public class InterfaceInit {

    private static JFrame jFrame;
    private static JPanel jPanel;


    class SimpleListener implements ActionListener {


        public void actionPerformed(ActionEvent e) {
            String buttonName = e.getActionCommand();
            if (buttonName.equals("干起来")) {
                JOptionPane.showMessageDialog(jFrame, "弄疼我了");
                System.out.println("干嘛呀");
            } else if (buttonName.equals("动起来")) {
                JOptionPane.showMessageDialog(jFrame, "爱死我了");
                System.out.println("恩恩爱呀");
            }
        }
    }


    public void init() {

        jFrame = new JFrame("监听事件练习");
        jPanel = new JPanel();

        JButton jButton1 = new JButton("干起来");
        JButton jButton2 = new JButton("动起来");

        SimpleListener simpleListener = new SimpleListener();
        jButton1.addActionListener(simpleListener);
        jButton2.addActionListener(simpleListener);

        jPanel.add(jButton1);
        jPanel.add(jButton2);


        jFrame.add(jPanel);
        jFrame.pack();
        jFrame.setVisible(true);
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }


    public static void main(String[] args) {
        new InterfaceInit().init();
    }


}


版本2


package com.uos.server;


import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;

public class InterfaceInit {

    private static JFrame jFrame;
    private static JPanel jPanel;


    JButton jButton1;
    JButton jButton2;


    public void init() {

        jFrame = new JFrame("监听事件练习");
        jPanel = new JPanel();

        jButton1 = new JButton("干起来");
        jButton2 = new JButton("动起来");
        


        jButton1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(jFrame,"中层干部动起来");
            }
        });
        jButton2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(jFrame,"底层动部动起来");
            }
        });
        




        jPanel.add(jButton1);
        jPanel.add(jButton2);


        jFrame.add(jPanel);
        jFrame.pack();
        jFrame.setVisible(true);
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }


    public static void main(String[] args) {
        new InterfaceInit().init();
    }


}

参考文献

https://www.cnblogs.com/dengyungao/p/7525013.html

posted on 2020-06-17 14:52  Indian_Mysore  阅读(55)  评论(0)    收藏  举报

导航