Statut : Non résoluInserer une image en java
Pierro56, le mardi 25 mars 2008 à 11:33:59 Bonjour,
voila j'ai consulté plusieurs forum depuis quelques jour et je n'arrive toujours pas à insérer une image de fond dans mon petit programme. Voici mon code, si quelqu'un pourrait m'aider ce serait très gentil merci.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.reflect.*;
public class ConnectView extends JFrame implements ActionListener
{
private JPasswordField passwordField;
private JTextField loginField;
private HomeView Home;
JPanel p1 = new JPanel();
JPanel p0 = new JPanel();
public ConnectView(String caption)
{
setTitle(caption);
p1.setVisible(true);
p1.setOpaque(true);
setContentPane(p1);
p1.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
loginField = new JTextField(10);
loginField.setActionCommand("Text");
loginField.addActionListener(this);
JLabel loginLabel = new JLabel("Identifiant");
loginLabel.setLabelFor(loginField);
JButton connection = new JButton("Connexion");
connection.setActionCommand("Connexion");
connection.addActionListener(this);
passwordField = new JPasswordField(10);
passwordField.setActionCommand("pass");
passwordField.addActionListener(this);
JLabel passwordLabel = new JLabel("Entrez le mot de passe : ");
p1.add(passwordLabel);
p1.add(passwordField);
c.gridx = 0;
c.gridy = 0;
c.insets = new Insets(0,0,5,0);
p1.add(loginLabel,c);
c.gridx = 0;
c.gridy = 1;
c.insets = new Insets(0,0,20,0);
p1.add(loginField,c);
c.gridx = 0;
c.gridy = 2;
c.insets = new Insets(0,0,5,0);
p1.add(passwordLabel,c);
c.gridx = 0;
c.gridy = 3;
c.insets = new Insets(0,0,40,0);
p1.add(passwordField,c);
c.gridx = 0;
c.gridy = 4;
p1.add(connection,c);
} //end constructor
public void actionPerformed(ActionEvent e)
{
if("Connexion".equals(e.getActionCommand()))
{
boolean correct = false;
char [] input = passwordField.getPassword();
String login = loginField.getText();
ConnectEngine anEngine = new ConnectEngine();
if(anEngine.Connexion(login, input))
{
JOptionPane.showMessageDialog(this, "Bonjour " + login);
}
else{
JOptionPane.showMessageDialog(this, "incorrect... re-essayez.");
}
passwordField.setText("");
}
HomeView HM = new HomeView();
HM.setVisible(true);
HM.setSize(326,326);
HM.setLocationRelativeTo(null);
HM.setAlwaysOnTop(true);
HM.setResizable(false);
p1.setVisible(false);
p1.setOpaque(false);
dispose();
}
private static void createAndShowGUI()
{
ConnectView frame = new ConnectView("Ecran de connexion");
frame.setSize(326,326);
//frame.setLayout(new BorderLayout());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
frame.setAlwaysOnTop(true);
frame.setResizable(false);
}
public static void main(String[] args)
{
javax.swing.SwingUtilities.invokeLater(new Runnable()
{
public void run() { createAndShowGUI(); }
});
}
} //end class