Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.32 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package swingapplication;
  7.  
  8. /**
  9. *
  10. * @author karmelek
  11. */
  12. import javax.swing.*;
  13. import java.awt.*;
  14. import java.awt.event.*;
  15. public class MoreWindows implements ActionListener, WindowListener {
  16.  
  17. JFrame mainOkno = new JFrame("MAIN OKNO");
  18. JFrame okno1 = new JFrame("Okno 1");
  19. JFrame okno2 = new JFrame("Okno 2");
  20.  
  21. /** Creates a new instance of MoreWindows */
  22. public MoreWindows() {
  23. GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
  24. Rectangle rect = ge.getMaximumWindowBounds();
  25.  
  26. mainOkno.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  27. okno1.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
  28. okno2.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
  29.  
  30. JComponent jcomp = (JComponent)mainOkno.getContentPane();
  31. jcomp.setLayout(new GridLayout(1, 0));
  32.  
  33. JButton jButtonPokazOkno1 = new JButton("FRAME 1 SHOW");
  34. jButtonPokazOkno1.addActionListener(this);
  35. jcomp.add(jButtonPokazOkno1);
  36. JButton jButtonPokazOkno2 = new JButton("FRAME 2 SHOW");
  37. jButtonPokazOkno2.addActionListener(this);
  38. jcomp.add(jButtonPokazOkno2);
  39.  
  40.  
  41. JComponent jc1 = (JComponent)okno1.getContentPane();
  42. jc1.setLayout(new GridLayout(2, 2, 0, 0));
  43. ButtonGroup bg = new ButtonGroup();
  44. JRadioButton jrb1= new JRadioButton("UNO", true);
  45. JRadioButton jrb2= new JRadioButton("DUE", true);
  46. JRadioButton jrb3= new JRadioButton("TRE", true);
  47. jrb1.setPreferredSize(new Dimension(200, 30));
  48. jrb2.setPreferredSize(new Dimension(200, 30));
  49. jrb3.setPreferredSize(new Dimension(200, 30));
  50. bg.add(jrb1);
  51. bg.add(jrb2);
  52. //bg.add(jrb3);
  53. JPanel jpButtons = new JPanel(new GridLayout(3, 1, 0, 0));
  54. jpButtons.add(jrb1);
  55. jpButtons.add(jrb2);
  56. jpButtons.add(jrb3);
  57. jc1.add(jpButtons);
  58. JTextField jtf = new JTextField("TEXT FIELD", 10);
  59. JPanel jpText = new JPanel(new FlowLayout(FlowLayout.RIGHT));
  60. jpText.add(jtf);
  61. jc1.add(jpText);
  62.  
  63. JComponent jc2 = (JComponent)okno2.getContentPane();
  64. jc2.setLayout(new GridLayout(0,1));
  65. JTextArea jta = new JTextArea("TXT AREA", 10, 15);
  66. JCheckBox jcb1 = new JCheckBox("ONE", true);
  67. JCheckBox jcb2 = new JCheckBox("TWO", true);
  68. JCheckBox jcb3 = new JCheckBox("THREE", true);
  69. jc2.add(jta);
  70. jc2.add(jcb1);
  71. jc2.add(jcb2);
  72. jc2.add(jcb3);
  73.  
  74.  
  75.  
  76.  
  77.  
  78. okno1.pack();
  79. okno2.setSize(300, 300);
  80. okno2.setLocation( (int)okno1.getBounds().getWidth(), 0 );
  81. mainOkno.pack();
  82.  
  83. Rectangle oknoRect = mainOkno.getBounds();
  84. mainOkno.setLocation((int)(rect.getWidth()-oknoRect.getWidth())/2,
  85. (int)(rect.getHeight()-oknoRect.getHeight())/2);
  86. mainOkno.setVisible(true);
  87. okno1.addWindowListener(this);
  88. }
  89.  
  90. public void actionPerformed(ActionEvent ae) {
  91. JButton jb = (JButton)ae.getSource();
  92. if (ae.getActionCommand().equals("FRAME 1 SHOW")) {
  93. okno1.setVisible(true);
  94. jb.setText("FRAME 1 HIDE");
  95. }
  96. else
  97. if (ae.getActionCommand().equals("FRAME 1 HIDE")) {
  98. okno1.setVisible(false);
  99. jb.setText("FRAME 1 SHOW");
  100. }
  101. else
  102. if (ae.getActionCommand().equals("FRAME 2 SHOW")) {
  103. okno2.setVisible(true);
  104. jb.setText("FRAME 2 HIDE");
  105. }
  106. else {
  107. okno2.setVisible(false);
  108. jb.setText("FRAME 2 SHOW");
  109. }
  110. }
  111.  
  112. @Override
  113. public void windowOpened(WindowEvent we) {
  114. //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  115. }
  116.  
  117. @Override
  118. public void windowClosing(WindowEvent we) {
  119. System.out.println("w");
  120. JButton jb = (JButton)we.getSource();
  121. jb.setText("FRAME 1 SHOW");
  122. we.getWindow().dispose();
  123. }
  124.  
  125. @Override
  126. public void windowClosed(WindowEvent we) {
  127. //System.out.println("w");
  128. }
  129.  
  130. @Override
  131. public void windowIconified(WindowEvent we) {
  132. //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  133. }
  134.  
  135. @Override
  136. public void windowDeiconified(WindowEvent we) {
  137. //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  138. }
  139.  
  140. @Override
  141. public void windowActivated(WindowEvent we) {
  142. //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  143. }
  144.  
  145. @Override
  146. public void windowDeactivated(WindowEvent we) {
  147. //System.out.println("w");
  148. }
  149.  
  150.  
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement