public class MouseDetailsFrame extends JFrame {
private String details;
private JLabel statusbar;
public MouseDetailsFrame(){
super("MouseFrame");
statusbar= new JLabel("Click The Mouse");
add(statusbar, BorderLayout.SOUTH);
addMouseListener(new MouseClickHandler());
}
private class MouseClickHandler extends MouseAdapter{
public void MouseClicked(MouseEvent event){
int xPos= event.getX();// has no use anywhere, i wonder why that is
int yPos= event.getY();// same
details= String.format(" clicked %d times:", event.getClickCount());
if (event.isMetaDown())
details = String.format(" clicked %d times:"+"with right mouse", event.getClickCount());
else if(event.isAltDown())
details=String.format(" clicked %d times:"+"with middle mouse", event.getClickCount());
else
details =String.format(" clicked %d times:"+ "with left mouse", event.getClickCount());
statusbar.setText(details);
}
}
}
//当我通过主字符串运行时没有任何反应。一个窗口只显示状态栏没有显示我点击了多少时间,或者我用鼠标左键或右键单击了。请给我一个提示,我想自己做。
答案 0 :(得分:2)
在MouseClicked
方法中添加@Override注释 - 您注意到了什么?
此是@Override
备件中的一种情况你是悲伤的。
去检查mouseClicked
方法的javadoc:你注意到拼写的区别吗?