-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ8(Practical).java
More file actions
50 lines (48 loc) · 1.14 KB
/
Q8(Practical).java
File metadata and controls
50 lines (48 loc) · 1.14 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
46
47
48
49
50
8) Write a program to create a frame using AWT. Implement mouseClicked(),
mouseEntered() and mouseExited() events such that:
a) Size of the frame should be tripled when mouse enters it.
b) Frame should reduce to its original size when mouse is clicked in it.
c) Close the frame when mouse exits it.
/**** Main.java ****/
import java.awt.*;
import java.awt.event.*;
public class Main extends Frame implements MouseListener {
Label l;
Main() {
super("AWT Frame");
l = new Label();
l.setBounds(25, 60, 250, 30);
l.setAlignment(Label.CENTER);
this.add(l);
this.setSize(300, 300);
this.setLayout(null);
this.setVisible(true);
this.addMouseListener(this);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
}
});
}
public static void main(String[] args) {
new Main();
}
@Override
public void mouseClicked(MouseEvent e) {
l.setText("Mouse Clicked");
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
l.setText("Mouse Entered");
}
@Override
public void mouseExited(MouseEvent e) {
l.setText("Mouse Exited");
}
}