Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
CardLayoutDemo.java
Package: Java.rar [view]
Upload User: szfcled
Upload Date: 2022-06-12
Package Size: 236k
Code Size: 2k
Category:
File Formats
Development Platform:
Java
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class CardLayoutDemo extends MouseAdapter {
- JPanel p1,p2,p3,p4,p5;
- JLabel l1,l2,l3,l4,l5;
- //声明一个CardLayout 对象
- CardLayout myCard;
- JFrame frame;
- Container contentPane;
- public static void main (String args[]) {
- CardLayoutDemo that = new CardLayoutDemo();
- that.go();
- }
- public void go() {
- frame = new JFrame ("Card Test");
- contentPane = frame.getContentPane();
- myCard = new CardLayout();
- //设置CardLayout 布局管理器
- contentPane.setLayout(myCard);
- p1 = new JPanel();
- p2 = new JPanel();
- p3 = new JPanel();
- p4 = new JPanel();
- p5 = new JPanel();
- //为每个JPanel创建一个标签并设定不同的
- //背景颜色,以便于区分
- l1 = new JLabel("This is the first JPanel");
- p1.add(l1);
- p1.setBackground(Color.white);
- l2 = new JLabel("This is the second JPanel");
- p2.add(l2);
- p2.setBackground(Color.black);
- l3 = new JLabel("This is the third JPanel");
- p3.add(l3);
- p3.setBackground(Color.magenta);
- l4 = new JLabel("This is the fourth JPanel");
- p4.add(l4);
- p4.setBackground(Color.yellow);
- l5 = new JLabel("This is the fifth JPanel");
- p5.add(l5);
- p5.setBackground(Color.red);
- // 设定鼠标事件的监听程序
- p1.addMouseListener(this);
- p2.addMouseListener(this);
- p3.addMouseListener(this);
- p4.addMouseListener(this);
- p5.addMouseListener(this);
- //将每个JPanel作为一张卡片加入frame的内容窗格
- contentPane.add(p1, "First");
- contentPane.add(p2, "Second");
- contentPane.add(p3, "Third");
- contentPane.add(p4, "Fourth");
- contentPane.add(p5, "Fifth");
- //显示第一张卡片
- myCard.show(contentPane, "First");
- frame.setSize(300, 200);
- frame.show();
- }
- // 处理鼠标事件,每当敲击鼠标键时,即显示下一张卡片。
- // 如果已经显示到最后一张,则重新显示第一张。
- public void mouseClicked(MouseEvent e) {
- myCard.next(contentPane);
- }
- }