저는 자바에서는 이것이 가능하지 않다고 믿습니다. 글쎄 그것은 JNI를 통해 가능하지만 그것은 고통의 세계입니다. 이벤트와 이렇게
는
어렵지 않다, 그리고 응용 프로그램의 나머지 부분과 더 나은 통합됩니다. 솔직해야 다른 기간의 시간이 지나면 (예 : 변경 붓 모드로) 다른 일을하기 위해이 수정
import javax.swing.*;
import java.awt.event.*;
public class Test {
public static void main(String[] args) {
JFrame frame = new JFrame();
final JLabel label = new JLabel("Click on me and hold the mouse button down");
label.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
frame.getContentPane().add(label);
label.addMouseListener(new TimingMouseAdapter());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
private static class TimingMouseAdapter extends MouseAdapter {
private Timer timer;
public void mousePressed(MouseEvent e) {
timer = new Timer(100, new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Mouse still pressed...");
}
});
timer.start();
}
public void mouseReleased(MouseEvent e) {
if (timer != null) {
timer.stop();
}
}
}
}
다음은 마우스 버튼을 누르고있는 동안 콘솔에 매 100 밀리 작성의 예입니다.
죄송하지만 ... 왜? –