Calculator Assignment
Calculator Assignment
Class: BS(SE).
Instructor: Dr.M.Awais.
Import javax.swing.*;
Import java.awt.*;
Import java.awt.event.ActionEvent;
Import java.awt.event.ActionListener;
// Constructor
Public ScientificCalculator() {
// Set up the frame
setTitle(“Scientific Calculator”);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400, 400);
setLayout(new BorderLayout());
// Initialize components
Display = new JTextField();
Buttons = new JButton[20];
// Create buttons
String[] buttonLabels = {“7”, “8”, “9”, “/”, “4”, “5”, “6”,
“*”, “1”, “2”, “3”, “-“, “0”, “.”, “=”, “+”};
JPanel buttonPanel = new JPanel(new GridLayout(4, 4));
Add(buttonPanel, BorderLayout.CENTER);
setVisible(true);
}
// Main method
Public static void main(String[] args) {
New ScientificCalculator();
}
}