Advertisement
Guest User

Problem

a guest
Jan 25th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. package de.frame;
  2.  
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import javax.swing.*;
  6.  
  7. public class Gui extends JFrame implements ActionListener {
  8.  
  9. private JButton seite1;
  10. private JButton seite2;
  11.  
  12. JPanel panelCont = new JPanel();
  13. JPanel panelSeite1 = new JPanel();
  14. JPanel panelSeite2 = new JPanel();
  15.  
  16. CardLayout cl = new CardLayout();
  17.  
  18. public static void main(String[] args) {
  19. new Gui("Frame");
  20. }
  21.  
  22. public Gui(String title) {
  23. super(title);
  24.  
  25. button();
  26.  
  27. this.setSize(500, 500);
  28. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  29. this.setVisible(true);
  30. this.add(panelCont);
  31. }
  32.  
  33. public void button() {
  34. panelCont.setLayout(cl);
  35. panelCont.add(panelSeite1, "1");
  36. panelCont.add(panelSeite2, "2");
  37. cl.show(panelCont, "1");
  38.  
  39.  
  40. seite1 = new JButton("Seite 2");
  41. seite1.setBounds(50, 50, 100, 25);
  42. seite1.addActionListener(this);
  43. panelSeite1.add(seite1);
  44.  
  45. seite2 = new JButton("Seite 1");
  46. seite2.setBounds(100, 100, 100, 25);
  47. seite2.addActionListener(this);
  48. panelSeite2.add(seite2);
  49.  
  50. panelSeite2.setBackground(Color.RED);
  51. }
  52.  
  53. public void actionPerformed(ActionEvent e) {
  54. if (e.getSource() == seite1) {
  55. cl.show(panelCont, "2");
  56. } else if (e.getSource() == seite2) {
  57. cl.show(panelCont, "1");
  58. }
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement