package qq.test;
import java.awt.CardLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.AbstractAction; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JPanel;
public class CardLayoutTest extends JPanel {
private JPanel panel; /** * Create the panel */ public CardLayoutTest() { super(); setLayout(null);
panel = new JPanel(); panel.setLayout(new CardLayout()); panel.setBounds(35, 65, 237, 244); add(panel);
final JLabel label1 = new JLabel(); label1.setText("test1"); label1.setName("label"); panel.add(label1, label1.getName());
final JLabel label2 = new JLabel(); label2.setText("test2"); label2.setName("label_1"); panel.add(label2, label2.getName());
final JLabel test3Label = new JLabel(); test3Label.setText("test3"); test3Label.setName("label1"); panel.add(test3Label, test3Label.getName());
final JLabel test4Label = new JLabel(); test4Label.setText("test4"); test4Label.setName("label_11"); panel.add(test4Label, test4Label.getName());
final JLabel test5Label = new JLabel(); test5Label.setText(" test5"); test5Label.setName("label_2"); panel.add(test5Label, test5Label.getName());
final JLabel cardLayoutTestLabel = new JLabel(); cardLayoutTestLabel.setText("Card layout Test"); cardLayoutTestLabel.setBounds(38, 41, 103, 18); add(cardLayoutTestLabel);
final JButton button1 = new JButton(); button1.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { CardLayout card= (CardLayout) panel.getLayout(); card.previous(panel); } }); button1.setText("Next"); button1.setBounds(338, 91, 106, 28); add(button1);
final JButton button2 = new JButton(); button2.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { CardLayout card= (CardLayout) panel.getLayout(); card.next(panel); } }); button2.setText("last"); button2.setBounds(338, 165, 106, 28); add(button2);
final JButton endButton = new JButton(); endButton.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { CardLayout card= (CardLayout) panel.getLayout(); card.last(panel); } }); endButton.setText("end"); endButton.setBounds(338, 236, 106, 28); add(endButton);
final JButton firstButton = new JButton(); firstButton.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { CardLayout card= (CardLayout) panel.getLayout(); card.first(panel); } }); firstButton.setText("first"); firstButton.setBounds(338, 36, 106, 28); add(firstButton); //
} public JPanel getPanel() { return panel; }
}
|