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
|
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class test extends JComponent {
JButton jButton1 = new JButton();
JLabel jLabel1 = new JLabel();
BufferedImage im;
test() {
try {
this.im = ImageIO.read(new File("test.png"));
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
test fenetre = new test();
JFrame f = new JFrame("truc");
f.setContentPane(fenetre);
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
f.setSize(600,400);
f.setLocationRelativeTo(null);
f.setVisible(true);
}
private void jbInit() throws Exception {
jButton1.setBounds(new Rectangle(250, 85, 123, 54));
jButton1.setText("entrer");
this.setLayout(null);
jLabel1.setText("le nom");
jLabel1.setBounds(new Rectangle(181, 94, 60, 38));
this.add(jLabel1, null);
this.add(jButton1, null);
this.repaint();
}
public void paint(Graphics arg0) {
arg0.drawImage(im, 0, 0, this);
super.paint(arg0);
}
} |