| |

VerySource

 Forgot password?
 Register
Search
View: 653|Reply: 1

Urgent ~~~~~ Questions about applets

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-22 18:00:02
| Show all posts |Read mode
I wrote a text marquee effect in the applet. If the double buffering technology (update (Graphics g) method is used, those texts will overlap. If not used, this problem will not occur. But do not use double If the buffering technology is used, the displayed interface will flash.
How can I solve this problem?
Or give an example

Here is the program code:
import java.awt. *;
import java.applet. *;
import java.util.Date;

public class Clock extends Applet implements Runnable
{
    Thread clockThread;
    Font font;
    String s = "Okay !!!!";
    int count = 0;
public void init () {
Ranch
font = new Font ("TimesRoman", Font.BOLD, 48);
}
public void start ()
{
if (clockThread == null)
clockThread = new Thread (this, "Showtime");
clockThread.start ();
Ranch
}
public void run ()
{
// while (clockThread! = null)
while (true)
{
repaint ();
try {
clockThread.sleep (300);
}
catch (InterruptedException e) {}
}
}
Ranch

public void paint (Graphics g) {
    double a, b, c, d, e, f;
    int h, i, j, k, l, m;
    Date now = new Date ();
    a = now.getSeconds ();
    b = now.getMinutes ();
    c = now.getHours ();
    d = (a-15) * Math.PI / 180 * 6;
    e = (b-15) * Math.PI / 180 * 6;
    f = (c-15) * Math.PI / 180 * 6;
    h = (int) (Math.sin (d) * 65);
    i = (int) (Math.cos (d) * 65);
    j = (int) (Math.sin (e) * 54);
    k = (int) (Math.cos (e) * 54);
    l = (int) (Math.sin (f) * 44);
    m = (int) (Math.cos (f) * 44);
    g.translate (100,100);
    play (getDocumentBase (), "a.wav");
    g.drawLine (0,0, i, h);
    g.drawLine (0,0, k, j);
    g.drawLine (0,0, m, l);
    g.drawString (now.getHours () + ":" + now.getMinutes () + ":" + now.getSeconds (),-10,100);
    char [] s1 = s.toCharArray ();
    int n1;
    String q = new String ();
    for (n1 = count; n1 <s1.length; n1 ++) {
    q + = s1 [n1];
    }
    count ++;
    g.drawString (q, 100,100);
    if (count == s1.length)
    {
    count = 0;
    }
    g.drawString (s, 100,110);
    g.drawString (s, 160,120);
}

    public void update (Graphics g) {// Double buffering technology
       paint (g);
     }

public void stop ()
{
clockThread.stop ();
}
}

Let's take a look
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 Norway

Post time: 2020-3-24 22:00:01
| Show all posts
Isn't it just a watch? Is it enough to redraw the second hand every second?
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list