Bonjour,
je trouve ces classes dans les codes sources java de ce site, j'aimerai m'inspirer a fin de créer une gui original avec une image de fond, et des buttons, textfield, et autres,
le seul problem est que si j'ajoute un button il n'est pas du tout visible. J'importe la classe dans jbuilder et la fenetre s'ouvre bien avec l'image du papillon mais si j'ajoute un jbutton ou un jTextfield il ne sont pas visibles?!
peut l'auteur, ou quelqu'un d'autre m'aider a resoudre ce probleme?
merci d'avance
voici le code
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 package image; /** * <p>Titre : </p> * * <p>Description : </p> * * <p>Copyright : Copyright (c) 2005</p> * * <p>Société : </p> * * @author non attribuable * @version 1.0 */ import javax.swing.*; import java.awt.*; import java.awt.image.*; public class JPanelImageBg extends JComponent { private int mode; private TexturePaint texture; private BufferedImage bufferedImage; public static final int CENTRE = 0; public static final int TEXTURE = 1; JPanelImageBg( String fileName, int mode ) { this.mode = mode; this.bufferedImage = this.toBufferedImage(Toolkit.getDefaultToolkit().getImage(fileName)); this.texture = new TexturePaint(bufferedImage,new Rectangle(0, 0, bufferedImage.getWidth(), bufferedImage.getHeight())); } public void paintComponent(Graphics g) { switch( mode ) { case TEXTURE : Graphics2D g2d = (Graphics2D)g; g2d.setPaint(texture); g2d.fillRect(0, 0, getWidth(), getHeight() ); break; case CENTRE : g.setColor(this.getBackground()); g.fillRect(0,0,getWidth(), getHeight() ); g.drawImage(bufferedImage,(getWidth()-bufferedImage.getWidth())/2,(getHeight()-bufferedImage.getHeight())/2,null); break; default : super.paintComponents(g); } } private BufferedImage toBufferedImage(Image image) { image = new ImageIcon(image).getImage(); BufferedImage bufferedImage = new BufferedImage( image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB); Graphics g = bufferedImage.createGraphics(); g.setColor(Color.white); g.fillRect(0, 0, image.getWidth(null), image.getHeight(null)); g.drawImage(image, 0, 0, null); g.dispose(); return bufferedImage; } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 import java.awt.BorderLayout; import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.JPanel; import java.awt.*; import javax.swing.*; import com.borland.jbcl.layout.XYLayout; import com.borland.jbcl.layout.*; /** * <p>Titre : </p> * * <p>Description : </p> * * <p>Copyright : Copyright (c) 2005</p> * * <p>Société : </p> * * @author non attribuable * @version 1.0 */ public class Cadre1 extends JFrame { JPanel contentPane; XYLayout xYLayout1 = new XYLayout(); JPanel jPanel1 = new JPanel(); XYLayout xYLayout2 = new XYLayout(); JTextField jTextField1 = new JTextField();// ajout jtextfield JButton jButton1 = new JButton(); //ajout button JRadioButton jRadioButton1 = new JRadioButton();//ajout autre button public Cadre1() { try { setDefaultCloseOperation(EXIT_ON_CLOSE); jbInit(); } catch (Exception exception) { exception.printStackTrace(); } } /** * Initialisation du composant. * * @throws java.lang.Exception */ private void jbInit() throws Exception { contentPane = (JPanel) getContentPane(); contentPane.setLayout(xYLayout1); setSize(new Dimension(500, 500)); this.setContentPane(new JPanelImageBg("butterfly.jpg",0)); setTitle("Titre du cadre"); jPanel1=(JPanel) getContentPane(); jPanel1.setBorder(BorderFactory.createRaisedBevelBorder()); jPanel1.setLayout(xYLayout2); jTextField1.setText("jTextField1"); jButton1.setText("jButton1"); jRadioButton1.setText("jRadioButton1"); contentPane.add(jPanel1, new XYConstraints(84, 112, 273, 230)); jPanel1.add(jTextField1, new XYConstraints(27, 49, 209, 31)); jPanel1.add(jButton1, new XYConstraints(26, 148, 74, 29)); jPanel1.add(jRadioButton1, new XYConstraints(178, 149, 44, 28)); } }
Partager