zoukankan      html  css  js  c++  java
  • 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();
      }
    }

  • 相关阅读:
    MSP430的CAN通信发送
    Arduino 101/Genuino101使用-第2篇
    CC2541调试问题记录-第一篇
    STM32运行FreeRTOS出现prvTaskExitError错误死机
    Arduino 101/Genuino101使用-第一篇
    LAUNCHXL-28379D入门学习-第一篇
    蒸汽机的原理
    等高线相似性匹配
    cad转shapefile文件
    ArcGIS坐标转换
  • 原文地址:https://www.cnblogs.com/sunnybowen/p/10014003.html
Copyright © 2011-2022 走看看