Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package swingapplication;
- /**
- *
- * @author karmelek
- */
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- public class MoreWindows implements ActionListener, WindowListener {
- JFrame mainOkno = new JFrame("MAIN OKNO");
- JFrame okno1 = new JFrame("Okno 1");
- JFrame okno2 = new JFrame("Okno 2");
- /** Creates a new instance of MoreWindows */
- public MoreWindows() {
- GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
- Rectangle rect = ge.getMaximumWindowBounds();
- mainOkno.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
- okno1.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
- okno2.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
- JComponent jcomp = (JComponent)mainOkno.getContentPane();
- jcomp.setLayout(new GridLayout(1, 0));
- JButton jButtonPokazOkno1 = new JButton("FRAME 1 SHOW");
- jButtonPokazOkno1.addActionListener(this);
- jcomp.add(jButtonPokazOkno1);
- JButton jButtonPokazOkno2 = new JButton("FRAME 2 SHOW");
- jButtonPokazOkno2.addActionListener(this);
- jcomp.add(jButtonPokazOkno2);
- JComponent jc1 = (JComponent)okno1.getContentPane();
- jc1.setLayout(new GridLayout(2, 2, 0, 0));
- ButtonGroup bg = new ButtonGroup();
- JRadioButton jrb1= new JRadioButton("UNO", true);
- JRadioButton jrb2= new JRadioButton("DUE", true);
- JRadioButton jrb3= new JRadioButton("TRE", true);
- jrb1.setPreferredSize(new Dimension(200, 30));
- jrb2.setPreferredSize(new Dimension(200, 30));
- jrb3.setPreferredSize(new Dimension(200, 30));
- bg.add(jrb1);
- bg.add(jrb2);
- //bg.add(jrb3);
- JPanel jpButtons = new JPanel(new GridLayout(3, 1, 0, 0));
- jpButtons.add(jrb1);
- jpButtons.add(jrb2);
- jpButtons.add(jrb3);
- jc1.add(jpButtons);
- JTextField jtf = new JTextField("TEXT FIELD", 10);
- JPanel jpText = new JPanel(new FlowLayout(FlowLayout.RIGHT));
- jpText.add(jtf);
- jc1.add(jpText);
- JComponent jc2 = (JComponent)okno2.getContentPane();
- jc2.setLayout(new GridLayout(0,1));
- JTextArea jta = new JTextArea("TXT AREA", 10, 15);
- JCheckBox jcb1 = new JCheckBox("ONE", true);
- JCheckBox jcb2 = new JCheckBox("TWO", true);
- JCheckBox jcb3 = new JCheckBox("THREE", true);
- jc2.add(jta);
- jc2.add(jcb1);
- jc2.add(jcb2);
- jc2.add(jcb3);
- okno1.pack();
- okno2.setSize(300, 300);
- okno2.setLocation( (int)okno1.getBounds().getWidth(), 0 );
- mainOkno.pack();
- Rectangle oknoRect = mainOkno.getBounds();
- mainOkno.setLocation((int)(rect.getWidth()-oknoRect.getWidth())/2,
- (int)(rect.getHeight()-oknoRect.getHeight())/2);
- mainOkno.setVisible(true);
- okno1.addWindowListener(this);
- }
- public void actionPerformed(ActionEvent ae) {
- JButton jb = (JButton)ae.getSource();
- if (ae.getActionCommand().equals("FRAME 1 SHOW")) {
- okno1.setVisible(true);
- jb.setText("FRAME 1 HIDE");
- }
- else
- if (ae.getActionCommand().equals("FRAME 1 HIDE")) {
- okno1.setVisible(false);
- jb.setText("FRAME 1 SHOW");
- }
- else
- if (ae.getActionCommand().equals("FRAME 2 SHOW")) {
- okno2.setVisible(true);
- jb.setText("FRAME 2 HIDE");
- }
- else {
- okno2.setVisible(false);
- jb.setText("FRAME 2 SHOW");
- }
- }
- @Override
- public void windowOpened(WindowEvent we) {
- //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- @Override
- public void windowClosing(WindowEvent we) {
- System.out.println("w");
- JButton jb = (JButton)we.getSource();
- jb.setText("FRAME 1 SHOW");
- we.getWindow().dispose();
- }
- @Override
- public void windowClosed(WindowEvent we) {
- //System.out.println("w");
- }
- @Override
- public void windowIconified(WindowEvent we) {
- //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- @Override
- public void windowDeiconified(WindowEvent we) {
- //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- @Override
- public void windowActivated(WindowEvent we) {
- //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- @Override
- public void windowDeactivated(WindowEvent we) {
- //System.out.println("w");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement