Depressed! ! How to achieve the applet subtitles rolling effect? Engage in a few days did not engage in out

Category: Java SE
 
ronghua_job
2009-01-31 01:14:44

Sponsored Links
My original code is as follows:
import java.awt. *;
Import java.applet. *;

Public class applet1 extends Applet implements Runnable {
Thread t;
String msg = "welcome to java!";
int state;
boolean stopflag;

public void init () {
setBackground (Color.cyan);
setForeground (Color.yellow);
}

public void start () {
t = new Thread (this);
stopflag = false;
t.start ();
}

public void run () {
char ch;
for ( ; ;) {
try {
repaint ();
Thread.sleep (300);
ch = msg.charAt (0);
msg = msg.substring (1, msg.length ());
msg + = ch;
; if (stopflag)
break;
} catch (java.lang.InterruptedException e) {}
}
}
public void stop () {
stopflag = true;
t = null;
}

; public void paint (Graphics g) {
g.drawString (msg, 50,30);
}
}

html file under:
<html>
<head>
<meta http-equiv = "Content-Type" content = "text / html; charset = GBK">
<title>
HTML Test Page
</title>
</head>
<body>
Applet1 will appear below in a Java enabled browser. <br>
<applet
code ; = "actword.class.Applet1"
width = "400"
; height = "300"
>
</applet>
</body>
</html>

path nothing bad, but I could not realize the trouble you ggjj facie, grateful brother! ! !

Sponsored Links

huangtebo
2009-01-31 01:22:50
g.drawString (msg, 50,30);

coordinates are fixed here, able to roll it?
qiqi_0303
2009-01-31 01:40:51
Since it is through drawing (paint) painted text, but you want to scroll, so, g.drawString yes, the coordinate transformation ah! For example g.drawString (msg, x, 30); Then, in a place to change x, and then notify the repaint () to redraw.
shenqikysdj
2009-01-31 01:58:00
import java.awt. *;
Import java . applet. *;

public class applet1 extends Applet implements Runnable {
Thread t;
String msg = "welcome to java!";
int state = 70;
boolean stopflag;

public void init () {
setBackground (Color.cyan);
setForeground (Color.yellow);
}

public void start () {
t = new Thread (this);
stopflag = false;
t.start ();
}

public void run ()
{

; while (true) {
state = state -1;
if (state <-69)
state = 70;
repaint ();
try {
Thread.sleep (300);
;} catch (InterruptedException e) {}
}
;}

public void stop () {
stopflag = true;
t = null;
}

; public void paint (Graphics g)
{
for (int i = 0; i <= msg.length (); i + +)
; g.drawString (msg.charAt (i), state + i, 50) / / state + i in turn draw a single Character
; ; / / OK fixed
;}

Because of my internet cafe without debugging environment so I did not test this program ; which may exist with errors, but the basic idea is that I will continue to pay attention you have any questions give me back

huzeper
2009-01-31 02:10:39
import java.awt. *;
import java.applet. *;

public class applet1 extends Applet implements Runnable {
Thread t;
String msg = "welcome to java!";
int state = 70;
boolean stopflag;

public void init () {
setBackground (Color.cyan);
setForeground ( Color.yellow);
}

public void start () {
t = new Thread (this) ;
stopflag = false;
t.start ();
}

public void run ()
{

while (true) {
; state = state -1;
if (state <-69 )
state = 70;
; repaint ();
try {
; Thread.sleep (300);
} catch (InterruptedException e) {}
}
}

public void stop () {
; stopflag = true;
; t = null;
}

public void paint (Graphics g)
{
for (int i = 0; i <= msg.length (); i + +)
g.drawString (msg.charAt (i), state + i, 50) / / state + i in turn draws a single character
/ / OK fixed
}

Because of my internet cafe without debugging environment ; so I did not test this procedure which may exist with errors, but the basic idea is that I will continue to pay attention you have any questions give me back

Domain and server ip had changed since 8/23/2013. Suspend the user registration and posts for program maintenance.