Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Week 3 Programming Assignment Create Java programs for the following two problem

ID: 3534103 • Letter: W

Question

Week 3 Programming Assignment Create Java programs for the following two problems. 1. Write a Java application to display the following GUI. At this point you are only implementing the display. We are not ready to make the calculator actually do any calculations! This program has the following requirements: 1. The size of the calculator is 250 x 250 pixels. 2. The background and foreground color of the calculator buttons must alternate in a checker board pattern as shown above. You can choose any pair of colors for your foreground and background colors. 3. The buttons should have at least 5 pixels of space between them. 4. The text on the buttons should be SanSerif size 16 and be bold. 5. Your application should be implemented in a single class. The main method of the class does nothing more than create an object of the class. The constructor of the class creates and displays the GUI. The constructor may call other methods of the class if needed. 6. The class must inherit from JFrame as the following demonstrates: public myGUI extends JFrame {

Explanation / Answer

This is what u needed. here is the code. run it and check ------------------------------------------------------------ import javax.swing.*; import java.awt.*; public class Calculator extends JFrame { JButton btn1 = new JButton("1"); JButton btn2 = new JButton("2"); JButton btn3 = new JButton("3"); JButton btn4 = new JButton("4"); JButton btn5 = new JButton("5"); JButton btn6 = new JButton("6"); JButton btn7 = new JButton("7"); JButton btn8 = new JButton("8"); JButton btn9 = new JButton("9"); JButton btn0 = new JButton("0"); JButton btnP = new JButton("."); JButton opPlus = new JButton("+"); JButton opMult = new JButton("x"); JButton opDivi = new JButton("/"); JButton opMinu = new JButton("-"); JButton Equal = new JButton("="); JTextField txt = new JTextField(); public Calculator() { Container c = getContentPane(); c.setLayout(null); txt.setBounds(5,5,215,25); btn1.setBounds(5,35,50,50); btn2.setBounds(60,35,50,50); btn3.setBounds(115,35,50,50); opMult.setBounds(170,35,50,50); btn4.setBounds(5,90,50,50); btn5.setBounds(60,90,50,50); btn6.setBounds(115,90,50,50); opDivi.setBounds(170,90,50,50); btn7.setBounds(5,145,50,50); btn8.setBounds(60,145,50,50); btn9.setBounds(115,145,50,50); opPlus.setBounds(170,145,50,50); btnP.setBounds(5,200,50,50); btn0.setBounds(60,200,50,50); opMinu.setBounds(115,200,50,50); Equal.setBounds(170,200,50,50); txt.setEditable(false); Font font = new Font("SanSerif",Font.BOLD,16); txt.setFont(font); txt.setHorizontalAlignment(JTextField.RIGHT); c.add(txt); txt.setBackground(Color.WHITE); c.add(btn1); btn1.setBackground(Color.RED); c.add(btn2); btn2.setBackground(Color.YELLOW); c.add(btn3); btn3.setBackground(Color.RED); c.add(opMult); opMult.setBackground(Color.YELLOW); c.add(btn4); btn4.setBackground(Color.YELLOW); c.add(btn5); btn5.setBackground(Color.RED); c.add(btn6); btn6.setBackground(Color.YELLOW); c.add(opDivi); opDivi.setBackground(Color.RED); c.add(btn7); btn7.setBackground(Color.RED); c.add(btn8); btn8.setBackground(Color.YELLOW); c.add(btn9); btn9.setBackground(Color.RED); c.add(opPlus); opPlus.setBackground(Color.YELLOW); c.add(btnP); btnP.setBackground(Color.YELLOW); c.add(btn0); btn0.setBackground(Color.RED); c.add(opMinu); opMinu.setBackground(Color.YELLOW); c.add(Equal); Equal.setBackground(Color.RED); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); setSize(240,290); int w = getSize().width; int h = getSize().height; int x = (dim.width-w)/2; int y = (dim.height-h)/2; setLocation(x, y); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); } public static void main(String[] args) { Calculator Cal = new Calculator(); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote