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

AJP Experiment 13

Uploaded by

Piush Gogi
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)
11 views6 pages

AJP Experiment 13

Uploaded by

Piush Gogi
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

EXPERIMENT 13

Title: Write a program to demonstrate the use of WindowAdapter


class .

import java.awt.*;
import java.awt.event.*;

public class Exp13 extends Frame


{
Exp13()
{
setTitle("Window Listener with WindowAdapter");
setBounds(100, 200, 300, 250);
setVisible(true);

addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.out.println("Window Closing");
dispose();
System.exit(0);
}
public void windowOpened(WindowEvent e)
{
System.out.println("Window Opened");
}

public void windowClosed(WindowEvent e)


{
System.out.println("Window Closed");
}

public void windowActivated(WindowEvent e)


{
System.out.println("Window Activated");
}

public void windowDeactivated(WindowEvent e)

Dasari N.S.
{
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)
{
new Exp13();
}
}
Output:

Dasari N.S.
Program 13.1: Write a program to demonstrate the use of anonymous
inner class.

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

public class Exp13_1


{
public static void main(String[] args)
{
JFrame f = new JFrame("Anonymous Inner Class");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(300, 200);
f.setLayout(null);

JButton b = new JButton("Click Me!");


b.setBounds(100, 70, 100, 30);

b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JOptionPane.showMessageDialog(f, "Button Clicked!");
}
});

f.add(b);
f.setVisible(true);
}
}

Dasari N.S.
Output:

Dasari N.S.
Program 13.2: Write a program using MouseMotionAdapter class to
implement only one method mouseDragged().

import java.awt.*;
import java.awt.event.*;

public class Exp13_2


{
Frame f = new Frame();
TextArea ta = new TextArea(5, 15);
Label l = new Label();

Exp13_2()
{
f.setTitle("MouseMotionAdapter Class with mouseDragged
method");
f.setSize(400, 400);
f.setLayout(new FlowLayout());
f.setVisible(true);

f.add(ta);
f.add(l);

ta.addMouseMotionListener(new MouseMotionAdapter()
{
public void mouseDragged(MouseEvent e)
{
l.setText("Mouse Dragged With the help of
MouseMotionAdapter Class");
}
});

f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
f.dispose();
}
});
}

Dasari N.S.
public static void main(String args[])
{
new Exp13_2();
}
}

Output:

Dasari N.S.

You might also like