java: Adapter Patterns

2022/9/17 1:17:12

本文主要是介绍java: Adapter Patterns,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

 

/**
 * 版权所有 2022 涂聚文有限公司
 * 许可信息查看:
 * 描述:
 * 适配器模式 Adapter Patterns
 * 历史版本: JDK 14.02
 * 2022-09-12 创建者 geovindu
 * 2022-09-12 添加 Lambda
 * 2022-09-12 修改:date
 * 接口类
 * 2022-09-12 修改者:Geovin Du
 * 生成API帮助文档的指令:
 *javadoc - -encoding Utf-8 -d apidoc SwingUI.java
 *
 * */


package com.javapatterns.adapter;

import java.awt.Color;
import java.awt.BorderLayout;
import java.awt.event.*;
import javax.swing.*;

/**
 *
 * @param
 * @author geovindu
 *
 * */
public class SwingUI  extends JFrame implements ActionListener{

    JLabel text, clicked,dutext;
    JButton button, clickButton;
    JPanel panel;
    private boolean m_clickMeMode = true;

    /**
     * @label Uses
     * @directed
     *
     */
    private WindowAdapter lnkWindowAdapter;

     public SwingUI()
    {
        text = new JLabel("我很高兴!");
        dutext=new JLabel("geovindu,"+"Geovin Du,涂聚文");
        button = new JButton("理我");
        button.addActionListener(this);

        panel = new JPanel();
        panel.setLayout(new BorderLayout());
        panel.setBackground(Color.white);
        getContentPane().add(panel);
        panel.add(BorderLayout.CENTER, text);
        panel.add(BorderLayout.EAST,dutext);
        panel.add(BorderLayout.SOUTH, button);
    }
     /**
      *
      * @param
      *
      * */
    public void actionPerformed(ActionEvent event)
    {
        Object source = event.getSource();
        if (m_clickMeMode)
        {
            text.setText("我很烦!");
            button.setText("别理我");
            dutext.setText("Geovin Du,涂聚文");
            m_clickMeMode = false;
        }
        else
        {
            text.setText("我很高兴!");
            button.setText("理我");
            dutext.setText("涂聚文");
            m_clickMeMode = true;
        }
    }

}

  

调用测试:

//适配器模式
            SwingUI frame=new SwingUI();
            frame.setTitle("我是涂聚文");
            WindowListener listener = new WindowAdapter()
            {
                public void windowClosing(WindowEvent e)
                {
                    System.out.println("关窗了!");
                    System.exit(0);
                }
            };

            frame.addWindowListener(listener);
            frame.pack();
            frame.setVisible(true);

  

输出:

 



这篇关于java: Adapter Patterns的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程