⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cardlayouttest.java

📁 实例精华
💻 JAVA
字号:
package AWTSWING;

import java.awt.event.*;
import java.awt.*;

public class CardLayoutTest implements ActionListener {

    Frame f = new Frame();
    Panel p = new Panel();
    CardLayout my;

    public void actionPerformed(ActionEvent e)
    {
        //可以得到按钮上的文字,返回的是字符串
        String s = e.getActionCommand();
        System.out.println(s);
       if(s.equals("前"))
        {
            my.previous(p);
        }
        if(s.equals("后"))
        {
            my.next(p);
        }
    }

    public CardLayoutTest()
    {

        Button b1 = new Button("前");
        Button b2 = new Button("后");
        f.setLayout(new FlowLayout());
        //!!!
        my = new CardLayout();
        p.setLayout(my);
        String[] s = {"a","b","c","d","e"};
        Label[] lb = new Label[s.length];
        for(int i = 0;i<s.length;i++)
        {
            lb[i] = new Label(s[i]);
            p.add(s[i],lb[i]);
        }
        b1.addActionListener(this);
        b2.addActionListener(this);
        f.add(b1);
        f.add(b2);
        f.add(p);
        f.setSize(200,200);
        f.setVisible(true);
    }

    public static void main(String[] args)
    {
        CardLayoutTest clt = new CardLayoutTest();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -