importjava.awt.*;importjava.awt.event.*;publicclassMainClassextendsFrame{privateKeyEventHandlerkeyListener=newKeyEventHandler();privateWindowCloserwindowListener=newWindo...
import java.awt.*;
import java.awt.event.*;
public class MainClass extends Frame
{
private KeyEventHandler keyListener = new KeyEventHandler ();
private WindowCloser windowListener = new WindowCloser ();
public MainClass ()
{
addKeyListener (keyListener);
addWindowListener (windowListener);
setSize (200, 200);
setVisible (true);
}
public static void main (String[] args)
{
MainClass a = new MainClass ();
} // main method
}
class KeyEventHandler implements KeyListener
{
public void KeyPressed (KeyEvent ke)
{
if (ke.getKeyChar () == 'q')
{
System.exit (0);
}
}
public void keyReleased (KeyEvent ke)
{
}
public void keyTyped (KeyEvent ke)
{
System.out.println (ke.getKeyChar ());
}
}
class WindowCloser implements WindowListener
{
public void windowClosing (WindowEvent we)
{
System.exit (0);
}
public void windowOpened (WindowEvent we)
{
}
public void windowIconified (WindowEvent we)
{
}
public void windowDeiconified (WindowEvent we)
{
}
public void windowClosed (WindowEvent we)
{
}
public void windowActivated (WindowEvent we)
{
}
public void windowDeactivated (WindowEvent we)
{
}
}
哪位高手帮忙看看哪错了。。
回二楼..不好意思,这是test的.. 后面的复杂着呢...
Ready to program..你的run不了..
展开