[go: up one dir, main page]

0% found this document useful (0 votes)
27 views6 pages

Ajp 13

This document contains code snippets and output for 3 exercises demonstrating the use of different adapter classes in Java - WindowAdapter, anonymous inner classes, and MouseMotionAdapter. The first exercise shows how to use WindowAdapter to listen for window events. The second uses an anonymous inner class to add an action listener to a button. The third implements mouseDragged using MouseMotionAdapter. For each exercise, the code is provided along with an area for output.

Uploaded by

Ganesh Ekambe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views6 pages

Ajp 13

This document contains code snippets and output for 3 exercises demonstrating the use of different adapter classes in Java - WindowAdapter, anonymous inner classes, and MouseMotionAdapter. The first exercise shows how to use WindowAdapter to listen for window events. The second uses an anonymous inner class to add an action listener to a button. The third implements mouseDragged using MouseMotionAdapter. For each exercise, the code is provided along with an area for output.

Uploaded by

Ganesh Ekambe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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