Click here to Skip to main content
11,928,754 members (53,761 online)
Rate this:
Please Sign up or sign in to vote.
See more: Java Applet

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


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));
		screen = new MainMenuScreen();
	public void start()
		running = true;;
	public void stop()
		running = false;
	public void run() 
		Graphics realg;
		Graphics g;
				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();
				realg.drawImage(backBuffer, 0, 0, null);
				try {
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
Posted 19-Aug-11 22:56pm
Edited 20-Aug-11 3:05am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.

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

Advertise | Privacy | Mobile
Web04 | 2.8.151126.1 | Last Updated 20 Aug 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100