Prac13 (Use of WindowAdapter Class)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

XIII. Exercise.

1.Write a Program To Demonstrate The Use Of WindowAdapter


Class.

Code :- import java.awt.*;

import java.awt.event.*;
public class WindowExDemo extends Frame implements
WindowListener{
WindowExDemo(){
setTitle("Window Listener");
setBounds(100,200,200,250);
setVisible(true);
addWindowListener(this);
}
public void windowClosing(WindowEvent e){
System.out.println(("Window Closing"));
dispose(); System.exit(0);
}
public void windowOpened(WindowEvent e){
System.out.println("Window Open");
}
public void windowClosed(WindowEvent e){
System.out.println("Window Close");
}
public void windowActivated(WindowEvent e){
System.out.println("Window Activated");
}
public void windowDeactivated(WindowEvent e){
System.out.println("Window Deactivated");
}
public void windowIconified(WindowEvent e){
System.out.println("Window Iconified");
}
public void windowDeiconified(WindowEvent e){
System.out.println("Window Deiconified");
}
public static void main(String args[]){
WindowExDemo WD=new WindowExDemo();
}
}
Output :-

2. Write A Program To Demonstrate The Use Of Anonymous Inner


Class. Code :-

import javax.swing.*;
import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

public class Innerclass1 extends JFrame {

public static void main(String args[]) {


Innerclass1 in=new Innerclass1();

JButton jb=new JButton("Don't Click Me");

jb.addActionListener((new ActionListener() {

public void actionPerformed(ActionEvent e) {

System.out.println("Oops!!");

} }));
in.add(jb);

in.pack();
in.setVisible(true);

} }

Output :-

3. Write a Program Using MouseMotionAdapter Class To Implement Only


One Method mouseDragged.
Code :-
import java.awt.*;
import java.awt.event.MouseMotionListener;
import java.awt.event.*;
public class MouseMotionEx implements MouseMotionListener {
Frame F=new Frame();
TextArea A=new TextArea(5,15);
Label l=new Label();
MouseMotionEx() {
F.setSize(400,400);
F.setLayout(new FlowLayout());
F.setVisible(true);
F.add(A);
F.add(l);
A.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
l.setText("Mouse Dragged With the help of MouseMotion Adapter Class");
} }); }
public static void main(String args[]) {
new MouseMotionEx(); }
Output :-

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy