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

1. Write a Java application to display the following GUI. At this point you are

ID: 3656315 • Letter: 1

Question

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! *NOTE: Trying to make a 4x4 panel that represents a calculator, with also the should be black and white checkered. 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

import javax.swing.*; import java.awt.*; public class myCalculator extends JFrame{ public myCalculator() { // Call the super class JFrame and set the title of the window to My Calculator Class super.setTitle(" My Calculator Class"); Color paleCyan = new Color(109, 207, 246); Color lightCyan = new Color(68, 140, 203); //Font font1 = new Font("SansSerif", 6); Font font1 = new Font("SansSerif", Font.PLAIN, 16); // In a real calculator these is where your calculations appear! JTextField jtext = new JTextField(" 0 "); jtext.setSize(250,25); jtext.setHorizontalAlignment(JTextField.RIGHT); JPanel textPanel = new JPanel(new BorderLayout()); /* Main Panel holding the Jtext field for the calculations area is used with the BorderLayout because the NORTH portion stretches the JTextfield Horizontal (side-to-side) */ textPanel.add(jtext, BorderLayout.NORTH); JPanel buttonsPanel = new JPanel(new GridLayout(4,4,5,5)); buttonsPanel.setBackground(paleCyan); JButton jTwo = new JButton("2"); JButton jOne = new JButton("1"); JButton jThree = new JButton("3"); JButton jFour = new JButton("4"); JButton jFive = new JButton("5"); JButton jSix = new JButton("6"); JButton jSeven = new JButton("7"); JButton jEight = new JButton("8"); JButton jNine = new JButton("9"); JButton jZero = new JButton("0"); JButton jDot = new JButton("."); JButton jEqual = new JButton("="); JButton jMultiply = new JButton("*"); JButton jDivide = new JButton("/"); JButton jMinus = new JButton("-"); JButton jAdd = new JButton("+"); buttonsPanel.add(jSeven); buttonsPanel.add(jEight); buttonsPanel.add(jNine); buttonsPanel.add(jMultiply); buttonsPanel.add(jFour); buttonsPanel.add(jFive); buttonsPanel.add(jSix); buttonsPanel.add(jDivide); buttonsPanel.add(jOne); buttonsPanel.add(jTwo); buttonsPanel.add(jThree); buttonsPanel.add(jMinus); buttonsPanel.add(jDot); buttonsPanel.add(jZero); buttonsPanel.add(jEqual); buttonsPanel.add(jAdd); JPanel mainPanel = new JPanel(new BorderLayout()); //Final step add the panels to the Frame (Container) mainPanel.add(textPanel, BorderLayout.NORTH); mainPanel.add(buttonsPanel, BorderLayout.CENTER); add(mainPanel, BorderLayout.CENTER); } public static void main(String[] args) { myCalculator frame = new myCalculator(); frame.setSize(250, 250); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setResizable( false ); frame.setVisible(true); } } // I could not see the photo so this is the best I can deliver. If you need additional help, please feel free to email me. This should be a good start though. There are no functions in the buttons its pretty much just a template. It is ready to run. Good Luck!! :)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote