0% found this document useful (0 votes)
4 views2 pages

Ajp Exp 3 Print

The document contains Java code for a simple calculator GUI and additional exercises demonstrating the use of AWT components. It includes classes for creating a calculator interface with buttons and a display, as well as examples of layout management using GridLayout and BorderLayout. The code is structured with main methods to instantiate the GUI components.

Uploaded by

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

Ajp Exp 3 Print

The document contains Java code for a simple calculator GUI and additional exercises demonstrating the use of AWT components. It includes classes for creating a calculator interface with buttons and a display, as well as examples of layout management using GridLayout and BorderLayout. The code is structured with main methods to instantiate the GUI components.

Uploaded by

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

Simple Calculator GUI X.

Program Code:
import java.awt.*; 1.
public class Calculator extends Frame { import java.awt.*;
TextField display; import java.net.InetAddress;
Button[] buttons; import java.util.Date;
String[] buttonLabels = {"7", "8", "9", public class Expt3_1 {
"/","4", "5", "6", "*","1", "2", "3", "-","C", "0", Frame f;
"=", "+"}; Expt3_1() {
public Calculator() { f = new Frame();
setTitle("Simple Calculator"); f.setLayout(new BorderLayout());
setSize(300, 400); Panel ip = new Panel();
setLayout(new BorderLayout()); ip.setLayout(new GridLayout(4, 1));
display = new TextField(); ip.add(n1);
display.setEditable(false); ip.add(n);
display.setFont(new Font("Arial", ip.add(d);
Font.BOLD, 40)); ip.add(l);
add(display, BorderLayout.NORTH); Panel bp = new Panel();
Panel buttonPanel = new Panel(); bp.setLayout(new GridLayout(5, 5));
buttonPanel.setLayout(new
GridLayout(4, 4)); for (Integer i=1; i<=25; i++) {
buttons = new Button[16]; Button b = new Button(i.toString());
for (int i = 0; i < 16; i++) { bp.add(b);
buttons[i] = new }
Button(buttonLabels[i]); f.add(ip, BorderLayout.CENTER);
buttonPanel.add(buttons[i]); f.add(bp, BorderLayout.NORTH);
}
add(buttonPanel, f.setSize(300, 300);
BorderLayout.CENTER); f.setVisible(true);
} }
public static void main(String[] args) { public static void main(String[] args) {
Calculator calculator = new new Expt3_1();
Calculator(); }
calculator.setVisible(true); }
}}
2.
import java.awt.*; XIII Exercise
import java.net.InetAddress; 1.
import java.util.Date; import java.awt.*;
public class Expt3_3 {
public class Expt3_2 Frame f;
{ Expt3_3() {
Frame fObj; f = new Frame();
Button b1, b2, b3, b4, b5, b6, b7, b8, b9; f.setLayout(new GridLayout(3, 3 ,10,
Expt3_2() { 10));
fObj = new Frame ("Expt3_2"); for (Integer i=1; i<=5; i++) {
Panel ip = new Panel(); Button b = new Button("Button
ip.setLayout(new GridLayout(4, 1)); "+i.toString());
ip.add(n1); f.add(b);
ip.add(n); }
ip.add(d); f.setSize(600, 200);
ip.add(l); f.setVisible(true);
for(Integer i=0;i<=9;i++){ }
Button b = new Button(i.toString()); public static void main(String[] args) {
fObj.add(b); new Expt3_3();
} }
}
fObj.setLayout(new FlowLayout()); ___________________________________
fObj.setSize(300,400); 2.
fObj.setVisible(true); import java.awt.*;
fObj.add(n1); class BoderLayoutDemo extends Frame {
fObj.add(n); BoderLayoutDemo()
fObj.add(d); {
fObj.add(l); Panel pa = new Panel();
pa.setLayout(new BorderLayout());
} pa.add(new Button("North"),
public static void main (String args[]) BorderLayout.NORTH);
{ pa.add(new Button("South"),
new Expt3_2(); BorderLayout.SOUTH);
} pa.add(new Button("East"),
} BorderLayout.EAST);
pa.add(new Button("West"),
BorderLayout.WEST);
pa.add(new Button("Center"),
BorderLayout.CENTER);
add(pa);
setSize(300, 300);
setVisible(true);
}
}
class MainFrame {
public static void main(String[] args)
{
new BoderLayoutDemo(); }}

You might also like