Posted: Tue Mar 14, 2006 2:58 pm Post subject: (No subject)
oh well now i no the basics of them fro later
Sponsor Sponsor
rizzix
Posted: Tue Mar 14, 2006 6:23 pm Post subject: (No subject)
Ah.. this is the first time I've actually attempted to try out this Applet thing. (had to do it sometime anyway).
Apparently, they don't work like normal swing applications. You are required to repaint the component your self. Hence threads are pretty much necessary.
Attached is the TimedBufferedApplet. What is does is basically "tick" at regular intervals upon which it will repaint the screen. All you are required to do is Override the offscreenPaint method as above..
Now that method has an extra agrument called "frame" well that basically tells you which frame is being drawn out.
By default the tick_interval is i think 100msec. If you find this too slow or too fast, you can change it by calling setTickInterval(some_int); Oh and there's a very special way you need to set this up:
Never make it Zero! Not a good idea, we have to give the awt thread a chance to excute, or else you won't see anything on screen. Yes, the ticking occurs in a different thread (this is why I said threads are sort-of necessary). Also, since this version is not thread safe, dont even think of trying to change the tick interval outside the init method.
public void drawship (int x, int y)
{
dbg.setColor (Color.green);
dbg.fillOval (x, y, 10, 20);
dbg.setColor (Color.red);
dbg.fillOval (x - 10, y + 10, 30, 10);
dbg.setColor (Color.black);
dbg.fillOval (x + 3, y + 4, 4, 4);
}
public void paint (Graphics g)
{
}
}
freeridin101
Posted: Fri Mar 17, 2006 3:37 pm Post subject: (No subject)
am i not putting things in the write spot or is this doulbe buffer not working.i tworks for the computer controlled ship but if you move the mouse up and down fast you see doubles any thoughts??
code:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class doublebufferworks extends Applet implements Runnable
{
int y = 0, y2 = 295, x3 = 0, y3 = 0, score = 0, direction = 0;
private Image dbImage;
private Graphics dbg;
static Graphics g;
public void init ()
{
direction = 1;
y = 10;
score = 0;
resize (800, 600);
}
public void start ()
{
Thread th = new Thread (this);
th.start ();
}
public void MoveEnemyShip ()
{
while (score < 10)
{
y = y + direction;
if (y > 590)
direction = -1;
if (y < 0)
direction = 1;
repaint ();
delay (15);
}
}