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
| import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.beans.EventHandler;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.JWindow;
public class MainWindow extends JWindow {
private static final long serialVersionUID = 1L;
private JLabel welcomeLbl = null;
private JPanel loginPane = null;
private JLabel loginLbl = null;
private JLabel passwordLbl = null;
private JTextField loginField = null;
private JPasswordField passwordField = null;
private JButton loginBt = null;
private Image img = null;
public MainWindow() {
initGUI();
}
public void initGUI() {
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension dim = toolkit.getScreenSize();
setSize(dim.width / 2, dim.height / 2);
setLocation(dim.width / 2 - getWidth() / 2, dim.height / 2
- getHeight() / 2);
this.getContentPane().add(createLoginPanel(), BorderLayout.CENTER);
System.out.println(this.getWidth() +""+ this.getHeight());
setVisible(true);
}
public void paintComponent(Graphics g)
{
img = Toolkit.getDefaultToolkit().getImage("assets/budget.png");
g.drawImage(img, 0, 0, this.getWidth(),this.getHeight(), createLoginPanel());
}
public JLabel getWelcomeLbl() {
if (welcomeLbl == null) {
welcomeLbl = new JLabel(
"Syndicat Manager, your easy way to manage your syndicat");
welcomeLbl.setForeground(Color.green.darker());
}
return welcomeLbl;
}
private JPanel createLoginPanel() {
if (loginPane == null) {
loginPane = new JPanel();
loginPane.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
int i = 0;
gbc.insets = new Insets(2, 2, 2, 2);
gbc.anchor = GridBagConstraints.NORTHEAST;
gbc.gridx = 1;
gbc.gridy = i;
loginPane.add(new JLabel("Veuillez entrer vos paramètres"), gbc);
i++;
loginLbl = new JLabel("Login ");
gbc.gridx = 0;
gbc.gridy = i;
gbc.gridwidth = 1;
gbc.fill = GridBagConstraints.NONE;
loginPane.add(loginLbl, gbc);
loginField = new JTextField(20);
gbc.gridx = 1;
gbc.gridy = i;
gbc.gridwidth = 2;
gbc.fill = GridBagConstraints.HORIZONTAL;
loginPane.add(loginField, gbc);
i++;
passwordLbl = new JLabel("Mot de passe ");
gbc.gridx = 0;
gbc.gridy = i;
gbc.gridwidth = 1;
gbc.fill = GridBagConstraints.NONE;
loginPane.add(passwordLbl, gbc);
passwordField = new JPasswordField();
gbc.gridx = 1;
gbc.gridy = i;
gbc.gridwidth = 2;
gbc.fill = GridBagConstraints.HORIZONTAL;
loginPane.add(passwordField, gbc);
i++;
loginBt = new JButton("Se connecter");
loginBt.setName("loginBt");
loginBt.addActionListener(EventHandler.create(ActionListener.class,
this, "mouseClicked", "source"));
gbc.gridx = 2;
gbc.gridy = i;
gbc.anchor = GridBagConstraints.CENTER;
gbc.fill = GridBagConstraints.BOTH;
loginPane.add(loginBt, gbc);
loginPane.setBackground(new Color(252, 252, 252));
loginPane.setBorder(BorderFactory.createLineBorder(Color.GRAY));
}
return loginPane;
}
public void mouseClicked(JButton jb) {
if (jb.getName() == "loginBt") {
new SyndicatMain().setVisible(true);
// close the window after calling the main frame of the application
addWindowListener (new WindowAdapter(){
public void windowClosing (WindowEvent e){
System.exit(0);
}
});
}
}
public static void main(String[] args) {
new MainWindow();
}
} |
Partager