?? testcardlayout.java
字號:
import java.awt.*;
import java.awt.event.*;
/**
* Description:
* <br/>Copyright (C), 2005-2008, Yeeku.H.Lee
* <br/>This program is protected by copyright laws.
* <br/>Program Name:
* <br/>Date:
* @author Yeeku.H.Lee kongyeeku@163.com
* @version 1.0
*/
public class TestCardLayout
{
Frame f = new Frame("測試窗口");
String[] names = {"第一張" , "第二張" , "第三張" , "第四張" , "第五張"};
Panel pl = new Panel();
CardLayout c = new CardLayout();
public void init()
{
pl.setLayout(c);
for (int i = 0 ; i < names.length ; i++)
{
pl.add(names[i] , new Button(names[i]));
}
Panel p = new Panel();
//控制顯示上一張的按鈕
Button previous = new Button("上一張");
previous.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
c.previous(pl);
}
});
//控制顯示下一張的按鈕
Button next = new Button("下一張");
next.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
c.next(pl);
}
});
//控制顯示第一張的按鈕
Button first = new Button("第一張");
first.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
c.first(pl);
}
});
//控制顯示最后一張的按鈕
Button last = new Button("最后一張");
last.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
c.last(pl);
}
});
//控制根據Card名顯示的按鈕
Button third = new Button("第三張");
third.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
c.show(pl , "第三張");
}
});
p.add(previous);
p.add(next);
p.add(first);
p.add(last);
p.add(third);
f.add(pl);
f.add(p , BorderLayout.SOUTH);
f.pack();
f.setVisible(true);
}
public static void main(String[] args)
{
new TestCardLayout().init();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -