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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
| public class Main extends JFrame {
private JTable table;
private String[] title= {"Date", "Heure"};
private Object[][] data= {};
private JPanel panTable;
private JLabel lblCandidat= new JLabel("Candidat :"), lblCode= new JLabel("Code :"), lblAvance= new JLabel("Avance :"),
lblPrixHeure= new JLabel("Prix d'heures :"), lblReste= new JLabel("Reste :");
private JTextField tfCandidat= new JTextField("Patrick"), tfCode= new JTextField("100"), tfAvance= new JTextField("100"),
tfPrixHeure= new JTextField("10"), tfReste= new JTextField("250");
private JPanel lftPan;
public Main() {
this.setSize(500, 300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("Titre de la fenetre");
this.setResizable(false);
this.setLocationRelativeTo(null);
//tableau
panTable= new JPanel();
panTable.setPreferredSize(new Dimension(250, 290));
panTable.setBackground(Color.white);
DefaultTableModel model= new DefaultTableModel(data, title);
table= new JTable(model);
JScrollPane scroll= new JScrollPane(table);
scroll.setPreferredSize(new Dimension(250, 290));
panTable.add(scroll);
//infos
lftPan= new JPanel();
lftPan.setPreferredSize(new Dimension(250, 290));
lftPan.setBackground(Color.white);
lftPan.setLayout(new GridBagLayout());
lblCandidat.setPreferredSize(new Dimension(90, 25));
lblCode.setPreferredSize(new Dimension(90, 25));
lblAvance.setPreferredSize(new Dimension(90, 25));
lblPrixHeure.setPreferredSize(new Dimension(90, 25));
lblReste.setPreferredSize(new Dimension(90, 25));
tfCandidat.setPreferredSize(new Dimension(120, 25));
tfCode.setPreferredSize(new Dimension(120, 25));
tfAvance.setPreferredSize(new Dimension(120, 25));
tfPrixHeure.setPreferredSize(new Dimension(120, 25));
tfReste.setPreferredSize(new Dimension(120, 25));
GridBagConstraints gbc= new GridBagConstraints();
gbc.insets= new Insets(0, 0, 15, 0);
gbc.gridx= 0;
gbc.gridy = 0;
gbc.gridheight= 1;
gbc.gridwidth= 1;
lftPan.add(lblCandidat, gbc);
gbc.gridx= 1;
gbc.gridy = 0;
gbc.gridwidth= GridBagConstraints.REMAINDER;
lftPan.add(tfCandidat, gbc);
gbc.gridx= 0;
gbc.gridy = 1;
gbc.gridwidth= 1;
lftPan.add(lblCode, gbc);
gbc.gridx= 1;
gbc.gridy = 1;
gbc.gridwidth= GridBagConstraints.REMAINDER;
lftPan.add(tfCode, gbc);
gbc.gridx= 0;
gbc.gridy = 2;
gbc.gridwidth= 1;
lftPan.add(lblAvance, gbc);
gbc.gridx= 1;
gbc.gridy = 2;
gbc.gridwidth= GridBagConstraints.REMAINDER;
lftPan.add(tfAvance, gbc);
gbc.gridx= 0;
gbc.gridy = 3;
gbc.gridwidth= 1;
lftPan.add(lblPrixHeure, gbc);
gbc.gridx= 1;
gbc.gridy = 3;
gbc.gridwidth= GridBagConstraints.REMAINDER;
lftPan.add(tfPrixHeure, gbc);
gbc.gridx= 0;
gbc.gridy = 4;
gbc.gridwidth= 1;
lftPan.add(lblReste, gbc);
gbc.gridx= 1;
gbc.gridy = 4;
gbc.gridwidth= GridBagConstraints.REMAINDER;
lftPan.add(tfReste, gbc);
this.getContentPane().add(panTable, BorderLayout.WEST);
this.getContentPane().add(lftPan, BorderLayout.EAST);
this.setVisible(true);
}
public static void main(String[] args) {
Main mmain= new Main();
}
} |
Partager