0% found this document useful (0 votes)
15 views7 pages

Exp 13

java code

Uploaded by

giripreetam566
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)
15 views7 pages

Exp 13

java code

Uploaded by

giripreetam566
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/ 7

X.

Q.1)
import java.awt.*;
import
java.awt.event.*;
public class WindowDemo {
Frame f;

public WindowDemo() {
f = new Frame("Window Adapter Example");

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

f.setSize(400,
400);
f.setLayout(null);

// Make the frame visible


f.setVisible(true);
}

public static void main(String[]


args) { new WindowDemo();
}
}

Output :
XIII .
Q.1)
import java.awt.*;
import
import java.net.InetAddress;
import
java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class WindowAdapterDemo1
{ public static void main(String[]
args) {
Frame frame = new Frame("Window Adapter Example");
String currentDateTime = new SimpleDateFormat("yyyy-MM-dd
HH:mm:ss").format(new Date());
String ipAddress = "Unknown";
String hostname = " Performed by Sumeet Sawant & Ved
Jadhav"; try {
InetAddress inetAddress = InetAddress.getLocalHost();
ipAddress = inetAddress.getHostAddress();
} catch
(UnknownHostException e) {
e.printStackTrace();
}
frame.setTitle("Window Adapter Example - " + currentDateTime + " - IP: " +
ipAddress + " - Host: " + hostname);
frame.addWindowListener(new
WindowAdapter() { public void
windowClosing(WindowEvent e) {
frame.dispose();
}
});
frame.setSize(400, 400);
frame.setLayout(null);
frame.setVisible(true);
}
}

Output :
Q.2)
import java.awt.*;
import
import
java.util.Date;
import java.net.*;
public class ButtonClickDemo {
public static void main(String[]
args) { InetAddress inet = null;
String ipStr = "IP not
found"; try {
inet =
InetAddress.getLocalHost(); ipStr
= inet.getHostAddress();
} catch (Exception
e) {
e.printStackTrace
();
}
String date = new Date().toString();
Frame frame = new Frame("Code by Sumeet Sawant and Ved Jadhav on " + ipStr
+ " " + date);
Button button = new Button("Click Me!");
button.addActionListener(new
ActionListener() {
@Override
public void actionPerformed(ActionEvent
e) { System.out.println("Button was
clicked!");
}
});
frame.add(button);
frame.setSize(300, 200);
frame.setLayout(new
FlowLayout());
frame.setVisible(true);
frame.addWindowListener(new
WindowAdapter() { public void
windowClosing(WindowEvent e) {
frame.dispose();
}
});
}}

Output :
Q.3)
import java.awt.*;
import
Q.4)
import java.awt.*;
import
import
java.net.InetAddress;
import java.util.Date;

public class MouseDragDemo extends

Frame { int x = 0;
int y = 0;

public MouseDragDemo() {
InetAddress inet = null;
String ipStr = "IP not
found"; try {
inet =
InetAddress.getLocalHost(); ipStr
= inet.getHostAddress();
} catch (Exception
e) {
e.printStackTrace
();
}
String date = new Date().toString();
super.setTitle("Code by Sumeet Sawant and Ved Jadhav on " + ipStr + " " + date);

addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void
mouseDragged(MouseEvent e) { x =
e.getX();
y=
e.getY();
repaint();
}
});

setSize(400,
400);
setVisible(true);
addWindowListener(new WindowAdapter()
{ public void
windowClosing(WindowEvent e) {
dispose();
}
});
}
Q.5)
import java.awt.*;
import
@Override
public void paint(Graphics g) {
g.setColor(Color.RED);
g.fillOval(x - 15, y - 15, 30,
30);
}
public static void main(String[]
args) { new MouseDragDemo();
}
}

Output :

You might also like