You are on page 1of 6

Name of Student: Ekambe Ganesh Roll No.

: 53

Experiment No.: 13 DOS:

Exercise
1. Write a program to demonstrate the use of WindowAdapter class

package advancejava;

import java.awt.*;
import java.awt.event.*;
public class pr13ex1 extends Frame implements WindowListener
{
pr13ex1()
{ 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)
{
Name of Student: Ekambe Ganesh Roll No.: 53

Experiment No.: 13 DOS:


System.out.println("Window Deiconified");
}
public static void main(String args[])
{
pr13ex1 WD=new pr13ex1();
}
}

Output
Name of Student: Ekambe Ganesh Roll No.: 53

Experiment No.: 13 DOS:

2. Write a program to demonstrate the use of anonymous inner class.

package advancejava;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class prex2 extends JFrame {
public static void main(String args[]) {
prex2 in=new prex2();
JButton jb=new JButton(" Click Me");
jb.addActionListener((new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.out.println("Oops!!");
}
}
)
);
in.add(jb);
in.pack(); in.setVisible(true);
}

Output
Name of Student: Ekambe Ganesh Roll No.: 53

Experiment No.: 13 DOS:

3. Write a program using MouseMotionAdapter class to implement only one


method mouseDragged() .

package advancejava;
import java.awt.*;
import java.awt.event.*;

public class pr13ex3 implements MouseMotionListener


{
Frame F=new Frame();
TextArea A=new TextArea(5,15);
Label l=new Label();
pr13ex3()
{
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");
}
});
}
Name of Student: Ekambe Ganesh Roll No.: 53

Experiment No.: 13 DOS:

public static void main(String args[])


{
new pr13ex3();
}
@Override
public void mouseDragged(MouseEvent e) {

@Override
public void mouseMoved(MouseEvent e) {

}
}

Output
Name of Student: Ekambe Ganesh Roll No.: 53

Experiment No.: 13 DOS:

You might also like