0
您好,我正在用Java中的mousewheel事件進行練習,因此當鼠標滾輪移動時,我製作了一個長大的蝦仁。現在我還想在鼠標指針旁邊的屏幕上顯示「MousWheel」的大小。任何人都可以告訴我一個如何做到這一點的例子嗎?在屏幕上獲得鼠標滾輪的大小
這就是我現在得到的。
public class MouseWheelPanel extends JPanel implements MouseWheelListener {
private int grootte = 50;
public MouseWheelPanel() {
this.addMouseWheelListener(this);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.YELLOW);
g.fillOval(10, 10, grootte, grootte);
}
public void mouseWheelMoved(MouseWheelEvent e) {
// TODO Auto-generated method stub
String
grootte += e.getWheelRotation();
repaint();
}
}
'g.drawString(arguments)'只需在Graphics api中查找該方法即可。 – thatidiotguy