I do not see anything wrong with this code, but I keep getting an error when I try to compile. I use JDK environment and just compile in a command prompt window. The error I get is:
myframe.java:26: ')' expected
if( (x+=3) 200) continue;
1 error
The code and the text in red is where the error is supposed to be. In the error message, the "<" doesn't show for some reason.
import java.awt.*;
class myframe extends Frame {
static int x=0,y=120; // x,y position to display message
static int i=0;
static int LtoR=1; // 1->msg L-to-R, 0->top to bot.
Font fb = new Font("TimesRoman", Font.BOLD, 36);
String msg[]={"Java", "Portable", "Secure", "Easy"};
Color color[]={Color.blue, Color.yellow, Color.green, Color.red};
public void paint(Graphics g) { // gets called by the runtime
g.setFont( fb );
g.setColor( color[i] );
g.drawString(msg[i],x,y);
}
static public void main(String s[]) throws Exception {
myframe mf = new myframe();
mf.setSize(220,200);
int pixelsPerLine=200, totalLines=4;
mf.setVisible(true);
for (int j=0;j<pixelsPerLine*totalLines; j++) {
Thread.sleep(25);
mf.repaint();
if (LtoR==1) {
if ( (x+=3) < 200) continue;
i = ++i % 4; // mv i to next msg/color
x=50; y=0; LtoR=0; // mv msg top to bot next
} else {
if ( (y+=3) < 200) continue;
i = ++i % 4; // mv i to next msg/color
x=0; y=120; LtoR=1; // move msg L-to-R next
}
}
System.exit(0);
}
}
Thanks.