JLabel not displaying text
Hello i have a problem displaying properly my JLabel here is the code for my class extending JLabel :
publicclass PanneauScoreextends JLabel
{
privateint score = 0;
/** Creates a new instance of PanneauScore */
public PanneauScore()
{
this.setText("score = " + score);
}
publicvoid incrementerScore(int y)
{
score += y;
this.setText("score = " + score);
}
publicvoid paintComponent(Graphics g)
{
((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(Color.MAGENTA);
g.drawRect(0, 0, 80, 20);
}
}
and here is where i use this class :
publicclass MyFrameextends JFrame
{
private JPanel backgroundPanel;
private PanneauScore unPanneauDeScore;
/** Creates a new instance of MyFrame */
public MyFrame()
{
Runnable runner =new Runnable()
{
publicvoid run()
{
backgroundPanel =new JPanel()
{
publicvoid paintComponent(Graphics g)
{
((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(Color.YELLOW);
g.fillRect(360, 320, 30, 30);
g.setColor(Color.RED);
g.fillOval(360, 320, 30, 30);
g.setColor(Color.BLACK);
g.fillOval(0, 80, 30, 30);
g.setColor(Color.RED);
g.drawOval(2, 120, 26, 26);
g.drawOval(0, 118, 30, 30);
g.drawString("100", 2, 140);
g.drawOval(2, 160, 26, 26);
g.drawOval(0, 158, 30, 30);
g.drawString("200", 2, 180);
g.drawOval(0, 200, 30, 30);
g.drawString("100", 2, 220);
g.drawOval(0, 240, 30, 30);
g.drawString("200", 0, 260);
g.setColor(Color.GREEN);
g.fillRect(0, 280, 30, 5);
g.drawLine(0, 283, 30, 285);
g.drawLine(30, 285, 0, 287);
g.drawLine(0, 287, 30, 289);
g.drawLine(30, 289, 0, 291);
}
};
setLayout(new BorderLayout());
unPanneauDeScore =new PanneauScore();
getContentPane().add(unPanneauDeScore, BorderLayout.NORTH);
getContentPane().add(backgroundPanel, BorderLayout.CENTER);
addWindowListener(new WindowAdapter()
{
publicvoid windowClosing(WindowEvent e)
{
System.exit(0);
}
});
setSize(400, 400);
setVisible(true);
}
};
SwingUtilities.invokeLater(runner);
}
publicstaticvoid main(String[] args)
{
MyFrame frame =new MyFrame();
}
}
thank you for help

