Mi problema es que ya puedo mover el circulo pero no puedo hacer que repinte por donde pasa. Quiero que vaya dejando color por donde pase
Código:
import java.awt.Color;
import java.awt.Graphics;
/**
*
* @author isaac
*/
public class PanelGrafica extends javax.swing.JPanel implements Runnable{
/**
* Creates new form PanelGrafica
*/
//Line Y
int x=10;
int y=10;
int x1=10;
int y1=200;
//Line X
int xx=10;
int yy=150;
int xx1=510;
int yy1=150;
//Binarios
int bin,bin1,bin2,bin3,bin4,bin5,bin6,bin7;
//si en 1
int mov=5;
int mov1=100;
//si es 0
int mov2=5;
int mov3=145;
Graphics e;
Thread h;
public PanelGrafica() {
initComponents();
h=new Thread(this);
}
//Binarios metodos
public int binario(int bin)
{
this.bin=bin;
return this.bin;
}
public int binario1(int bin1)
{
this.bin1=bin1;
return this.bin1;
}
public int binario2(int bin1)
{
this.bin2=bin1;
return this.bin2;
}
public int binario3(int bin1)
{
this.bin3=bin1;
return this.bin3;
}
public int binario4(int bin1)
{
this.bin4=bin1;
return this.bin4;
}
public int binario5(int bin1)
{
this.bin5=bin1;
return this.bin5;
}
public int binario6(int bin1)
{
this.bin6=bin1;
return this.bin6;
}
public int binario7(int bin1)
{
this.bin7=bin1;
return this.bin7;
}
@Override
public void paint(Graphics g)
{
g.setColor(getBackground());
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(Color.yellow);
g.drawLine(x, y, x1, y1);
g.setColor(Color.blue);
g.drawLine(xx, yy, xx1, yy1);
g.setColor(Color.red);
g.setColor(Color.orange);
g.drawLine(60, 150,60 ,140);
g.drawLine(105, 150,105 ,140);
g.drawLine(155, 150,155 ,140);
g.drawLine(205, 150, 205, 140);
g.drawLine(255, 150, 255, 140);
if(bin == 0)
{
g.fillOval(mov2, mov3, 10, 10);
}else
if(bin ==1)
{
g.fillOval(mov, mov1, 10, 10);
}
}
public void Iniciar(){
h.start();
}
public void Detener(){
h.suspend();
}
public void Continuar(){
h.resume();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
setBackground(new java.awt.Color(0, 0, 0));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
}// </editor-fold>
@Override
public void run() {
try {
while(true)
{
if(bin==0 )
{
while(mov2 <= 50 )
{
Thread.sleep(100);
mov2+=5;
repaint();
}
//linea
if(bin1==0)
{
while(mov2 < 100){
Thread.sleep(100);
mov2+=5;
repaint();
}
}else if(bin1==1)
{
while(mov3 > 100)
{
Thread.sleep(100);
mov3-=5;
repaint();
}
while(mov2<100)
{
Thread.sleep(100);
mov2+=5;
repaint();
}
}
if(bin2==0)
{
while(mov3 < 145)
{
Thread.sleep(100);
mov3+=5;
repaint();
}
while(mov2 < 150)
{
Thread.sleep(100);
mov2+=5;
repaint();
}
}else if(bin2==1)
{
while(mov3 > 100)
{
Thread.sleep(100);
mov3-=5;
repaint();
}
while(mov2<150)
{
Thread.sleep(100);
mov2+=5;
repaint();
}
}
if(bin3==0)
{
while(mov3<145)
{
Thread.sleep(100);
mov3+=5;
repaint();
}
while(mov2<200)
{
Thread.sleep(100);
mov2+=5;
repaint();
}
}else if(bin3==1)
{
while(mov3>100)
{
Thread.sleep(100);
mov3-=5;
repaint();
}
while(mov2<200)
{
Thread.sleep(100);
mov2+=5;
repaint();
}
}
if(bin4==0)
{
while(mov3<145)
{
Thread.sleep(100);
mov3+=5;
repaint();
}
while(mov2<250)
{
Thread.sleep(100);
mov2+=5;
repaint();
}
}else if(bin4==1)
{
while(mov3>100){
Thread.sleep(100);
mov3-=5;
repaint();
}
while(mov2<250)
{
Thread.sleep(100);
mov2+=5;
repaint();
}
}
}
//si inicia en 1
if(bin==1)
{
while(mov<=50)
{
Thread.sleep(100);
mov+=5;
repaint();
}
if(bin1==0)
{
while(mov1<145)
{
Thread.sleep(100);
mov1+=5;
repaint();
}
while(mov<100)
{
Thread.sleep(100);
mov+=5;
repaint();
}
}else if(bin1==1)
{
while(mov<100)
{
Thread.sleep(100);
mov+=5;
repaint();
}
}
if(bin2==0)
{
while(mov<100)
{
Thread.sleep(100);
mov+=5;
repaint();
}
}else if(bin2==1)
{
while(mov1>100)
{
Thread.sleep(100);
mov1-=5;
repaint();
}
while(mov<150)
{
Thread.sleep(100);
mov+=5;
repaint();
}
}
if(bin3==0)
{
while(mov1<145)
{
Thread.sleep(100);
mov1+=5;
repaint();
}
while(mov<250)
{
Thread.sleep(100);
mov+=5;
repaint();
}
}else if(bin3==1)
{
while(mov<250)
{
Thread.sleep(100);
mov+=5;
repaint();
}
}
if(bin4==0)
{
while(mov1<145)
{
Thread.sleep(100);
mov1+=5;
repaint();
}
while(mov<300)
{
Thread.sleep(100);
mov+=5;
repaint();
}
}else if(bin4==1)
{
while(mov<300)
{
Thread.sleep(100);
mov+=5;
repaint();
}
}
}
}
} catch (Exception e) {
}
}
// Variables declaration - do not modify
// End of variables declaration
}