Você está na página 1de 4

X.1.

code:
import java.awt.*;
import java.awt.event.*;

public class prg1 {


Frame f;
prg1()
{
f = new Frame("window adapter");
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
f.dispose();
}
});
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
public static void main(String args[])
{
new prg1();
}

}
OUTPUT:
The frame is closed when user is closed or clicked on closed button of frame.
XIII.1.
CODE:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class prg
{

Label l1;
prg()
{
Frame f=new Frame();
f.setSize(300,300);
f.setVisible(true);
f.setLayout(new FlowLayout());
l1=new Label("Click Me");
f.add(l1);
f.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
l1.setText("Clicked event using Adapter Class");
}
}
);

public static void main(String arg[])


{
prg p=new prg();
}

}
OUTPUT:
XIII.2.
CODE:
interface Age
{
int x = 21;
void getAge();
}
class AnonymousDemo
{
public static void main(String[] args)
{
// Myclass is implementation class of Age interface
MyClass obj=new MyClass();

// calling getage() method implemented at Myclass


obj.getAge();
}
}

// Myclass implement the methods of Age Interface


class MyClass implements Age
{
@Override
public void getAge()
{
// printing the age
System.out.print("Age is "+x);
}
}

OUTPUT:
XIII.3.
CODE:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class prg
{

Label l1;
prg()
{
Frame f=new Frame();
f.setSize(300,300);
f.setVisible(true);
f.setLayout(new FlowLayout());
l1=new Label("Click Me");

f.add(l1);
f.addMouseMotionListener(new MouseMotionAdapter()
{
public void mouseDragged(MouseEvent e)
{
l1.setText(" dragged");
}
}
);

public static void main(String arg[])


{
prg p=new prg();
}

Você também pode gostar