日期:2014-05-20 浏览次数:20660 次
final JPanel left = new JPanel(new GridLayout(3,2,5,5)); left.add(new JButton("1")); left.add(new JButton("2")); left.add(new JButton("3")); left.add(new JButton("4")); left.add(new JButton("5")); left.add(new JButton("6")); final JPanel right = new JPanel(new GridLayout(3,2,5,5)); right.add(new JButton("7")); right.add(new JButton("8")); right.add(new JButton("9")); right.add(new JButton("10")); right.add(new JButton("11")); right.add(new JButton("12")); final CardLayout layout = new CardLayout(); final JPanel pages = new JPanel(layout); pages.add(left, "left"); pages.add(right, "right"); final JButton showLeft = new JButton("Left"); showLeft.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent e){ layout.show(pages,"left"); } }); final JButton showRight = new JButton("Right"); showRight.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent e){ layout.show(pages,"right"); } }); final JPanel buttonPanel = new JPanel(); buttonPanel.add(showLeft); buttonPanel.add(showRight); final JPanel main = new JPanel(new BorderLayout()); main.add(pages,BorderLayout.CENTER); main.add(buttonPanel,BorderLayout.SOUTH);