1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
   |  
import java.awt.*;
import javax.swing.*;
 
public class Test {
 
	private int valNode = 1;
	JFrame fen = new JFrame();
	JPanel advanced = new JPanel();
 
    public Test () 
    {
        initFenetre();
        initEntete();
        initMain();
        mainBoutons();
    }
 
    public void initFenetre()
    {        
		fen.setTitle("Launcher");
		fen.setSize(600, 400);
		fen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		fen.setResizable(false);
		fen.setLocationRelativeTo(null);
		fen.setVisible(true);
		fen.setLayout(new FlowLayout(0, 0, 0));
    }
    public void initEntete()
    {
    	JPanel entete = new JPanel();
    	JLabel[] texteEntete = new JLabel[2];
    	JButton boutonHelp = new JButton();
		entete.setLayout(new GridBagLayout());
		GridBagConstraints gbc = new GridBagConstraints();
		texteEntete[0] = new JLabel("      Node id : " + valNode);
		texteEntete[1] = new JLabel("Impossible d'afficher les coordonnées GPS");
 
		gbc.gridx = 0;
		gbc.gridy = 0;
		gbc.insets = new Insets(10, 0, 10, 135); //Insets gère l'espacement(top, left, bot,right)
		entete.add(texteEntete[0], gbc);
 
		gbc.gridx = 1;
		gbc.gridy = 0;
		gbc.insets = new Insets(10, 0, 10, 105);
		entete.add(texteEntete[1], gbc);
		gbc.gridx = 2;
		gbc.gridy = 0;
		gbc.insets = new Insets(8, -10, 8, 20); // -10 pour rapprocher de l'élément à gauche
 
		entete.add(boutonHelp, gbc);
		boutonHelp.setIcon(new ImageIcon(getClass().getResource("Help.png")));
		boutonHelp.setPreferredSize(new Dimension(32, 32));
 
		entete.setBackground(new Color(184, 229, 255));
		fen.add(entete);
		fen.getContentPane().setBackground(new Color(224, 224, 224));
    }
 
    public void initMain()
    {
    	JPanel main = new JPanel();
    	JLabel mainTexte = new JLabel("MAIN APPLICATIONS");
    	main.setLayout(new GridBagLayout());
    	GridBagConstraints gbc = new GridBagConstraints();
 
		gbc.gridx = 0;
		gbc.gridy = 0;
		gbc.insets = new Insets(10, 240, 10, 240);
    	main.add(mainTexte, gbc);
 
    	fen.add(main);
    }
 
    public void mainBoutons()
    {
    	JPanel mainBoutons = new JPanel();
    	int nbBoutons = 50;
    	JButton boutons[] = new JButton[nbBoutons];
    	mainBoutons.setLayout(new FlowLayout(0,50,10));
    	for(int i = 0; i < nbBoutons ; i++)
    	{
    		boutons[i] = new JButton("" + i);
    		boutons[i].setPreferredSize(new Dimension(64, 64));
    		mainBoutons.add(boutons[i]);
    	}
    	fen.add(mainBoutons);
    }
 
    public static void main(String[] args) 
    {
        new Test();
    }
} | 
Partager