Question
import javax.swing.*; import java.awt.*; public class Calculator { public static void main(String[] args) { JFrame frame = new JFrame(Calculator); Container ContentPane = frame.getContentPane(); JLabel topLabel
import javax.swing.*; import java.awt.*; public class Calculator { public static void main(String[] args) { JFrame frame = new JFrame("Calculator"); Container ContentPane = frame.getContentPane(); JLabel topLabel = new JLabel("CSc 20 Lab 08", JLabel.CENTER); JPanel main = new JPanel (new GridLayout(7,1,2,2)); ContentPane.add(main); main.add(topLabel); JPanel ptext = new JPanel(); JTextField textField = new JTextField("0",42); ptext.add(textField); main.add(ptext); textField.setHorizontalAlignment(JTextField.RIGHT); JPanel pane = new JPanel (new GridLayout(1,5,2,2)); JPanel pane2 = new JPanel (new GridLayout(1,5,2,2)); JPanel pane3 = new JPanel (new GridLayout(1,5,2,2)); JPanel pane4 = new JPanel (new GridLayout(1,5,2,2)); JPanel pane5 = new JPanel (new GridLayout(1,3,2,2)); JButton backspace = new JButton(" BkSP "); pane.add(backspace); JButton CE = new JButton(" CE "); pane.add(CE); JButton C = new JButton(" C "); pane.add(C); JButton divide = new JButton(" / "); pane.add(divide); JButton sqrt = new JButton(" sqrt "); pane.add(sqrt); JButton seven = new JButton(" 7 "); pane2.add(seven); JButton eight = new JButton(" 8 "); pane2.add(eight); JButton nine = new JButton(" 9 "); pane2.add(nine); JButton Multiply = new JButton(" * "); pane2.add(Multiply); JButton precentage = new JButton(" % "); pane2.add(precentage); JButton four = new JButton(" 4 "); pane3.add(four); JButton five = new JButton(" 5 "); pane3.add(five); JButton six = new JButton(" 6 "); pane3.add(six); JButton subtract = new JButton(" - "); pane3.add(subtract); JButton dividex = new JButton(" 1/x "); pane3.add(dividex); JButton one = new JButton(" 1 "); pane4.add(one); JButton two = new JButton(" 2 "); pane4.add(two);; JButton three = new JButton(" 3 "); pane4.add(three); JButton add = new JButton(" + "); pane4.add(add); JButton PlusMinus = new JButton(" +/- "); pane4.add(PlusMinus); main.add(pane); main.add(pane2); main.add(pane3); main.add(pane4); JButton zero = new JButton(" 0 "); pane5.add(zero); JButton Point = new JButton(" . "); pane5.add(Point); JButton Equals = new JButton(" = "); pane5.add(Equals); main.add(pane5); frame.setVisible(true); frame.setSize(500, 300); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
}
What I got done so far
Objective: This assignment will give you practice with action event handling The programming assignment: In this assignment you are to add functionality to the calculator created in lab 08. You don't have to make the calculator a full function calculator. You only need to make buttons 0 9, +, -, *, / and work. Some programming hints 1. Implement an action listener public void actionPerformed(ActionEvent e) for (int i=0; iStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started