当前位置: 代码迷 >> Java相关 >> java编译时出现问题 ,谢谢了
  详细解决方案

java编译时出现问题 ,谢谢了

热度:265   发布时间:2007-10-25 22:01:00.0
java编译时出现问题 ,谢谢了


import java.awt.*;
import java.awt.event.*;
public class MultipleEventTester extends Frame implements WindowListener,MouseListener,KeyListener{
//定义域
public MultipleEventTester()
//定义构造方法
{
addWindowListener(this);
addMouseListener(this);
addKeyListener(this);
setSize(200,200);
//pack();
show();
}
//窗口处理事件
public void WindowClosing(WindowEvent we)
{ System.exit(0);}
public void WindowOpened(WindowEvent we)
{ System.out.println("窗口打开1");}
public void WindowIconified(WindowEvent we)
{System.out.println("窗口打开2");}
public void WindowDeiconified(WindowEvent we)
{System.out.println("窗口打开3"+we);}
public void WindowClosed(WindowEvent we)
{System.out.println("窗口打开4"+we);}
public void WindowActivated(WindowEvent we)
{System.out.println("窗口打开5"+we);}
public void WindowDeactivated(WindowEvent we)
{System.out.println("窗口打开6"+we);}
//鼠标事件处理方法
public void mousePressed(MouseEvent me)
{System.out.println("mouse Pressed"+me);}
public void mouseReleased(MouseEvent me)
{System.out.println("mouse Released"+me);}
//public void mouseReleased(MouseEvent me)
//{System.out.println("mouse Released"+me);}
public void mouseEntered(MouseEvent me)
{System.out.println("mouse Entered"+me);}
public void mouseExited(MouseEvent me)
{System.out.println("mouse Exit"+me);}
public void mouseClicked(MouseEvent me)
{System.out.println("mouse Click"+me);}
//键盘事件处理 方法
public void keyPressed(KeyEvent ke)
{System.out.println("Key Pressed1"+ke);}
public void keyReleased(KeyEvent ke)
{System.out.println("Key Released2"+ke);}
public void keyTyped(KeyEvent ke)
{System.out.println("Key Released3"+ke);}
//主函数
public static void main(String args[])
{ MultipleEventTester p=new MultipleEventTester();
}
}
---------------------------------------------------------------------------
MultipleEventTester.java:3: MultipleEventTester 不是抽象的,并且未覆盖 java.awt.
event.WindowListener 中的抽象方法 windowDeactivated(java.awt.event.WindowEvent)
public class MultipleEventTester extends Frame implements WindowListener,MouseL
istener,KeyListener{
^
注意:MultipleEventTester.java 使用或覆盖了已过时的 API。
注意:要了解详细信息,请使用 -Xlint:deprecation 重新编译。
1 错误

---------------------------------------------------------------------------------------------
本人初学JAVA 望大家多多指点
搜索更多相关的解决方案: java  awt  public  编译  import  

----------------解决方案--------------------------------------------------------
如提示你没有覆盖继承接口中的所有抽象接方法
import java.awt.*;
import java.awt.event.*;
class MultipleEventTester extends Frame implements

WindowListener,MouseListener,KeyListener{
//定义域
public MultipleEventTester()
//定义构造方法
{
addWindowListener(this);
addMouseListener(this);
addKeyListener(this);
setSize(200,200);
//pack();
show();
}
public void windowDeactivated(WindowEvent we){}
public void windowActivated(WindowEvent we){}
public void windowDeiconified(WindowEvent we){}
public void windowIconified(WindowEvent we){}
public void windowClosed(WindowEvent we){}
public void windowClosing(WindowEvent we){}
public void windowOpened(WindowEvent we){}
//窗口处理事件
public void WindowClosing(WindowEvent we)
{ System.exit(0);}
public void WindowOpened(WindowEvent we)
{ System.out.println("窗口打开1");}
public void WindowIconified(WindowEvent we)
{System.out.println("窗口打开2");}
public void WindowDeiconified(WindowEvent we)
{System.out.println("窗口打开3"+we);}
public void WindowClosed(WindowEvent we)
{System.out.println("窗口打开4"+we);}
public void WindowActivated(WindowEvent we)
{System.out.println("窗口打开5"+we);}
public void WindowDeactivated(WindowEvent we)
{System.out.println("窗口打开6"+we);}
//鼠标事件处理方法
public void mousePressed(MouseEvent me)
{System.out.println("mouse Pressed"+me);}
public void mouseReleased(MouseEvent me)
{System.out.println("mouse Released"+me);}
//public void mouseReleased(MouseEvent me)
//{System.out.println("mouse Released"+me);}
public void mouseEntered(MouseEvent me)
{System.out.println("mouse Entered"+me);}
public void mouseExited(MouseEvent me)
{System.out.println("mouse Exit"+me);}
public void mouseClicked(MouseEvent me)
{System.out.println("mouse Click"+me);}
//键盘事件处理 方法
public void keyPressed(KeyEvent ke)
{System.out.println("Key Pressed1"+ke);}
public void keyReleased(KeyEvent ke)
{System.out.println("Key Released2"+ke);}
public void keyTyped(KeyEvent ke)
{System.out.println("Key Released3"+ke);}
//主函数
public static void main(String args[])
{ MultipleEventTester p=new MultipleEventTester();
}
}
这样就可以了,不过太麻烦
可以继承有一个类他会自动帮你覆盖所有抽象方法
我也才学,这些还不熟悉

----------------解决方案--------------------------------------------------------

import java.awt.*;
import java.awt.event.*;

public class MultipleEventTester extends Frame{

public static void main(String args[]){
MultipleEventTester p=new MultipleEventTester();
}

public MultipleEventTester(){
super("hello");
this.addWindowListener(new MyListener());
addMouseListener(new MyListener());
addKeyListener(new MyListener());
setSize(200,200);
setVisible(true);
show();
}
private class MyListener extends WindowAdapter implements MouseListener,KeyListener{

public void keyPressed(KeyEvent ke)
{
System.out.println("Key Pressed1"+ke);
}

public void keyReleased(KeyEvent ke)
{
System.out.println("Key Released2"+ke);
}

public void keyTyped(KeyEvent ke)
{
System.out.println("Key Released3"+ke);
}

public void mouseClicked(MouseEvent me)
{
System.out.println("mouse Click"+me);
}

public void mouseEntered(MouseEvent me)
{
System.out.println("mouse Entered"+me);
}

public void mouseExited(MouseEvent me)
{
System.out.println("mouse Exit"+me);
}

public void mousePressed(MouseEvent me)
{
System.out.println("mouse Pressed"+me);
}

public void mouseReleased(MouseEvent me)
{
System.out.println("mouse Released"+me);
}

public void windowActivated(WindowEvent we)
{
System.out.println("窗口打开5"+we);
}

public void windowClosed(WindowEvent we)
{
System.out.println("窗口打开4"+we);
}

public void windowClosing(WindowEvent we)
{
MultipleEventTester.this.dispose();
}

public void windowDeactivated(WindowEvent we)
{
System.out.println("窗口打开6"+we);
}
public void windowDeiconified(WindowEvent we)
{
System.out.println("窗口打开3"+we);
}

public void windowIconified(WindowEvent we)
{
System.out.println("窗口打开2");
}

public void windowOpened(WindowEvent we)
{
System.out.println("窗口打开1");
}
}
}

这样就行了,在这给你提点建议!
1) 方法名第一个字母小写,你把本应该覆盖的windowXXX()类的方法都写成了大写WindowXXX()的形式,既便编译过了,在运行时也不会实现关于窗口的各种操作。
2)编写代码一定要养成良好的习惯,多看看书本上那些程序的格式,不要乱写,否则会使别人感到厌烦,更别说给你看程序、改程序了。


----------------解决方案--------------------------------------------------------
三楼说的很对呀!
----------------解决方案--------------------------------------------------------
  相关解决方案