77 lines
1.8 KiB
Java
77 lines
1.8 KiB
Java
import java.awt.*;
|
|
import javax.swing.*;
|
|
import java.util.Arrays;
|
|
|
|
public class Fenetre extends JFrame {
|
|
|
|
private String[] modules;
|
|
private String[] champs;
|
|
private int[] idChamps;
|
|
|
|
public Fenetre(String[] modules, String[] champs, int[] idChamps) {
|
|
this.modules = modules;
|
|
this.champs = champs;
|
|
this.idChamps = idChamps;
|
|
|
|
int[] nbChampsParModule = new int[this.modules.length];
|
|
|
|
Arrays.fill(nbChampsParModule, 0);
|
|
|
|
int indexIdChamps = 0;
|
|
|
|
for (int i = 0; i != this.modules.length; i++) {
|
|
while ((indexIdChamps < this.idChamps.length) && this.idChamps[indexIdChamps] == (i+1)) {
|
|
nbChampsParModule[i]++;
|
|
indexIdChamps++;
|
|
}
|
|
System.out.println(nbChampsParModule[i]);
|
|
}
|
|
|
|
System.out.println(Arrays.toString(nbChampsParModule));
|
|
|
|
this.setSize(200, 500);
|
|
this.setLocation(100, 100);
|
|
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
|
|
this.setLayout(new GridBagLayout());
|
|
|
|
|
|
GridBagConstraints gbc = new GridBagConstraints();
|
|
|
|
|
|
gbc.gridx = 0;
|
|
gbc.gridy = 0;
|
|
gbc.fill = GridBagConstraints.BOTH; // Make the component fill its display area entirely
|
|
gbc.gridwidth = 1;
|
|
gbc.weightx = 1.0;
|
|
gbc.weighty = 1.0;
|
|
|
|
|
|
for (int i = 0; i != this.modules.length; i++) {
|
|
gbc.gridheight = nbChampsParModule[i];
|
|
JLabel texte = new JLabel(this.modules[i]);
|
|
texte.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
|
texte.setHorizontalAlignment(JLabel.CENTER);
|
|
texte.setVerticalAlignment(JLabel.CENTER);
|
|
this.add(texte, gbc);
|
|
gbc.gridy += nbChampsParModule[i];
|
|
}
|
|
|
|
gbc.gridx = 1;
|
|
gbc.gridheight = 1;
|
|
|
|
|
|
for (int i = 0; i != this.champs.length; i++) {
|
|
gbc.gridy = i;
|
|
JLabel texte = new JLabel(this.champs[i]);
|
|
texte.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
|
texte.setHorizontalAlignment(JLabel.CENTER);
|
|
texte.setVerticalAlignment(JLabel.CENTER);
|
|
this.add(texte, gbc);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} |