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

Code

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

Code

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

1.

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

class WindowAdapterDemo extends WindowAdapter


{
Frame f;
Label l;
WindowAdapterDemo()
{
f = new Frame("TYIF 4. Atharva Wadekar");
f.setSize(500,500);
f.setLayout(new FlowLayout());

l = new Label("WindowAdapter");
f.add(l);

f.addWindowListener(this);
f.setVisible(true);
}
public void windowClosing(WindowEvent e)
{
l.setText("WindowClosing");
}
public void windowActivated(WindowEvent e)
{
l.setText("WindowActivated");
}
public static void main(String[] args)
{
new WindowAdapterDemo();
}
}
Output
2. Code

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

class AnonymousClass extends Frame


{
AnonymousClass()
{
setSize(400,400);
setTitle("TYIF 4. Atharva Wadekar");

add(new Label("Close the Window"));

addWindowListener(new WindowAdapter(){

@Override
public void windowClosing(WindowEvent e)
{
dispose();
}

});

setVisible(true);
}

public static void main(String[] args)


{
new AnonymousClass();
}
}
Output
3. Code
import java.awt.*;
import java.awt.event.*;

class DragDemo extends Frame


{
Label l;
DragDemo()
{
setSize(400,400);
setTitle("TYIF 4. Atharva Wadekar");
setLayout(new FlowLayout());

l = new Label("X: Y: ");


l.setPreferredSize(new Dimension(100,30));
add(l);

addMouseMotionListener(new MouseMotionAdapter(){

public void mouseDragged(MouseEvent e)


{
Graphics g = getGraphics();
l.setText("X: " + e.getX() + " Y: " + e.getY());
g.fillOval(e.getX(),e.getY(),3,3);
}
});

setVisible(true);
}
public static void main(String[] args)
{
new DragDemo();
}
}
Output

You might also like