prosze o pomoc, probowalem dojsc co jest, ale caly czas nie moge dojsc czemu jest ciagle ten blad:
cannot find symbol symbol : constructor Thread(test2)
location: class java.lang.Thread
animator = new Thread(this);
^
1 error
oto kod:
/**
- @(#)test1.java
- test1 Applet application
- @Author
- @version 1.00 2008/9/28
*/
import java.awt.;
import java.applet.;
import java.awt.Image;
import java.net.URL;
import java.io.IOException;
import java.io.InputStream;
import java.awt.image.*;
import java.awt.event.;
import java.awt.geom.;
import java.applet.Applet;
import java.awt.AWTException;
import java.awt.image.PixelGrabber;
import java.io.BufferedOutputStream;
import java.io.OutputStream;
import java.util.Vector;
//import java.awt.image.BufferedImage;
//import com.sun.image.codec.jpeg.JPEGImageEncoder;
//import com.sun.image.codec.jpeg.JPEGCodec;
public class test2 extends Applet {
float rad,value;
Image img;
int WidthScreen,HeightScreen;
long newTime,oldTime;
int nowFps,getFpsT;
long newTimeS,oldTimeS;
int controlFps;
//dodane
public static final int DEFAULT_FPS = 25;
public static long MAX_STATS_INTERVAL = 1500000000L;
public static final int NO_DELAYS_PER_YIELD = 16;
public static int MAX_FRAME_SKIPS = 5;
public static int NUM_FPS = 10;
public Thread animator;
public volatile boolean running = false;
public volatile boolean isPaused = false;
public long period;
private Image dbImage;
private Graphics dbg;
public void start()
{
if (animator == null || !running)
{
animator = new Thread(this);
animator.start();
}
}
public void stop()
{
animator.interrupt();
animator = null;
}
public void destroy()
{ }
public void digitesd(double vd,int x,int y,Graphics g)
{
g.drawString(String.valueOf(vd),x,y);
}
public void digitesf(float vf,int x,int y,Graphics g)
{
g.drawString(String.valueOf(vf),x,y);
}
public void digitesi(int vi,int x,int y,Graphics g)
{
g.drawString(String.valueOf(vi),x,y);
}
public int[] ImageToInt(Image image, int width, int height){
int pixMap[] = new int[width*height];
PixelGrabber pg = new PixelGrabber(image, 0,0,width,height, pixMap, 0, width);
try {
pg.grabPixels();
} catch (InterruptedException e){return null;}
if((pg.status() & ImageObserver.ABORT)!=0) return null;
return pixMap;
}
public Image IntToImage(int pix[], int width, int height)
{
return this.createImage(new MemoryImageSource(width,height,pix,0,width));
}
public void init()
{
oldTime=0;
newTime=0;
oldTimeS=0;
newTimeS=0;
nowFps=0;
getFpsT=0;
controlFps=85;
setBackground (Color.black);
value=0;
rad=(float)3.141592653/180;
img=getImage(getDocumentBase(),"plika.JPG");
WidthScreen=320;
HeightScreen=240;
int pix[] = ImageToInt(img,WidthScreen,HeightScreen);
for(int i=0;i<WidthScreen*HeightScreen;i++)
{
int alpha=(pix[i] >> 24) & 255;
int red=(pix[i] >> 16) & 255;
int green=(pix[i] >> 8) & 255;
int blue=(pix[i]) & 255;
pix[i]=blue+256*green+(256*256)*red+(256*256*256)*alpha;
}
img=IntToImage(pix,WidthScreen,HeightScreen);
}
public int getTimeDi()
{
long timeD;
oldTime=newTime;
newTime=System.nanoTime();
if(newTime>oldTime)
timeD=newTime-oldTime;
else
timeD=oldTime-newTime;
return (int)timeD;
}
public float getTimeDf()
{
return (float)getTimeDi()/1500000000;
}
long OldTime,NewTime;
long fps=85;
public int getFPS()
{
NewTime=System.nanoTime();
if(OldTime!=0 && (NewTime-OldTime)!=0)
{
long NEW_FPS=1500000000/(NewTime-OldTime);
if (fps>NEW_FPS)
fps--;
else if (fps<NEW_FPS)
fps++;
}
OldTime=NewTime;
return (int)fps;
}
public int getFps()
{
newTimeS=System.nanoTime();
if(newTimeS>oldTimeS)
{
if(newTimeS-oldTimeS>=1500000000)
{
oldTimeS=newTimeS;
getFpsT=nowFps;
nowFps=0;
}
else
nowFps++;
}
if(oldTimeS>newTimeS)
{
if(oldTimeS-newTimeS>=1500000000)
{
oldTimeS=newTimeS;
getFpsT=nowFps;
nowFps=0;
}
else
nowFps++;
}
return getFpsT;
}
public void gameUpdate()
{
}
public void gameRender()
{
if (dbImage == null)
{
dbImage = createImage(320, 240);
if (dbImage == null)
{
System.out.println("dbImage is null");
return;
}
else
dbg = dbImage.getGraphics();
}
//draw
}
public void paintScreen()
{
Graphics g;
try {
g = this.getGraphics();
if ((g != null) && (dbImage != null))
g.drawImage(dbImage, 0, 0, null);
Toolkit.getDefaultToolkit().sync(); // sync the display on some systems
g.dispose();
}
catch (Exception e) // quite commonly seen at applet destruction
{ System.out.println("Graphics Context error: " + e); }
}
public void paint(Graphics g) {
value+=1;
g.setColor(Color.green);
g.drawString("fps:",2,10);
digitesi(getFps(),25,10,g);
float beta=value*rad;
int x=Math.round(160+100*(float)Math.sin(beta));
int y=Math.round(100+100*(float)Math.cos(beta));
g.drawImage(img,x,y,this);
g.drawString("BH is live!",x,y);
//repaint();
}
public void run()
{
long gameStartTime,beforeTime, afterTime, timeDiff, sleepTime,prevStatsTime;
long overSleepTime = 0L;
int noDelays = 0;
long excess = 0L;
gameStartTime = System.nanoTime();
prevStatsTime = gameStartTime;
beforeTime = gameStartTime;
running = true;
while(running) {
gameUpdate(); //liczenie itd
gameRender(); // rysowanie to bufora
paintScreen(); // rysowanie bufora na ekranie
afterTime = System.nanoTime();
timeDiff = afterTime - beforeTime;
sleepTime = (period - timeDiff) - overSleepTime;
if (sleepTime > 0) { // some time left in this cycle
try {
Thread.sleep(sleepTime/1500000000); // nano -> ms
}
catch(InterruptedException ex){}
overSleepTime = (System.nanoTime() - afterTime) - sleepTime;
}
else { // sleepTime <= 0; the frame took longer than the period
excess -= sleepTime; // store excess time value
overSleepTime = 0L;
if (++noDelays >= NO_DELAYS_PER_YIELD) {
Thread.yield(); // give another thread a chance to run
noDelays = 0;
}
}
beforeTime = System.nanoTime();
int skips = 0;
while((excess > period) && (skips < MAX_FRAME_SKIPS)) {
excess -= period;
gameUpdate(); // liczenie itd
skips++;
}
}
}
/public void update (Graphics g)
{
//DoubleBuffers
if (dbImage == null)
{
dbImage = createImage (this.getSize().width, this.getSize().height);
dbg = dbImage.getGraphics ();
}
dbg.setColor (getBackground ());
dbg.fillRect (0, 0, this.getSize().width, this.getSize().height);
dbg.setColor (getForeground());
paint (dbg);
g.drawImage (dbImage, 0, 0, this);
}/
}