javacardlayoutdemo.java

来自「这是一个用JAVA语言开发的一个关于卡片布局的使用」· Java 代码 · 共 49 行

JAVA
49
字号
import java.awt.*;
                         import java.awt.event.*;
                         public class CardLayoutDemo implements       MouseListener 
{  Panel p1, p2, p3, p4, p5;
	Label l1, l2, l3, l4, l5; 
	CardLayout myCard;
	Frame f;	
	public static void main (String args[])
	{	CardLayoutDemo ct = new CardLayoutDemo();	ct.init();	}
		public void init()
	{	f = new Frame ("Card Test");
		myCard = new CardLayout();
		f.setLayout(myCard);
			p1 = new Panel();	 
p2 = new Panel();
		p3 = new Panel(); 	
p4 = new Panel(); 
		p5 = new Panel();
			l1 = new Label("This is the first Panel"); 
		p1.setBackground(Color.yellow);
		p1.add(l1);	p1.addMouseListener(this);
		l2 = new Label("This is the second Panel");
		p2.setBackground(Color.green);
		p2.add(l2);	p2.addMouseListener(this);
		l3 = new Label("This is the third Panel"); 
p3.setBackground(Color.magenta); 
		p3.add(l3); 	p3.addMouseListener(this);
		l4 = new Label("This is the fourth Panel"); 
		p4.setBackground(Color.white); 
		p4.add(l4);	p4.addMouseListener(this);
		l5 = new Label("This is the fifth Panel"); 
		p5.setBackground(Color.cyan);
		p5.add(l5);	p5.addMouseListener(this);
			f.add(p1, "First");	

f.add(p2, "Second"); 
		f.add(p3, "Third");	
f.add(p4, "Fourth");
		f.add(p5, "Fifth");
	myCard.show(f, "First");
		f.setSize (200, 200);
		f.setVisible(true); 	}	
	public void mouseClicked(MouseEvent e) {myCard.next(f);}
		public void mousePressed(MouseEvent e){}
public void mouseReleased(MouseEvent e) {}
		public void mouseEntered(MouseEvent e) {}
		public void mouseExited(MouseEvent e) {}
         }

⌨️ 快捷键说明

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