Experiment - 7: Source Code
Experiment - 7: Source Code
Experiment - 7: Source Code
SOURCE CODE:
public class ProducerConsumer
{
public static void main(String[] args)
{
Shop c = new Shop();
Producer p1 = new Producer(c, 1);
Consumer c1 = new Consumer(c, 1);
p1.start();
c1.start();
}
}
class Shop
{
private int materials;
private boolean available = false;
public synchronized int get()
{
while (available == false)
{
try
{
wait();
}
catch (InterruptedException ie)
{
}
}
available = false;
notifyAll();
return materials;
}
public synchronized void put(int value)
{
while (available == true)
{
try
{
wait();
}
catch (InterruptedException ie)
{
ie.printStackTrace();
}
}
materials = value;
available = true;
notifyAll();
}
}
OUTPUT:
EXPERIMENT – 8
SOURCE CODE:
import java.applet.Applet;
import java.awt.Graphics;
public class AppletLifeCycleDemo extends Applet {
String msg = "";
public void init() {
msg += "init( ) -> ";
}
public void start() {
msg += "start( ) -> ";
}
public void paint(Graphics g) {
msg += "paint( )";
g.drawString(msg, 20, 20);
}
public void stop() {
msg += " -> stop( )";
}
public void destroy() {
msg += "-> destroy( )";
}
}
OUTPUT:
EXPERIMENT– 9
SOURCE CODE:
import java.applet.Applet;
import java.awt.*;
import java.util.*;
public class analogClock extends Applet
{
public void init()
{
this.setSize(new Dimension(800, 400));
setBackground(new Color(50, 50, 50));
new Thread() {
public void run()
{
while (true) {
repaint();
delayAnimation();
}
}
}.start();
}
OUTPUT: