-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathButtonHandler.java
More file actions
33 lines (28 loc) · 872 Bytes
/
ButtonHandler.java
File metadata and controls
33 lines (28 loc) · 872 Bytes
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
package eventbuttonframe;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
*
* @author INAM
*/
public class ButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
JButton clickedButton = (JButton) event.getSource();
JRootPane rootPane = clickedButton.getRootPane();
JFrame frame = (JFrame) rootPane.getParent();
String buttonText = clickedButton.getText();
frame.setTitle("You clicked " + buttonText);
Container C = frame.getContentPane();
if(buttonText.equalsIgnoreCase("ok"))
{
C.setBackground(Color.YELLOW);
}
else if(buttonText.equalsIgnoreCase("CANCEL"))
{
C.setBackground(Color.MAGENTA);
}
}
}