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: 3542192 • 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 {

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!

Explanation / Answer

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import java.awt.*;


public class ShowGridLayout extends JFrame{
public ShowGridLayout () {

JPanel p1 = new JPanel();
p1.setLayout (new GridLayout(4, 4, 5, 5));

for (int i=1; i<=16; i++); {
p1.add(new JButton ("" + 1));
}

p1.add(new JButton("7"));
p1.add(new JButton("8"));
p1.add(new JButton("9"));
p1.add(new JButton("/"));
p1.add(new JButton("4"));
p1.add(new JButton("5"));
p1.add(new JButton("6"));
p1.add(new JButton("*"));
p1.add(new JButton("1"));
p1.add(new JButton("2"));
p1.add(new JButton("3"));
p1.add(new JButton("-"));
p1.add(new JButton("0"));
p1.add(new JButton("."));
p1.add(new JButton("="));
p1.add(new JButton("+"));

JPanel p2 = new JPanel(new BorderLayout());
p2.add(new JTextField(""), BorderLayout.NORTH);
p2.add(p1, BorderLayout.CENTER);

}

public static void main (String[] args){
ShowGridLayout frame = new ShowGridLayout ();
frame.setTitle("Calculator");
frame.setSize(250, 250);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.setVisible(true);
}
}

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