• Java(41)_卡片布局管理器


    package MYSQK.example01;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    
    /**
     * 卡片布局管理器
     */
    class Layout extends Frame implements ActionListener {
        CardLayout cardLayout = new CardLayout();//定义卡片布局管理器
        Panel cardPanel = new Panel();//定义面板放卡片
        Panel controlPanel = new Panel();//定义面板放置按钮
        Button preButton;//按钮声明
        Button nextButton;
    
        public  Layout(){
            this.setSize(300,200);//设置窗体大小
            cardPanel.setLayout(cardLayout);//设置布局为卡管理器 把cardPanel,而不是当前窗体!!!this
            cardPanel.add(new Label("FistCard",Label.CENTER));
            cardPanel.add(new Label("SecondCard",Label.CENTER));
            cardPanel.add(new Label("ThirdCard",Label.CENTER));
    
            nextButton = new Button("Next");
            preButton = new Button("Back");
    
            controlPanel.add(preButton);
            controlPanel.add(nextButton);
    
            this.add(cardPanel,BorderLayout.CENTER);
            this.add(controlPanel,BorderLayout.SOUTH);
    
            //为按钮添加事件监听器
            nextButton.addActionListener(this);
            preButton.addActionListener(this);
    
            this.addWindowListener(new WindowAdapter() {
                public void  windowClosing(WindowEvent e){
                    Layout.this.dispose();
                }
            });
    
            this.setVisible(true);
    
        }
         @Override
        public  void actionPerformed(ActionEvent e){
            // 如果用户点击向后按钮
             if(e.getSource()==nextButton){
                 cardLayout.next(cardPanel);
             }
             if(e.getSource()==preButton){
                 cardLayout.previous(cardPanel);
             }
        }
    }
    public class example01 {
      public  static  void  main(String[] args){
           Layout layout = new Layout();
      }
    }

  • 相关阅读:
    .csproj文件
    堆栈
    数据库操作(一)
    Math数学函数
    SSM框架下各个层的解释说明
    MyBatis DAO层传递参数到mapping.xml
    Spring MVC3在controller和视图之间传递参数的方法
    注册/登陆界面验证码的作用及代码实现
    input中name和id的区别
    <mvc:default-servlet-handler/>的作用
  • 原文地址:https://www.cnblogs.com/sunnybowen/p/10014003.html
Copyright © 2020-2023  润新知