0% found this document useful (0 votes)
13 views4 pages

Assignment: 4 Name: Vaibhav Tale ROLL NO: 12920

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)
13 views4 pages

Assignment: 4 Name: Vaibhav Tale ROLL NO: 12920

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

Assignment : 4

NAME : VAIBHAV TALE

ROLL NO : 12920

Write a java program to design GUI screen shown in the below image attached using the Swing
components

package ass;

import javax.swing.*;

import java.awt.*;

public class Calculator

JFrame frame;

JLabel label = new JLabel();

JTextField textField = new JTextField();

JButton buttonZero = new JButton("0");

JButton buttonOne = new JButton("1");

JButton buttonTwo = new JButton("2");

JButton buttonThree = new JButton("3");

JButton buttonFour = new JButton("4");

JButton buttonFive = new JButton("5");

JButton buttonSix = new JButton("6");

JButton buttonSeven = new JButton("7");

JButton buttonEight = new JButton("8");

JButton buttonNine = new JButton("9");

JButton buttonDot = new JButton(".");

JButton buttonEqual = new JButton("=");

JButton buttonMul = new JButton("x");

JButton buttonDiv = new JButton("/");


JButton buttonPlus = new JButton("+");

JButton buttonMinus = new JButton("-");

Calculator()

prepareGUI();

addComponents();

public void prepareGUI()

frame=new JFrame();

frame.setTitle("Calculator");

frame.setSize(280,380);

frame.getContentPane().setLayout(null);

frame.getContentPane().setBackground(Color.white);

frame.setResizable(false);

frame.setLocationRelativeTo(null);

frame.setVisible(true);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

public void addComponents()

label.setBounds(250, 0, 50, 50);

label.setForeground(Color.white);

frame.add(label);

textField.setBounds(20, 35, 220, 25);

textField.setFont(new Font("Arial", Font.BOLD, 20));

textField.setEditable(false);

textField.setHorizontalAlignment(SwingConstants.RIGHT);
frame.add(textField);

buttonOne.setBounds(20, 90, 40, 40);

buttonOne.setFont(new Font("Arial", Font.BOLD, 12));

frame.add(buttonOne);

buttonTwo.setBounds(80, 90, 40, 40);

buttonTwo.setFont(new Font("Arial", Font.BOLD, 12));

frame.add(buttonTwo);

buttonThree.setBounds(140, 90, 40, 40);

buttonThree.setFont(new Font("Arial", Font.BOLD, 12));

frame.add(buttonThree);

buttonFour.setBounds(20, 150, 40, 40);

buttonFour.setFont(new Font("Arial", Font.BOLD, 12));

frame.add(buttonFour);

buttonFive.setBounds(80, 150, 40, 40);

buttonFive.setFont(new Font("Arial", Font.BOLD, 12));

frame.add(buttonFive);

buttonSix.setBounds(140, 150, 40, 40);

buttonSix.setFont(new Font("Arial", Font.BOLD, 12));

frame.add(buttonSix);

buttonSeven.setBounds(20, 210, 40, 40);

buttonSeven.setFont(new Font("Arial", Font.BOLD, 12));

frame.add(buttonSeven);

buttonEight.setBounds(80, 210, 40, 40);

buttonEight.setFont(new Font("Arial", Font.BOLD, 12));

frame.add(buttonEight);

buttonNine.setBounds(140, 210, 40, 40);

buttonNine.setFont(new Font("Arial", Font.BOLD, 12));


frame.add(buttonNine);

buttonZero.setBounds(20, 270, 40, 40);

buttonZero.setFont(new Font("Arial", Font.BOLD, 12));

frame.add(buttonZero);

buttonDot.setBounds(80, 270, 40, 40);

buttonDot.setFont(new Font("Arial", Font.BOLD, 12));

frame.add(buttonDot);

buttonEqual.setBounds(140, 270, 40, 40);

buttonEqual.setFont(new Font("Arial", Font.BOLD, 11));

frame.add(buttonEqual);

buttonDiv.setBounds(200, 270, 40, 40);

buttonDiv.setFont(new Font("Arial", Font.BOLD, 20));

frame.add(buttonDiv);

buttonMul.setBounds(200, 210, 40, 40);

buttonMul.setFont(new Font("Arial", Font.BOLD, 12));

frame.add(buttonMul);

buttonMinus.setBounds(200, 150, 40, 40);

buttonMinus.setFont(new Font("Arial", Font.BOLD, 20));

frame.add(buttonMinus);

buttonPlus.setBounds(200, 90, 40, 40);

buttonPlus.setFont(new Font("Arial", Font.BOLD, 11));

frame.add(buttonPlus);

public static void main(String[] args)

new Calculator();

You might also like