Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java Applet
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:
 
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 19-Aug-11 22:56pm
Edited 20-Aug-11 3:05am
v2

1 solution

Rate this: bad
good
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.
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 504
1 Maciej Los 349
2 Kornfeld Eliyahu Peter 325
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,303
1 DamithSL 4,764
2 Maciej Los 4,306
3 Kornfeld Eliyahu Peter 3,914
4 Sergey Alexandrovich Kryukov 3,538


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 20 Aug 2011
Copyright © CodeProject, 1999-2014
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