B
BEHROUZ
Hi Every one,
I am new at java swing and I am trying to add a Jpanel to my frame. I
have three simple class as below
1-Class MyPanel
2-Class MyFrame
3-Class Main
I did my best to add the panel to my frame but it did not work! Could
you please let me know what I am doing wrong!?
//=====================
1.
2. package mypaneltest;
3. import javax.swing.JButton;
4. import javax.swing.JPanel;
5.
6. public class MyPanel extends JPanel {
7. public MyPanel(){
8. JPanel pan = new JPanel();
9. JButton okButton = new JButton("OK");
10. pan.add(okButton);
11. }
12. }
13. //=====================
14. package mypaneltest;
15. import javax.swing.JFrame;
16.
17. public class MyFrame extends JFrame {
18. public MyFrame(){
19. super("Test");
20. setSize(300,200);
21. setLocationRelativeTo(null);
22. MyPanel pane = new MyPanel();
23. add(pane);
24. }
25. }
26. //======================
27. package mypaneltest;
28.
29. public class Main {
30. public static void main(String[] args) {
31. new MyFrame().setVisible(true);
32. }
33. }
Best Regards
I am new at java swing and I am trying to add a Jpanel to my frame. I
have three simple class as below
1-Class MyPanel
2-Class MyFrame
3-Class Main
I did my best to add the panel to my frame but it did not work! Could
you please let me know what I am doing wrong!?
//=====================
1.
2. package mypaneltest;
3. import javax.swing.JButton;
4. import javax.swing.JPanel;
5.
6. public class MyPanel extends JPanel {
7. public MyPanel(){
8. JPanel pan = new JPanel();
9. JButton okButton = new JButton("OK");
10. pan.add(okButton);
11. }
12. }
13. //=====================
14. package mypaneltest;
15. import javax.swing.JFrame;
16.
17. public class MyFrame extends JFrame {
18. public MyFrame(){
19. super("Test");
20. setSize(300,200);
21. setLocationRelativeTo(null);
22. MyPanel pane = new MyPanel();
23. add(pane);
24. }
25. }
26. //======================
27. package mypaneltest;
28.
29. public class Main {
30. public static void main(String[] args) {
31. new MyFrame().setVisible(true);
32. }
33. }
Best Regards