Advertisement
apl-mhd

what i want version two

Dec 29th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. package com.company;
  2.  
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7.  
  8. public class Main extends JFrame implements ActionListener{
  9.  
  10. @Override
  11. public void actionPerformed(ActionEvent e) {
  12.  
  13. getContentPane().removeAll();
  14. getContentPane().add(anotherPanel.foo());
  15.  
  16.  
  17. getContentPane().validate();
  18. getContentPane().repaint();
  19. }
  20.  
  21. AnotherPanel anotherPanel = new AnotherPanel();
  22.  
  23. public Main() {
  24.  
  25. super("hello");
  26.  
  27. setLayout(new FlowLayout());
  28. JButton button1 = new JButton("Main panel");
  29.  
  30. getContentPane().add(button1);
  31.  
  32. button1.addActionListener(this);
  33.  
  34. setDefaultCloseOperation(EXIT_ON_CLOSE);
  35. setSize(500,500);
  36. setVisible(true);
  37. }
  38.  
  39. public static void main(String[] args) {
  40.  
  41.  
  42. new Main();
  43.  
  44.  
  45.  
  46. }
  47. }
  48.  
  49.  
  50. package com.company;
  51.  
  52. import javax.swing.*;
  53. import java.awt.*;
  54.  
  55. public class AnotherPanel extends JPanel {
  56.  
  57.  
  58. AnotherPanel(){
  59.  
  60.  
  61.  
  62. }
  63.  
  64. JPanel foo(){
  65.  
  66. JPanel jPanel = new JPanel();
  67.  
  68. jPanel.setLayout(new FlowLayout());
  69.  
  70. JButton button = new JButton("Hello I am Another panel");
  71.  
  72. jPanel.add(button);
  73. return jPanel;
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement