package mypackage1; import java.awt.Graphics; /*package essait.ImportationImage;*/ import java.awt.*; import java.awt.event.*; import javax.swing.JTextField; import java.awt.Rectangle; import javax.swing.JPasswordField; import javax.swing.JLabel; import javax.swing.JButton; public class Images2 extends Frame { // Objets Image image; private JTextField jTextField1 = new JTextField(); private JPasswordField jPasswordField1 = new JPasswordField(); private JLabel jLabel1 = new JLabel(); private JLabel jLabel2 = new JLabel(); private JButton jButton1 = new JButton(); // Constructeur public Images2() { setTitle("Afficher des images"); // Titre // WindowListener addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); // Définir couleur d'arrière-plan setBackground(Color.lightGray); // Charger image image = getToolkit().getImage("C:\\Users.........\\password.gif"); // Créer MediaTracker MediaTracker mt = new MediaTracker(this); // Lier MediaTracker avec image mt.addImage(image, 0); try { //Attendre le chargement complet de l'image mt.waitForAll(); } catch (InterruptedException e) { /* mache nichts */ } // Déclencher nouveau dessin repaint(); // Définir taille setSize(100,100); // Rendre fenêtre visible (afficher) setVisible(true); setBounds(50,50,400,300); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } /** Méthode paint*/ public void paint(Graphics g) { // Dessiner image if (image != null) { g.drawImage(image,20,100,this); } } /** * Méthode main() */ public static void main( String[] args ) { new Images2(); } private void jbInit() throws Exception { this.setLayout(null); jTextField1.setText("jTextField1"); jTextField1.setBounds(new Rectangle(230, 100, 130, 25)); jPasswordField1.setText("jPasswordField1"); jPasswordField1.setBounds(new Rectangle(230, 160, 130, 25)); jLabel1.setText("user"); jLabel1.setBounds(new Rectangle(230, 80, 60, 20)); jLabel2.setText("pass"); jLabel2.setBounds(new Rectangle(230, 140, 60, 20)); jButton1.setText("Connection"); jButton1.setBounds(new Rectangle(235, 210, 115, 25)); this.add(jButton1, null); this.add(jLabel2, null); this.add(jLabel1, null); this.add(jPasswordField1, null); this.add(jTextField1, null); } }