Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. package zadanie9;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.Color;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import javax.swing.BorderFactory;
  8. import javax.swing.ButtonGroup;
  9. import javax.swing.JButton;
  10. import javax.swing.JCheckBox;
  11. import javax.swing.JFrame;
  12. import javax.swing.JPanel;
  13. import javax.swing.JRadioButton;
  14. import javax.swing.border.Border;
  15. import javax.swing.border.TitledBorder;
  16. import javax.swing.JTextField;
  17.  
  18. public class Zadanie9 extends JFrame implements ActionListener {
  19. JPanel pane,pane1,pane2;
  20. TitledBorder title;
  21. JTextField text1, text2, text3;
  22. ButtonGroup grupa;
  23. JRadioButton rb1,rb2,rb3;
  24. JCheckBox check1, check2, check3;
  25.  
  26. public Zadanie9() {
  27. setSize(500, 500);
  28. setTitle("Moja formatka");
  29. setLayout(null);
  30.  
  31. pane = new JPanel();
  32. pane.setBounds(10, 10, 130, 130);
  33. Border loweredetched = null;
  34. add(pane);
  35.  
  36.  
  37.  
  38.  
  39. title = BorderFactory.createTitledBorder(loweredetched, "Panel 1");
  40. title.setTitleJustification(TitledBorder.LEFT);
  41. pane.setBorder(title);
  42.  
  43. pane1 = new JPanel();
  44. pane1.setBounds(150, 10, 130, 130);
  45.  
  46. add(pane1);
  47.  
  48. title = BorderFactory.createTitledBorder(loweredetched, "Panel 2");
  49. title.setTitleJustification(TitledBorder.CENTER);
  50. pane1.setBorder(title);
  51.  
  52. pane2 = new JPanel();
  53. pane2.setBounds(300, 10, 130, 130);
  54.  
  55. add(pane2);
  56.  
  57. title = BorderFactory.createTitledBorder(loweredetched, "Panel 3");
  58. title.setTitleJustification(TitledBorder.RIGHT);
  59. pane2.setBorder(title);
  60.  
  61. text1 = new JTextField("JTextField1");
  62. pane.add(text1, BorderLayout.CENTER);
  63.  
  64. JButton Button1 = new JButton("Button1");
  65. pane.add(Button1);
  66.  
  67. text2 = new JTextField("JTextField2");
  68. pane1.add(text2, BorderLayout.CENTER);
  69.  
  70. JButton Button2 = new JButton("Button1");
  71. pane1.add(Button2);
  72.  
  73. text3 = new JTextField("JTextField2");
  74. pane2.add(text3, BorderLayout.CENTER);
  75.  
  76. JButton Button3 = new JButton("Button1");
  77. pane2.add(Button3);
  78.  
  79.  
  80.  
  81. grupa = new ButtonGroup();
  82. rb1= new JRadioButton("Widocznosc",true);
  83. rb1.setBounds(10, 170, 100, 20);
  84. grupa.add(rb1);
  85. add(rb1);
  86. rb1.addActionListener(this);
  87.  
  88. rb2= new JRadioButton("Widocznosc",false);
  89. rb2.setBounds(150, 170, 100, 20);
  90. grupa.add(rb2);
  91. add(rb2);
  92. rb2.addActionListener(this);
  93.  
  94. rb3= new JRadioButton("Widocznosc",false);
  95. rb3.setBounds(300, 170, 100, 20);
  96. grupa.add(rb3);
  97. add(rb3);
  98. rb3.addActionListener(this);
  99.  
  100.  
  101. }
  102.  
  103. public static void main(String[] args) {
  104.  
  105. Zadanie9 okno = new Zadanie9();
  106. okno.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  107. okno.setVisible(true);
  108. }
  109.  
  110. @Override
  111. public void actionPerformed(ActionEvent e) {
  112. Object zrodlo = e.getSource();
  113.  
  114. if(zrodlo==rb1){
  115.  
  116. pane.setVisible(true);
  117.  
  118.  
  119. }
  120.  
  121. else if(zrodlo==rb2){
  122.  
  123. pane1.setVisible(true);
  124.  
  125. }
  126. else if(zrodlo==rb3){
  127.  
  128. pane2.setVisible(true);
  129.  
  130.  
  131.  
  132. }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement