-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuButton.java
More file actions
42 lines (37 loc) · 1.2 KB
/
Copy pathMenuButton.java
File metadata and controls
42 lines (37 loc) · 1.2 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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
* Project 2: MenuButton class that extends JButton.
* Stores attributes of id and parkedCar,
* getter methods for its attributes, and methods to add and remove a car.
*
* @author Abdurrahman Faqih 104675143
* @version 0.1 9 May 2024
*/
public class MenuButton extends JButton {
public MenuButton(String text, ActionListener actionListener) {
super(text);
// Set view settings
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
setBackground(new Color(62, 61, 69));
setForeground(Color.white);
setOpaque(true);
setBorderPainted(false);
setFocusPainted(false);
// Hover effect
addMouseListener(new MouseAdapter() {
JButton button;
@Override
public void mouseEntered(MouseEvent e) {
button = (JButton) e.getSource();
button.setBackground(new Color(79, 79, 82));
}
@Override
public void mouseExited(MouseEvent e) {
button.setBackground(new Color(62, 61, 69));
}
});
addActionListener(actionListener);
}
}