-1

キーボードから入力を取得するために KeyListener を追加したいので、keyListener を追加してそのメソッドを実装しますが、それを実行して任意のキーを押すと機能しますが、コンソールでは次のように記述します。

  Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedOperationException: Not supported yet.
at Calculator.keyReleased(Calculator.java:520)
at java.awt.Component.processKeyEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Window.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

このキーリスナーが正常に動作した後、ボタンをクリックすると動作が停止し、キーを押しても何も起こりません。私のコード:

 @Override
public void keyPressed(KeyEvent e) {

    try{

        switch (e.getKeyCode())

{
case KeyEvent.VK_NUMPAD0:
case KeyEvent.VK_0:
     num0();
     break;
case KeyEvent.VK_NUMPAD1:
case KeyEvent.VK_1:
     num1();
     break;
case KeyEvent.VK_NUMPAD2:
case KeyEvent.VK_2:
    num2();
     break;
case KeyEvent.VK_NUMPAD3:
case KeyEvent.VK_3:
    num3();
     break;
case KeyEvent.VK_NUMPAD4:
case KeyEvent.VK_4:
    num4();
     break;
case KeyEvent.VK_NUMPAD5:
case KeyEvent.VK_5:
    num5();
     break;
case KeyEvent.VK_NUMPAD6:
case KeyEvent.VK_6:
    num6();
     break;
case KeyEvent.VK_NUMPAD7:
case KeyEvent.VK_7:
    num7();
     break;
case KeyEvent.VK_NUMPAD8:
case KeyEvent.VK_8:
    num8();
     break;
case KeyEvent.VK_NUMPAD9:
case KeyEvent.VK_9:
    num9();
     break;
case KeyEvent.VK_BACK_SPACE:
     back();
     break;
case KeyEvent.VK_DELETE:
     clear();
     break;
case KeyEvent.VK_ENTER:
    equals();
     break;
case KeyEvent.VK_ADD:
    bAdd();
    break;
case KeyEvent.VK_DECIMAL:
    bDot();
    break;
case KeyEvent.VK_MULTIPLY:
      bMul();
     break;
case KeyEvent.VK_SUBTRACT:
    bSub();
   break;
case KeyEvent.VK_DIVIDE:
    bDiv();
   break;
default:

}
}
catch(UnsupportedOperationException ex){}

}

@Override
public void keyReleased(KeyEvent e) {
    throw new UnsupportedOperationException("Not supported yet.");// line 520
}
4

1 に答える 1

1

あなたのプログラムは例外を投げました

at Calculator.keyReleased(Calculator.java:520)

また、次のタイプの例外をスローしました。

java.lang.UnsupportedOperationException: Not supported yet.

Calculator.javaそのため、まだサポートされていないファイル の 520 行目でルーチンを呼び出しているようです。

メソッドが壊れている場所に投稿し、壊れている行をマークしていただければ、さらにお手伝いできます。

于 2012-09-12T16:13:55.947 に答える