有人可以告訴我爲什麼mousedragged不被識別在下面的代碼,並可能幫助我解決這個問題?Mousedragged不被識別
public class Hello extends JPanel implements KeyListener, MouseListener, MouseMotionListener{
JPanel panel = new JPanel();
JFrame frame = new JFrame();
public Hello() {
addKeyListener(this);
addMouseListener(this);
addMouseMotionListener(this);
panel.addKeyListener(this);
panel.addMouseListener(this);
frame.addKeyListener(this);
frame.addMouseListener(this);
}
public static void main(String [] args){
Hello play = new Hello();
play.setPanel();
}
public void setPanel(){
panel.setLayout(null);
frame.add(panel);
frame.setLayout(null);
panel.setBounds(0,0,100,100);
frame.setVisible(true);
panel.setVisible(true);
panel.setFocusable(true);
frame.setSize(100,100);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void keyTyped(KeyEvent arg0){
System.out.println("keytyped");
}
public void keyPressed(KeyEvent arg0){
System.out.print("keypressed");
}
public void keyReleased(KeyEvent arg0){
System.out.println("keyreleased");
}
public void mousePressed(MouseEvent arg0){
System.out.println("mousepressed");
}
public void mouseReleased(MouseEvent arg0){
System.out.println("mousereleased");
}
public void mouseClicked(MouseEvent arg0){
System.out.println("mouseclicked");
}
public void mouseEntered(MouseEvent arg0){
System.out.println("mousenentered");
}
public void mouseExited(MouseEvent arg0){
System.out.println("mouseexited");
}
public void mouseDragged(MouseEvent arg0){
System.out.println("mousedragged");
}
你能解決你的問題,所以我們可以在正確的代碼文本中看到類聲明和構造函數嗎? –