Problème avec mon titledborder
Bonjour j'ai écris un petit programme qui étend une applet mais seulement, le problème c'est que mon TitledBorder à la même hauteur pour les deux blocs que j'ai coder. De plus je n'arrive pas a aligner mon applet au centre de ma fenetre. Voici le code que j'ai tapé sous netbeans
Code:
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
| package Calcul;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.TitledBorder;
class ImagePanel extends JPanel {
private Image img;
public ImagePanel(String img) {
this(new ImageIcon(img).getImage());
}
public ImagePanel(Image img) {
this.img = img;
}
protected void paintComponent(Graphics g) {
g.drawImage(img, 0, 0, null);
}
}
public class Calculons extends JApplet{
private action test = new action(this);
public JMenuBar mb = new JMenuBar();
public JMenu text1 = new JMenu("Texte");
public JMenu son1 = new JMenu("Musique");
public JMenuItem demar1 = new JMenuItem("Démarrer");
public JMenuItem arret1 = new JMenuItem("Arrêter");
public JMenuItem affich = new JMenuItem("Afficher");
public JMenuItem masque = new JMenuItem("Masquer");
public JMenuItem demar2 = new JMenuItem("Démarrer L'annimation");
public JMenuItem arret2 = new JMenuItem("Arrêter L'annimation");
public JLabel lab1 = new JLabel("Opérande 1 :");
public JLabel lab2 = new JLabel("Opérande 2 :");
public JLabel lab3 = new JLabel("<HTML>Résultat : </HTML>");
public JLabel lab4 = new JLabel("DIT - MGL I");
public JTextField t1 = new JTextField(15);
public JTextField t2 = new JTextField(15);
public JTextField t3 = new JTextField("0.0",15);
public JButton pl = new JButton("+");
public JButton mn = new JButton("-");
public JButton ml = new JButton("*");
public JButton dv = new JButton("/");
public JButton c = new JButton("C");
public JPanel p1 = new JPanel();
public JPanel p2 = new JPanel();
public JPanel p3 = new JPanel();
public JPanel p4 = new JPanel();
public JPanel p5 = new JPanel();
ImagePanel panel = new ImagePanel(new ImageIcon(getClass().getResource("fond.jpg")).getImage());
public void content(){
lab1.setForeground(Color.white);
lab2.setForeground(Color.white);
lab3.setForeground(Color.white);
mb.add(text1);
mb.add(son1);
text1.add(affich);
text1.addSeparator();
text1.add(masque);
masque.setBackground(Color.white);
text1.addSeparator();
text1.add(demar2);
text1.addSeparator();
text1.add(arret2);
arret2.setBackground(Color.white);
son1.add(demar1);
son1.addSeparator();
son1.add(arret1);
arret1.setBackground(Color.white);
t3.setEditable(false);
this.setJMenuBar(mb);
p1.add(lab1);
p1.add(t1);
p2.add(lab2);
p2.add(t2);
p3.add(lab3);
p3.add(t3);
p5.setBorder(new TitledBorder("Opérades"));
p5.setLayout(new FlowLayout(FlowLayout.LEFT));
p5.add(p1);
p5.add(p2);
p5.add(p3);
p4.setBorder(new TitledBorder("Opérations"));
p4.add(pl);
p4.add(mn);
p4.add(ml);
p4.add(dv);
p4.add(c);
pl.addActionListener(test);
ml.addActionListener(test);
mn.addActionListener(test);
dv.addActionListener(test);
c.addActionListener(test);
p1.setOpaque(false);
p2.setOpaque(false);
p3.setOpaque(false);
p4.setOpaque(false);
p5.setOpaque(false);
panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS));
panel.add(p5);
panel.add(p4);
getContentPane().add(panel);
}
public Calculons(){
content();
}
/** Initializes the applet Animation */
public void init() {
try {
java.awt.EventQueue.invokeAndWait(new Runnable() {
public void run() {
new Calculons();
setSize(300,300);
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
}
} |