-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHandlerClass.java
More file actions
45 lines (43 loc) · 1.58 KB
/
HandlerClass.java
File metadata and controls
45 lines (43 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/********************************************************************************************************************
Author: Chad Cromwell
Date: December 1st, 2017
Assignment: 2
Program: HandlerClass.java
Description: A class that handles the user's mouse input
********************************************************************************************************************/
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class HandlerClass implements MouseListener, MouseMotionListener {
int x; //Holds x position of the mouse
int y; //Holds y position of the mouse
boolean click; //Whether or not the user has clicked
@Override
//What happens when the mouse is clicked
public void mouseClicked(MouseEvent e) {
}
//What happens when the mouse is pressed
public void mousePressed(MouseEvent e) {
click = true; //The user is clicking
}
//What happens when the mouse is released
public void mouseReleased(MouseEvent e) {
click = false; //The user is no longer clicking
}
//What happens when the mouse enters the frame
public void mouseEntered(MouseEvent e) {
}
//What happens when the mouse exits the frame
public void mouseExited(MouseEvent e) {
}
//What happens when the mouse is moved within the frame
public void mouseMoved(MouseEvent e) {
x = e.getX(); //Capture x position of the mouse
y = e.getY(); //Capture y position of the mouse
}
//What happens when the mouse is pressed and moved (dragging)
public void mouseDragged(MouseEvent e) {
x = e.getX(); //Capture x position of the mouse
y = e.getY(); //Capture y position of the mouse
}
}