Click here to Skip to main content
15,882,838 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have some problems with my Applet viewer/Applet/Canvas:

When i use it, the Applet viewer is the size i want, but the applet itself is 1x2(Pixels)

I am using Eclipse

Source:

Java
package net.petterroea;
 
import java.applet.Applet;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
 
public class TheBox extends Applet implements Runnable{
	Input input;
	Screen screen;
	boolean running;
	Thread thisThread;
	Image backBuffer;
	public TheBox()
	{
		thisThread = new Thread(this);
		input = new Input(this);
		this.setPreferredSize(new Dimension(640, 480));
		this.addKeyListener(input);
		this.addFocusListener(input);
		this.addMouseListener(input);
		Media.loadImages();
		screen = new MainMenuScreen();
	}
	@Override
	public void start()
	{
		running = true;
		thisThread.run();
	}
	@Override
	public void stop()
	{
		running = false;
	}
	@Override
	public void run() 
	{
		Graphics realg;
		Graphics g;
		while(running)
		{
			synchronized(this)
			{
				System.out.println(this.getWidth() + " " + this.getHeight());
				realg = this.getGraphics();
				if(backBuffer == null)
				{
					backBuffer = createImage(this.getWidth(), this.getHeight());
				}
				else if(backBuffer.getWidth(null) != this.getWidth() || backBuffer.getHeight(null) != this.getHeight())
				{
					backBuffer = createImage(this.getWidth(), this.getHeight());
					
				}
				g = backBuffer.getGraphics();
				screen.tick(g);
				realg.drawImage(backBuffer, 0, 0, null);
				try {
					Thread.sleep(50);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
}
Posted
Updated 20-Aug-11 2:05am
v2

1 solution

Simple answer: Your code is wrong.
Complex answer: We cannot guess anything about your code without seeing where it is going wrong, and by you explaining what you expect it to do.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900