-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathClickable_JLabel_JavaTutorial.java
More file actions
43 lines (38 loc) · 1.28 KB
/
Copy pathClickable_JLabel_JavaTutorial.java
File metadata and controls
43 lines (38 loc) · 1.28 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
import java.awt.BorderLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
/**
*
*@author Vincent
*/
public class clickableJLabel_JavaTutorial {
public static void main(String[] args) {
JFrame window = new JFrame("JLabel Button");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel buttonLabel = new JLabel();
buttonLabel.setText("<html><h1>Click Me!</h1></html");
JPanel panel_1 = new JPanel();
buttonLabel.addMouseListener(new MouseListener() {
public void mouseReleased(MouseEvent e) {
buttonLabel.setText("<html><h1>Thanks!</h1></html");
}
public void mousePressed(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseClicked(MouseEvent e) {
buttonLabel.setText("<html><h1>Thanks!</h1></html");
}
});
panel_1.add(buttonLabel);
window.add(BorderLayout.NORTH, panel_1);
window.setSize(500, 500);
window.setVisible(true);
window.setLocationRelativeTo(null);
}
}