Problem for the ImageIcon can't show after paintComponent()
i want to draw a chessboard on a panel,and set a robot (a imageicon of JLabel) on the chessboard,then move the robot .but the question is ,i have to paintComponent () to draw the chessboard,then when the board add JLabel,i can't see the imageicon. if i do not use method of paintComponent() to draw ,i can see the imageicon.
this is my code,there are three classes.
import javax.swing.*;
import java.awt.*;
publicclass Labelextends JLabel{
private ImageIcon icon;
public Label(){
icon=new ImageIcon(this.getClass().getResource("robot.gif"));
this.setIcon(icon);
}
}
import javax.swing.*;
import java.awt.*;
publicclass ImageTestextends JFrame{
private Board board=null;
public ImageTest(){
this.setSize(700,700);
this.setLocation(200,150);
board=new Board();
this.getContentPane().add(board);
setVisible(true);
}
publicstaticvoid main(String args[]){
ImageTest imageTest=new ImageTest();
}
}
import java.awt.*;
import javax.swing.*;
publicclass Boardextends JPanel{
private Label label=null;
public Board(){
label=new Label();
this.add(label);
}
// this is the problem,if i don't use this method and draw nothing,i can see the imageicon when the program run
publicvoid paint(Graphics g){
super.paintComponent(g);
this.add(label);
}
}

