Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 69702fd

Browse files
some more code
1 parent d00044d commit 69702fd

File tree

7 files changed

+119
-51
lines changed

7 files changed

+119
-51
lines changed

‎.idea/workspace.xml

Lines changed: 48 additions & 51 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
946 Bytes
Binary file not shown.
1.27 KB
Binary file not shown.
1.46 KB
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package com.example.hello_world_package;
2+
3+
import javax.swing.*;
4+
import java.awt.*;
5+
import java.awt.event.ActionEvent;
6+
import java.awt.event.ActionListener;
7+
import java.awt.event.MouseEvent;
8+
import java.awt.event.MouseListener;
9+
10+
public class Event_handling_in_java {
11+
public static void main(String[] args) {
12+
JFrame frame = new JFrame("JFRAME");
13+
Panel panel = new Panel();
14+
//CREATE A SOURCE OF EVENT
15+
JButton jButton = new JButton("CLICK ME");
16+
panel.add(jButton);
17+
frame.add(panel);
18+
frame.setSize(400,400);
19+
frame.setVisible(true);
20+
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
21+
22+
23+
24+
//Implement a Listener
25+
26+
ActionListener actionListener = new ActionListener() {
27+
@Override
28+
public void actionPerformed(ActionEvent actionEvent) {
29+
jButton.setBackground(Color.RED);
30+
}
31+
};
32+
33+
//Another Example of Listener
34+
35+
MouseListener mouseListener = new MouseListener() {
36+
@Override
37+
public void mouseClicked(MouseEvent mouseEvent) {
38+
39+
}
40+
41+
@Override
42+
public void mousePressed(MouseEvent mouseEvent) {
43+
44+
}
45+
46+
@Override
47+
public void mouseReleased(MouseEvent mouseEvent) {
48+
49+
}
50+
51+
@Override
52+
public void mouseEntered(MouseEvent mouseEvent) {
53+
jButton.setBackground(Color.BLUE);
54+
55+
}
56+
57+
@Override
58+
public void mouseExited(MouseEvent mouseEvent) {
59+
jButton.setBackground(Color.GREEN);
60+
61+
}
62+
};
63+
64+
65+
//register the actionListener to an event source
66+
jButton.addActionListener(actionListener);
67+
jButton.addMouseListener(mouseListener);
68+
69+
70+
}
71+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /