Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Other Java > Java GUI
Java GUI Discussions specific to programming Java GUI.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java GUI section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 3rd, 2003, 02:51 PM
Registered User
Join Date: Aug 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Trouble Converting Application to applet

Hi, i have a simple Snake game i programmed as an application. Now i want to convert it to an applet in the standard way. All is fine and dandy except the key listeners no longer work. Why is this and why would an applet behave differently to the application?

the code for the KeyHandler:

import java.awt.event.*;

public class KeyHandler extends KeyAdapter {

    public KeyHandler(GamePane controller) {
        this.controller = controller;
        System.out.println("key handler created");

    public void keyPressed(KeyEvent e) { System.out.println("key pressed");
        int keyCode = e.getKeyCode();

    private GamePane controller;

In the main JApplet class, this is how it is added:

addKeyListener(new KeyHandler(gamePane));

The message that the keyHandler has been created is received, but there is never any message so say that a key has been pressed. No exception occur and the applet is in focus.

Many thanks
Old August 18th, 2003, 05:27 AM
Registered User
Join Date: Aug 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

At what point do u call : addKeyListener(new KeyHandler(gamePane))????

Old August 19th, 2003, 01:30 AM
Authorized User
Join Date: May 2003
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts

On which all browser's have u tested this applet. JApplet dosen't behave properly on most of the browser's. Have u installed a java/swing plugin to run swing component's on your browser.


Yashraj Chauhan
Java\J2EE Specialist
Wiley Support Team

Similar Threads
Thread Thread Starter Forum Replies Last Post
need help in applet splashsvp Java Basics 1 March 4th, 2007 08:47 AM
Trouble shoting - Server Application Error itHighway ASP.NET 1.0 and 1.1 Professional 1 June 21st, 2005 12:34 PM
Trouble shoting - Server Application Error itHighway ASP.NET 1.0 and 1.1 Basics 1 June 21st, 2005 12:33 PM
Converting an Access VBA application to Mobile PDA Paulsh Access VBA 0 September 21st, 2004 07:27 AM
Web Application Trouble with 2003 Server merediths C# 1 July 25th, 2003 05:50 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.