tipo, eu tentei acha coisas sobre CardLayout na net… mas nada funciono, tentei na tora, e tb n consegui… sera q alguem podia coloca um exemplo do uso de CardLayout aki plz?
import java.awt.*;
import java.awt.event.*;
public class CardLayoutDemo extends Frame implements ActionListener{
private Panel cards;
private Button bPrim, bAnt, bProx, bUlt;
public CardLayoutDemo(){
super("CardLayoutDemo Demo");
setSize(300,200);
Panel p1 = new Panel();
p1.setBackground(SystemColor.control);
Panel p2 = new Panel();
p2.setBackground(SystemColor.control);
p2.setLayout(new GridLayout(4, 1, 5, 5));
p2.add(bPrim = new Button("Primeiro"));
bPrim.addActionListener(this);
p2.add(bAnt = new Button("Anterior"));
bAnt.addActionListener(this);
p2.add(bProx = new Button("Próximo"));
bProx.addActionListener(this);
p2.add(bUlt = new Button("Último"));
bUlt.addActionListener(this);
p1.add(p2);
add("East", p1);
cards = new Panel();
cards.setLayout(new CardLayout());
cards.add(new Label("Primeiro Painel"), "C1");
cards.add(new Picture("cupHJbutton.gif"), "C2");
cards.add(new TextArea(), "C3");
p2 = new Panel();
p2.setBackground(SystemColor.control);
p2.add(new Label("Quarto Painel"));
p2.add(new Picture("cupHJbutton.gif", 32, 32));
cards.add(p2, "C4");
p2 = new Panel();
p2.setBackground(Color.lightGray);
cards.add(p2, "C5");
add("Center", cards);
}
public void actionPerformed(ActionEvent e){
CardLayout c1 = ((CardLayout)cards.getLayout());
if( e.getSource() == bPrim )
c1.first(cards);
else
if( e.getSource() == bAnt )
c1.previous(cards);
else
if( e.getSource() == bProx )
c1.next(cards);
else
c1.last(cards);
}
public static void main(String args[]){
CardLayoutDemo f = new CardLayoutDemo();
f.addWindowListener(new CloseWindowAndExit());
f.show();
}
}
Abraços