HELLO guys IM beginner using java IM asking what is my problem of my codes?? can you fix it??
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
public class invalid3 extends Applet implements Runnable {
/**
*
*/
private static final long serialVersionUID = 1L;
private int x0 , y0 , incx , incy,height0, width0;
private int x1, y1,width1,height1;
private Thread boxOne;
private Thread boxTwo;
public void init() {
resize(800,1000);
// box one;
x0=0;
y0=0;
width0=300;
height0=300;
boxOne = new Thread(this);
boxOne.start();
// box two
x1=900;
y1=0;
width1=300;
height1=300;
boxTwo = new Thread(this);
boxTwo.start();
}
public void update(Graphics g) {
g.setColor(getBackground());
g.fillRect(0, 0, 800, 1000);
g.fillRect(900,0, 800,1000);
paint(g);
}
public void paint(Graphics g) {
g.setColor(Color.BLACK);
g.drawRect(x0, y0, width0, height0);
g.setColor(Color.BLUE);
g.drawRect(x1, y1, width1, height1);
}
@Override
public void run(){
// TODO Auto-generated method stub
if(Thread.currentThread() == boxOne) {
while(true){
if(x0 < width0 && y0 == 0){
incx = 5;
incy = 0;
}
if(x0 == width0 && y0 < height0){
incx = 0;
incy = 5;
}
if(x0 <= width0 && y0 == height0){
incx = -5;
incy = 0;
}
if(x0 == 0 && y0 > 0){
incx = 0;
incy = -5;
}
x0 = x0 + incx;
y0 = y0 + incy;
try{
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
repaint();
}
}
if(Thread.currentThread() == boxTwo) {
while(true){
if(x1 < 600 && y1 == 0){
incx = -5;
incy = 0;
}
if(x1 == 600 && y1 < height1){
incx = 0;
incy = -5;
}
if(x1 >= 900 && y1 == height1){
incx = 5;
incy = 0;
}
if(x1 == 600 && y1 < 0){
incx = 0;
incy = 5;
}
x1 = x1 - incx;
y1 = y1 - incy;
try{
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
repaint();
}
}
}}
My problem is the boxTwo. the fourth if, is getting false since the right to left and up to down and left to right is reading but the down to up is not reading can anyone help me fix my code???
sorry for my english if i have mistake....