请问如何在多个面板间使用CardLayout布局管理器呢?如能给代码,大谢.
解决方案 »
- 亲们,我问个令我纠结的问题
- java 如何将一个时间字符串转换为时间戳?
- 如何将Jtable指定行删除?
- 问个关于线程 暂停 继续的问题,希望有代码示例,谢谢。
- 大家帮忙看看,我初学java,第一个java程序,第一个java问题:编译提示MyFirstJavaProgram.java:1: 'class' or 'interface' expected
- 怎么编译一个文件下面所有的java源文件,包括子文件夹中的哟
- 问个cmd控制台的问题
- 这是什么异常?
- 哪位有用java实现ftp的源程序,急用
- 为什么:win98下不能显示,win2000下可以显示.
- resin和mysql做的电影网站的cpu占用问题
- 输出流的迷惑——在线等马上给分
south.add("perform",perform_in_south);//上面的语句是添加两个面版到south中去,
//下面是响应事件
if(evt.target instanceof Component &&
((Component)evt.target).getParent().equals())
import java.awt.event.*;public class exec
{
public static void main(String args[])
{
MyFrame m=new MyFrame("OK");
m.setSize(200,400);
m.setVisible(true);
}
}class MyFrame extends Frame implements ActionListener
{
CardLayout c=new CardLayout();
Label l1=new Label("Label1");
Label l2=new Label("Label2");
Label l3=new Label("Label3"); Button b1=new Button("<-");
Button b2=new Button("->"); Panel p1=new Panel();
Panel p2=new Panel();
public MyFrame(String title)
{
super(title);
setLayout(new FlowLayout(FlowLayout.CENTER,0,0));
p1.setLayout(c);
l1.setBackground(Color.red);
l2.setBackground(Color.green);
l3.setBackground(Color.blue);
p1.add("a",l1);//用“1”,“one”皆可
p1.add("b",l2);
p1.add("c",l3);
add(p1);
p2.setLayout(new FlowLayout(FlowLayout.CENTER,0,50));
p2.add(b1);
p2.add(b2);
add(p2);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
Graphics g=getGraphics();
if(e.getSource()==b1)c.previous(p1);//上一个
if(e.getSource()==b2)c.next(p1);//下一个
}
}楼主
希望对你有帮助
看了你的东西,感到很受益。