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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class Acceuil extends JFrame {
private JButton bouton;
private JButton bouton2;
private JLabel label;
private JTextField loginField;
private JTextField passwordField;
public static void main(String[] args) {
Acceuil a = new Acceuil();
a.pack();
a.setVisible(true);
}
public Acceuil() {
super();
build();// On initialise notre fenêtre
}
private void build() {
setTitle("Client msn CoRed"); // On donne un titre à l'application
setSize(850, 700); // On donne une taille à notre fenêtre
setLocationRelativeTo(null); // On centre la fenêtre sur l'écran
setResizable(false); // On interdit la redimensionnement de la fenêtre
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // On dit à
// l'application de se
// fermer lors du clic
// sur la croix
this.setContentPane(buildContentPane());
}
// ...
private JPanel buildContentPane() {
// Menu
// FIN MENU
JPanel panelPrincipal = new JPanel();
panelPrincipal.setLayout(new GridBagLayout());
Logo logo = new Logo();
GridBagConstraints cLogo = new GridBagConstraints();
cLogo.gridheight = 1;
cLogo.gridwidth = 1;
cLogo.gridx = 0;
cLogo.gridy = 0;
cLogo.weightx = 1;
cLogo.weighty = 1;
cLogo.insets = new Insets(10, 10, 10, 10);
cLogo.fill = GridBagConstraints.BOTH;
panelPrincipal.add(logo, cLogo);
JLabel login = new JLabel("Login");
GridBagConstraints cLogin = new GridBagConstraints();
cLogin.anchor = GridBagConstraints.LINE_END;
cLogin.gridheight = 1;
cLogin.gridwidth = 1;
cLogin.gridx = 0;
cLogin.gridy = 1;
cLogin.insets = new Insets(10, 10, 10, 10);
panelPrincipal.add(login, cLogin);
JLabel password = new JLabel("Password");
GridBagConstraints cPassword = new GridBagConstraints();
cPassword.anchor = GridBagConstraints.LINE_END;
cPassword.gridx = 0;
cPassword.gridy = 2;
panelPrincipal.add(password, cPassword);
loginField = new JTextField("Taper ici votre login");
GridBagConstraints cLoginField = new GridBagConstraints();
cLoginField.anchor = GridBagConstraints.LINE_START;
cLoginField.fill = GridBagConstraints.HORIZONTAL;
cLoginField.gridheight = 1;
cLoginField.gridwidth = GridBagConstraints.REMAINDER;
cLoginField.gridx = 1;
cLoginField.gridy = 1;
cLoginField.insets = new Insets(10, 10, 10, 10);
panelPrincipal.add(loginField, cLoginField);
passwordField = new JTextField("Taper ici votre mot de passe");
GridBagConstraints cPasswordField = new GridBagConstraints();
cPasswordField.insets = new Insets(10, 10, 10, 10);
cPasswordField.fill = GridBagConstraints.HORIZONTAL;
cPasswordField.gridwidth = GridBagConstraints.REMAINDER;
cPasswordField.anchor = GridBagConstraints.LINE_START;
cPasswordField.gridx = 1;
cPasswordField.gridy = 2;
panelPrincipal.add(passwordField, cPasswordField);
JLabel nouveauCompte = new JLabel("Nouveau Compte");
GridBagConstraints cNouveauCompte = new GridBagConstraints();
cNouveauCompte.insets = new Insets(10, 10, 10, 10);
cNouveauCompte.gridx = 2;
cNouveauCompte.gridy = 3;
panelPrincipal.add(nouveauCompte, cNouveauCompte);
JLabel seConnecter = new JLabel("Se Connecter");
GridBagConstraints cSeConnecter = new GridBagConstraints();
cSeConnecter.insets = new Insets(10, 10, 10, 10);
cSeConnecter.gridx = 3;
cSeConnecter.gridy = 3;
panelPrincipal.add(seConnecter, cSeConnecter);
JTextField banniere = new JTextField();
banniere.setEditable(false);
GridBagConstraints cBanniere = new GridBagConstraints();
cBanniere.gridx = 1;
cBanniere.gridy = 0;
cBanniere.gridwidth = GridBagConstraints.REMAINDER;
cBanniere.fill = GridBagConstraints.BOTH;
cBanniere.insets = new Insets(10, 10, 10, 10);
panelPrincipal.add(banniere, cBanniere);
return panelPrincipal;
}
class BoutonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
label.setText("Résultat : Pas encore calculé");
}
}
public JTextField getField1() {
return loginField;
}
public JTextField getField2() {
return passwordField;
}
}
class Logo extends JPanel {
Image img;
public Logo() {
try {
this.img = ImageIO.read(new File("graf10.gif"));// new
// Dimension(img.getWidth(null),
// img.getHeight(null))
this.setPreferredSize(new Dimension(img.getWidth(null), img
.getHeight(null)));
} catch (IOException ex) {
ex.printStackTrace();
}
}
@Override
public void paintComponent(Graphics g) {
g.drawImage(img, 0, 0, this);
}
} |
Partager