Quote
SaveChristmas is not abstract and does not override abstract method keyReleased(java.awt.event.KeyEvent) in java.awt.event.KeyListener
Here's my code so far:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/*
<applet code="SaveChristmas" width=300 height=50>
</applet>
*/
public class SaveChristmas extends JApplet
implements KeyListener
{
boolean pause;
char ch = 0;
String hw = "HW";
public void init()
{
addKeyListener(this);
}
public void start()
{
pause = false;
}
public void run()
{
char ch;
for( ; ; )
{
try
{
repaint();
if(pause)
break;
}
catch(InterruptedException exc) {}
}
}
public void stop()
{
pause = true;
}
public void keyTyped(KeyEvent e)
{
ch = getKeyChar();
}
public void paint(Graphics g)
{
g.drawString(hw, 0, 0);
}
}
I am trying to make an RPG, in which the user will input single key commands and am trying to use getKeyChar() to read the key typed. PLEASE NOTE: I'm trying to do this WITHOUT a special text field for input. I've seen it done without making the class abstract, and since I don't know what implications that would have on what my program does, I'm gonna try to avoid that. Please note that I will be using a GridLayout manager, so please make any suggestions compatible with this.
What I have tried:
changing the extends from JApplet to Applet
putting filler code into paint()
I'm fresh out of ideas on how to fix this. Could anyone possible help me? Any amount of help, no matter how small, is gleefully welcomed.

New Topic/Question
Reply



MultiQuote



|