gestionnaires.java 4.53 KB
package tp1;

import javax.swing.*;
import java.awt.*;

public class gestionnaires {
    public static final int width = 500;
    public static final int height = 400;

    public static void main(String[] args) {

        //question 16
        try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
        } catch (UnsupportedLookAndFeelException | ClassNotFoundException | InstantiationException | IllegalAccessException e) {
            e.printStackTrace();
        }
        JFrame win = new JFrame();

        win.setSize( width, height);
        win.setLocationRelativeTo(null);

        /*
        //questioon 6
        JButton toto1 = new JButton("button1");
        JButton toto2 = new JButton("button2");
        JButton toto3 = new JButton("button3");
        JButton toto4 = new JButton("button4");
        JButton toto5 = new JButton("button5");

        win.add(toto1, BorderLayout.EAST);
        win.add(toto2, BorderLayout.WEST);
        win.add(toto3, BorderLayout.NORTH);
        win.add(toto4, BorderLayout.SOUTH);
        win.add(toto5, BorderLayout.CENTER);
        */

        /*
        //question 7
        FlowLayout layout = new FlowLayout();
        win.setLayout(layout);

        JButton[] buttons = new JButton[20];

        for (int i = 0; i < buttons.length; i++) {
           buttons[i] = new JButton("button "+ i);
           win.add(buttons[i]);
        }
        */

        /*
        //question 8
        GridLayout layout = new GridLayout(4,4);
        win.setLayout(layout);
        JButton[] buttons = new JButton[16];
        for (int i = 0; i < buttons.length; i++) {
           buttons[i] = new JButton("button "+ i);
           win.add(buttons[i]);
        }
        */

        /*
        //question 9
        BoxLayout layout = new BoxLayout(win.getContentPane(), BoxLayout.PAGE_AXIS);
        win.setLayout(layout);
        JButton[] buttons = new JButton[3];
        for (int i = 0; i < buttons.length; i++) {
           buttons[i] = new JButton("button "+ i);
           buttons[i].setPreferredSize(new Dimension(width-1, 50));
        }

        win.add(buttons[0]);
        win.add(Box.createRigidArea(new Dimension(0, 20)));
        win.add(buttons[1]);
        win.add(Box.createVerticalGlue());
        win.add(buttons[2]);
         */

        /*
        //question 10
        GridBagLayout layout = new GridBagLayout();
        win.setLayout(layout);
        GridBagConstraints[] c = new GridBagConstraints[10];
        for (int i = 0; i < c.length; i++) {
           c[i] = new GridBagConstraints();
        }

        c[0].gridx = 0;
        c[0].gridy = 0;

        c[1].gridx = 1;
        c[1].gridy = 0;

        c[2].gridx = 2;
        c[2].gridy = 0;

        c[3].gridx = 3;
        c[3].gridy = 0;

        c[4].gridx = 0;
        c[4].gridy = 1;
        c[4].gridwidth = 4;

        c[5].gridx = 0;
        c[5].gridy = 2;
        c[5].gridwidth = 3;

        c[6].gridx = 3;
        c[6].gridy = 2;

        c[7].gridx = 0;
        c[7].gridy = 3;
        c[7].gridheight = 2;

        c[8].gridx = 1;
        c[8].gridy = 3;
        c[8].gridwidth = 3;

        c[9].gridx = 1;
        c[9].gridy = 4;
        c[9].gridwidth = 3;

        JButton[] buttons = new JButton[10];
        for (int i = 0; i < buttons.length; i++) {
           buttons[i] = new JButton("button "+ i);
           c[i].fill = GridBagConstraints.BOTH;
           win.add(buttons[i], c[i]);
        }
        */

        /*
        //question 12
        win.setLayout(null);
        int nbouton = 10;
        int xstep = width/(nbouton +1);
        int ystep = height/(nbouton +1);
        JButton[] buttons = new JButton[nbouton];

        for (int i = 0; i < buttons.length; i++) {
           buttons[i] = new JButton("button "+ i);
           win.add(buttons[i]);
           buttons[i].setBounds( i*xstep, i*ystep,100,30);
           buttons[i].repaint();
        }
        */

        JButton toto1 = new JButton("button1");
        JButton toto2 = new JButton("button2");
        JButton toto4 = new JButton("button4");
        JButton toto5 = new JButton("button5");

        JPanel toto3 = new JPanel();
        toto3.add(new Button("bouton"));
        toto3.add(new Button("bouton"));
        toto3.add(new Button("bouton"));

        win.add(toto1, BorderLayout.EAST);
        win.add(toto2, BorderLayout.WEST);
        win.add(toto3, BorderLayout.NORTH);
        win.add(toto4, BorderLayout.SOUTH);
        win.add(toto5, BorderLayout.CENTER);

        win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        win.setVisible(true);
    }
}