import java.awt.*;
import java.awt.event.*;class CardStart
{
public static void main(String[] args)
{
CardTest c=new CardTest("MyCardLayoutTest");
}
}class CardTest extends Frame
{
Panel t1=new Panel();
Panel t2=new Panel();
Panel t3=new Panel();
Panel t4=new Panel();
Panel p1=new Panel();
Panel p2=new Panel();
Button b1=new Button();
Button b2=new Button();
Button b3=new Button();
Button b4=new Button();
CardLayout cl=new CardLayout();
Label l1=new Label("The Number 1 CardPage");
Label l2=new Label("The Number 2 CardPage");
Label l3=new Label("The Number 3 CardPage");
Label l4=new Label("The Number 4 CardPage");
public CardTest(String s)
{
super(s);
MyWL mw=new MyWL(this);
myML mm=new myML(this); this.addWindowListener(mw);
this.p2.addMouseListener(mm); b1.setSize(30,5);
this.setLayout(new BorderLayout());
this.setSize(500,400);
p2.setSize(500,200); t1.add(l1);
t2.add(l2);
t3.add(l3);
t4.add(l4); p1.setLayout(cl);
p1.add("a",t1);
p1.add("b",t2);
p1.add("c",t3);
p1.add("d",t4); p2.setLayout(new FlowLayout());
p2.add(b1);
p2.add(b2);
p2.add(b3);
p2.add(b4); p1.setBackground(Color.blue);
p2.setBackground(Color.red);
this.add(p2,BorderLayout.SOUTH);
this.add(p1,BorderLayout.CENTER);
this.setResizable(false);
this.setVisible(true);
}
public void T1()
{
cl.show(p1,"a");
}
public void T2()
{
cl.show(p1,"b");
}
public void T3()
{
cl.show(p1,"c");
}
public void T4()
{
cl.show(p1,"d");
}
}class MyWL extends WindowAdapter
{
CardTest t;
public MyWL(CardTest ct)
{
t=ct;
}
public void windowClosing(WindowEvent we)
{
t.dispose();
}
}
class myML extends MouseAdapter
{
CardTest t;
public myML(CardTest ct)
{
t=ct;
}
public void mouseClicked(MouseEvent me)
{
if((Button)me.getSource()==t.b1)
{
t.T1();
}
else if((Button)me.getSource()==t.b2)
{
t.T2();
}
else if((Button)me.getSource()==t.b3)
{
t.T3();
}
else if((Button)me.getSource()==t.b4)
{
t.T4();
}
}
}整个程序很简单,就是想联系CARDLAYOUT和其他的,但是发现就算不管封装性,把他们的PRIVATE都去掉,现在还是点了BUTTON不给我翻页,郁闷死了,而且,我明明设定的是500,200给的下边的PANEL,但是,大家运行都能看到,比例就不是我设定的哪个嘛,而且怎么改都改不动,我的BUTTON的大小也改不动,不论是用SETBOUNDS还是SETSIZE,郁闷了
import java.awt.event.*;class CardStart
{
public static void main(String[] args)
{
CardTest c=new CardTest("MyCardLayoutTest");
}
}class CardTest extends Frame
{
Panel t1=new Panel();
Panel t2=new Panel();
Panel t3=new Panel();
Panel t4=new Panel();
Panel p1=new Panel();
Panel p2=new Panel();
Button b1=new Button();
Button b2=new Button();
Button b3=new Button();
Button b4=new Button();
CardLayout cl=new CardLayout();
Label l1=new Label("The Number 1 CardPage");
Label l2=new Label("The Number 2 CardPage");
Label l3=new Label("The Number 3 CardPage");
Label l4=new Label("The Number 4 CardPage");
public CardTest(String s)
{
super(s);
MyWL mw=new MyWL(this);
myML mm=new myML(this); this.addWindowListener(mw);
this.p2.addMouseListener(mm); b1.setSize(30,5);
this.setLayout(new BorderLayout());
this.setSize(500,400);
p2.setSize(500,200); t1.add(l1);
t2.add(l2);
t3.add(l3);
t4.add(l4); p1.setLayout(cl);
p1.add("a",t1);
p1.add("b",t2);
p1.add("c",t3);
p1.add("d",t4); p2.setLayout(new FlowLayout());
p2.add(b1);
p2.add(b2);
p2.add(b3);
p2.add(b4); p1.setBackground(Color.blue);
p2.setBackground(Color.red);
this.add(p2,BorderLayout.SOUTH);
this.add(p1,BorderLayout.CENTER);
this.setResizable(false);
this.setVisible(true);
}
public void T1()
{
cl.show(p1,"a");
}
public void T2()
{
cl.show(p1,"b");
}
public void T3()
{
cl.show(p1,"c");
}
public void T4()
{
cl.show(p1,"d");
}
}class MyWL extends WindowAdapter
{
CardTest t;
public MyWL(CardTest ct)
{
t=ct;
}
public void windowClosing(WindowEvent we)
{
t.dispose();
}
}
class myML extends MouseAdapter
{
CardTest t;
public myML(CardTest ct)
{
t=ct;
}
public void mouseClicked(MouseEvent me)
{
if((Button)me.getSource()==t.b1)
{
t.T1();
}
else if((Button)me.getSource()==t.b2)
{
t.T2();
}
else if((Button)me.getSource()==t.b3)
{
t.T3();
}
else if((Button)me.getSource()==t.b4)
{
t.T4();
}
}
}整个程序很简单,就是想联系CARDLAYOUT和其他的,但是发现就算不管封装性,把他们的PRIVATE都去掉,现在还是点了BUTTON不给我翻页,郁闷死了,而且,我明明设定的是500,200给的下边的PANEL,但是,大家运行都能看到,比例就不是我设定的哪个嘛,而且怎么改都改不动,我的BUTTON的大小也改不动,不论是用SETBOUNDS还是SETSIZE,郁闷了
解决方案 »
- 为什么在执行线程是重画圆时还是在一个位置?
- 帮个忙,这个运行异常怎么解决?
- 菜鸟求助java数据库连接问题?
- 静态字段的一个问题,请大家帮我分析个源码
- 救急~~~请问怎样在程序中调用别人写好的Action中的actionPerformed(ActionEvent e)中的代码?
- int与char运算的问题...
- 请教各位两个问题:URL和URLConnection的
- 实现取服务器上的时间
- g.drawString(....),怎样设置字体
- truncate有索引的表和没有索引的表速度一样吗?
- 解释一下下段代码的意思
- [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
换一种布局方式
import java.awt.event.*;class CardStart {
public static void main(String[] args) {
CardTest c = new CardTest("MyCardLayoutTest");
}
}class CardTest extends Frame {
Panel t1 = new Panel(); Panel t2 = new Panel(); Panel t3 = new Panel(); Panel t4 = new Panel(); Panel p1 = new Panel(); Panel p2 = new Panel(); Button b1 = new Button("1"); Button b2 = new Button("2"); Button b3 = new Button("3"); Button b4 = new Button("4"); CardLayout cl = new CardLayout(); Label l1 = new Label("The Number 1 CardPage"); Label l2 = new Label("The Number 2 CardPage"); Label l3 = new Label("The Number 3 CardPage"); Label l4 = new Label("The Number 4 CardPage"); public CardTest(String s) {
super(s);
MyWL mw = new MyWL(this);
myML mm = new myML(this); this.addWindowListener(mw);
b1.addActionListener(mm);
b2.addActionListener(mm);
b3.addActionListener(mm);
b4.addActionListener(mm); b1.setSize(30, 5);
this.setLayout(new BorderLayout());
this.setSize(500, 400);
p2.setSize(500, 200); t1.add(l1);
t2.add(l2);
t3.add(l3);
t4.add(l4); p1.setLayout(cl);
p1.add("a", t1);
p1.add("b", t2);
p1.add("c", t3);
p1.add("d", t4); p2.setLayout(new GridLayout(1, 4));
p2.add(b1);
p2.add(b2);
p2.add(b3);
p2.add(b4); p1.setBackground(Color.cyan);
p2.setBackground(Color.white);
this.add(p2, BorderLayout.SOUTH);
this.add(p1, BorderLayout.CENTER);
this.setResizable(false);
this.setVisible(true);
} public void T1() {
cl.show(p1, "a");
} public void T2() {
cl.show(p1, "b");
} public void T3() {
cl.show(p1, "c");
} public void T4() {
cl.show(p1, "d");
}
}class MyWL extends WindowAdapter {
CardTest t; public MyWL(CardTest ct) {
t = ct;
} public void windowClosing(WindowEvent we) {
t.dispose();
}
}class myML implements ActionListener {
CardTest t; public myML(CardTest ct) {
t = ct;
} public void actionPerformed(ActionEvent me) {
if (me.getSource() == t.b1) {
System.out.println("1");
t.T1();
} else if (me.getSource() == t.b2) {
System.out.println("2");
t.T2();
} else if (me.getSource() == t.b3) {
System.out.println("3");
t.T3();
} else if (me.getSource() == t.b4) {
System.out.println("4");
t.T4();
}
}
}