Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package wan.dev.sample.cardlayout;
- import java.awt.CardLayout;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.JButton;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import javax.swing.JLabel;
- public class HowToUseCardLayout {
- private JFrame frame;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- HowToUseCardLayout window = new HowToUseCardLayout();
- window.frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the application.
- */
- public HowToUseCardLayout() {
- initialize();
- }
- /**
- * Initialize the contents of the frame.
- */
- private void initialize() {
- frame = new JFrame();
- frame.setBounds(100, 100, 688, 358);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.getContentPane().setLayout(null);
- JPanel mainPanel = new JPanel();
- mainPanel.setBounds(0, 0, 672, 260);
- frame.getContentPane().add(mainPanel);
- mainPanel.setLayout(new CardLayout(0, 0));
- JPanel PrePanel = new JPanel();
- mainPanel.add(PrePanel, "name_246268073832057");
- PrePanel.setLayout(null);
- JLabel lblPanel_1 = new JLabel("Pre Panel");
- lblPanel_1.setBounds(280, 115, 57, 20);
- PrePanel.add(lblPanel_1);
- JPanel panelOne = new JPanel();
- mainPanel.add(panelOne, "name_246268067657434");
- panelOne.setLayout(null);
- JLabel lblPanel = new JLabel("panel 1");
- lblPanel.setBounds(279, 118, 46, 14);
- panelOne.add(lblPanel);
- JButton btnPan1 = new JButton("Call PanelOne");
- btnPan1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- CardLayout card = (CardLayout) mainPanel.getLayout();
- card.show(mainPanel, "PanelOne");
- }
- });
- btnPan1.setBounds(262, 286, 144, 23);
- frame.getContentPane().add(btnPan1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement