-
Flickering in applet problem
Hey right now i'm simply writing a probram that will move crosshairs around the screen with green ships put on the screen and that's all it's supposed to be doing but it flickers and i'm using double buffering:
import static java.lang.System.*;
import java.io.*;
import java.util.*;
import java.text.*;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class prob1 extends Applet implements MouseListener,MouseMotionListener,Runnable
{
int px=0,py=0,opx=0,opy=0,radi=10;
Image vMem;
Graphics s;
Thread pl;
ArrayList<Ship> ships = new ArrayList<Ship>();
public void init()
{
int aW=getWidth();
int aH=getHeight();
px=getWidth()/2;py=getHeight()/2;
opx=px;opy=py;
vMem=createImage(aW,aH);
s = vMem.getGraphics();
addMouseListener(this);
addMouseMotionListener(this);
createShips();
pl=new Thread();
}
public void run()
{
drawCrosshair();
}
public void createShips()
{
for(int x=0;x<5;x++)
ships.add(new Ship(x*30,30,10,s));
}
public void drawShips()
{
for(int x=0;x<ships.size();x++)
ships.get(x).drawShip();
}
public void paint(Graphics screen)
{
drawShips();
drawCrosshair();
screen.drawImage(vMem,0,0,this);
super.paint(screen);
}
public void drawCrosshair()
{
s.setColor(Color.white);
s.drawOval(opx,opy,1,1);
s.drawOval(opx-radi,opy-radi,radi*2,radi*2);
s.drawLine(opx,opy+radi+3,opx,opy-radi-3);
s.drawLine(opx-radi-3,opy,opx+radi+3,opy);
opx=px;opy=py;
s.setColor(Color.black);
s.drawOval(px,py,1,1);
s.drawOval(px-radi,py-radi,radi*2,radi*2);
s.drawLine(px,py+radi+3,px,py-radi-3);
s.drawLine(px-radi-3,py,px+radi+3,py);
}
public void mouseClicked(MouseEvent evt){}
public void mousePressed(MouseEvent evt){}
public void mouseMoved(MouseEvent evt)
{
px=evt.getX();
py=evt.getY();
drawCrosshair();
repaint();
}
public void mouseDragged(MouseEvent evt)
{
px=evt.getX();
py=evt.getY();repaint();
}
public void mouseReleased(MouseEvent evt){}
public void mouseExited(MouseEvent evt){}
public void mouseEntered(MouseEvent evt){}
}
They say if you play a Microsoft Windows CD backwards it will play satanic messages. But thats nothing, if you play it forwards it installs Windows.
Similar Threads
-
By ah_beng78 in forum Java
Replies: 0
Last Post: 03-22-2006, 02:17 AM
-
By aesoprock00 in forum Java
Replies: 2
Last Post: 01-28-2006, 06:18 PM
-
By Tataroz T. in forum Java
Replies: 1
Last Post: 10-20-2005, 06:19 AM
-
Replies: 0
Last Post: 12-13-2001, 12:06 PM
-
By John Syrakis in forum Java
Replies: 0
Last Post: 11-09-2000, 04:11 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks