0
点赞
收藏
分享

微信扫一扫

CardLayout(卡片布局管理器)


CardLayout(卡片布局管理器)

效果如下:

CardLayout(卡片布局管理器)_卡片布局管理器

CardLayout(卡片布局管理器)_布局管理器_02

代码如下:

package com.cn.gui.layout;
import java.awt.CardLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import com.cn.gui.util.FrameUtil;
/**
* Author:Liu Zhiyong
* Version:Version_1
* Date:2016年8月13日19:28:30
* Desc:
CardLayout(卡片布局管理器)
*/
public class Demo4 {
public static void main(String[] args) {
JFrame frame = new JFrame("卡片布局管理器窗体");
final JPanel panel = new JPanel();
frame.add(panel);//将面板添加到窗体

//创建卡片布局管理器
final CardLayout cardLayout = new CardLayout();
panel.setLayout(cardLayout);

//往面板添加数据
JButton button = new JButton("按钮1");
panel.add(button);
panel.add(new JButton("按钮2"));
panel.add(new JButton("按钮3"));
panel.add(new JButton("按钮4"));
panel.add(new JButton("按钮1"));

button.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
cardLayout.next(panel); //下一张
// cardLayout.previous(panel);//上一张
}

});

FrameUtil.initFrame(frame, 300, 300);

}
}

举报

相关推荐

布局管理器

Qt布局管理器

【QT】QT布局管理器

0 条评论