Program - 11: Aim: Write A Program To Create A Simple Calculator Using Awt. Code
Program - 11: Aim: Write A Program To Create A Simple Calculator Using Awt. Code
Calculator() {
tf = new TextField();
tf.setBounds(50, 50, 300,
50);
b1 = new Button("1");
b1.setBounds(50, 120, 50,
50); b2 = new Button("2");
b2.setBounds(120, 120, 50,
50); b3 = new Button("3");
b3.setBounds(190, 120, 50,
50); bAdd = new Button("+");
bAdd.setBounds(260, 120, 50, 50);
b4 = new Button("4");
b4.setBounds(50, 190, 50,
50); b5 = new Button("5");
b5.setBounds(120, 190, 50,
50); b6 = new Button("6");
b6.setBounds(190, 190, 50,
50); bSub = new Button("-");
bSub.setBounds(260, 190, 50, 50);
b7 = new Button("7");
b7.setBounds(50, 260, 50,
50); b8 = new Button("8");
b8.setBounds(120, 260, 50,
50); b9 = new Button("9");
b9.setBounds(190, 260, 50,
50); bMul = new Button("*");
bMul.setBounds(260, 260, 50, 50);
b0 = new Button("0");
b0.setBounds(50, 330, 50, 50);
bEqual = new Button("=");
bEqual.setBounds(120, 330, 50,
50); bClear = new Button("C");
bClear.setBounds(190, 330, 50,
50);
bDiv = new Button("/");
bDiv.setBounds(260, 330, 50,
50);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
b0.addActionListener(this);
bAdd.addActionListener(this);
bSub.addActionListener(this);
bMul.addActionListener(this);
bDiv.addActionListener(this);
bEqual.addActionListener(this
);
bClear.addActionListener(this
);
add(tf);
add(b1);
add(b2);
add(b3);
add(bAdd);
add(b4);
add(b5);
add(b6);
add(bSub);
add(b7);
add(b8);
add(b9);
add(bMul);
add(b0);
add(bEqual);
add(bClear);
add(bDiv);
setSize(400, 400);
setLayout(null);
setVisible(true);
}
Output:
Program – 10
Aim : Write a program to show multithreaded producer and consumer
application.
Code:
import java.util.LinkedList;
class ProducerConsumer {
LinkedList<Integer> buffer = new
LinkedList<>(); int capacity = 2;
System.out.println("Producer produced-" +
value); buffer.add(value++);
notify();
Thread.sleep(1000
);
}
}
}
producerThread.start(
);
consumerThread.start(
);
}
}
Output: