import [Link].
*;
import [Link].*;
public class WindowAdapterExample extends Frame {
public WindowAdapterExample() {
// Set the title of the Frame
setTitle("Window Adapter Example");
// Set the size of the Frame
setSize(400, 300);
// Add a WindowAdapter to handle window events
addWindowListener(new WindowAdapter() {
// Override the windowClosing method to handle the close event
public void windowClosing(WindowEvent we) {
// Display a message when the window is about to close
[Link]("Window is closing...");
// Close the window and terminate the program
[Link](0);
});
// Set the layout and add a label for demonstration
setLayout(new FlowLayout());
Label label = new Label("Close the window to trigger the WindowAdapter.");
add(label);
// Make the Frame visible
setVisible(true);
}
public static void main(String[] args) {
// Create an instance of the WindowAdapterExample class
new WindowAdapterExample();
import [Link].*;
import [Link].*;
public class AnonymousInnerClassExample {
public static void main(String[] args) {
// Create a Frame
Frame frame = new Frame("Anonymous Inner Class Example");
// Set frame layout and size
[Link](new FlowLayout());
[Link](300, 200);
// Create a Button
Button button = new Button("Click Me!");
// Add ActionListener to the button using an anonymous inner class
[Link](new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Code to handle button click
[Link]("Button clicked!");
});
// Add button to the frame
[Link](button);
// Add a WindowListener using an anonymous inner class to handle window closing
[Link](new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
[Link]("Window closing...");
[Link](0); // Close the application
});
// Make the frame visible
[Link](true);
}
import [Link].*;
import [Link].*;
public class MouseMotionAdapterExample extends Frame {
// Label to display coordinates
Label coordinatesLabel;
public MouseMotionAdapterExample() {
// Set the title of the Frame
setTitle("Mouse Drag Example");
// Set the size of the Frame
setSize(400, 300);
// Set layout to FlowLayout
setLayout(new FlowLayout());
// Create a label to display the mouse coordinates
coordinatesLabel = new Label("Drag the mouse to see the coordinates");
add(coordinatesLabel);
// Add MouseMotionAdapter to handle the mouseDragged event
addMouseMotionListener(new MouseMotionAdapter() {
// Override the mouseDragged method
@Override
public void mouseDragged(MouseEvent e) {
// Get the X and Y coordinates of the mouse drag event
int x = [Link]();
int y = [Link]();
// Display the coordinates in the label
[Link]("Mouse dragged at X: " + x + ", Y: " + y);
});
// Add WindowListener to handle window closing
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
[Link](0); // Close the window
});
// Make the frame visible
setVisible(true);
public static void main(String[] args) {
// Create an instance of MouseMotionAdapterExample class
new MouseMotionAdapterExample();