I'm not used to GUI development, but now I need it a little bit, and I want to avoid reading all documentation just because of this problem.
I'm having trouble displaying a custom component like the one I posted below. If I add it to a JFrame it works fine, but I cant add more then one, and if I add it to a JPanel it wont be displayed at all.
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JComponent;
public class Test extends JComponent implements Runnable {
private int c,x,y;
public Test(int x,int y){
c = 0;
this.x = x;
this.y = y;
}
private void inc(){
c++;
if(c>255){
c = 0;
}
}
public void paint(Graphics g) {
g.setColor(new Color(c,c,c));
g.fillRect(x, y, 50, 50);
}
public void run() {
while(true){
inc();
try{
Thread.currentThread().sleep(20);
} catch (Exception e){
}
repaint();
}
}
}