展开全部
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.CardLayout;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Label;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class Ceshi extends Frame
{
private static final long serialVersionUID = 1L;
PanelF pf = new PanelF ();
PanelS ps = new PanelS ();
Panel panelMain, panelXZ;
Button btNext, btPrevious, bt1, bt2, bt3, bt4, bt5;
CardLayout cl;
Boolean w = false;
public Ceshi ()
{
cl = new CardLayout ();
panelMain = new Panel (cl);// 被设定为卡片布局的面板
panelXZ = new Panel ();// 构造放按钮的面板
btPrevious = new Button ("上一页62616964757a686964616fe58685e5aeb931333337383837");
btNext = new Button ("下一页");
bt1 = new Button ("1");
bt2 = new Button ("2");
// 给定义为卡片布局的面板添加面板
panelMain.add (pf, "pf");
panelMain.add (ps, "ps");
panelXZ.add (btPrevious);
panelXZ.add (btNext);
panelXZ.add (bt1);
panelXZ.add (bt2);
btPrevious.addActionListener (new ActionListener ()
{
@Override
public void actionPerformed ( ActionEvent e )
{
cl.previous (panelMain);
}
});
btNext.addActionListener (new ActionListener ()
{// 下一页的按钮
public void actionPerformed ( ActionEvent e )
{
cl.next (panelMain);
}
});
bt1.addActionListener (new ActionListener ()
{// 跳转到第二个面板的按钮
public void actionPerformed ( ActionEvent e )
{
cl.show (panelMain, "pf");
}
});
bt2.addActionListener (new ActionListener ()
{// 跳转到第二个面板的按钮
public void actionPerformed ( ActionEvent e )
{
cl.show (panelMain, "ps");
}
});
addWindowListener (new WindowAdapter ()
{
public void windowClosing ( WindowEvent wevent )
{
System.exit (0);
}
});
panelXZ.setLayout (new FlowLayout ());
setTitle ("主界面");
setSize (800, 600);
setLocationRelativeTo (null);
add (panelMain, BorderLayout.CENTER);// 把设为卡片布局的面板放置在窗体中间
add (panelXZ, BorderLayout.SOUTH);// 把带按钮的面板放置在底部
setVisible (true);
}
public static void main ( String args[] )
{
new Ceshi ();
}
}
// 第一个面板
class PanelF extends Panel
{
private static final long serialVersionUID = 1L;
public PanelF ()
{
add (new Label ("第一个面板"));
}
}
// 第二个面板
class PanelS extends Panel
{
private static final long serialVersionUID = 1L;
public PanelS ()
{
add (new Label ("第二个面板"));
}
}