Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Java program to perform four arithmetic operations: Add, Subtract, Multiply, and Divide. The inputs and output should be displayed with proper Java GUI

Write a Java program to perform four arithmetic operations: Add, Subtract, Multiply, and Divide. The inputs and output should be displayed with proper Java GUI items shown in below:

// This program creates a simple Printer GUI import javax.swing.JFrame;

public class Printer { public static void main( String[] args ) { PrinterFrame printerFrame = new PrinterFrame(); printerFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); printerFrame.setSize( 400, 180 ); // set frame size printerFrame.setVisible( true ); // display frame } // end main } // end class Printer

// This program creates a simple Printer GUI import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.BorderLayout; import java.awt.Color; import javax.swing.JFrame; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JCheckBox; import javax.swing.JRadioButton; import javax.swing.ButtonGroup; import javax.swing.JComboBox; import javax.swing.JPanel;

public class PrinterFrame extends JFrame { private JButton button1; private JButton button2; private JButton button3; private JButton button4; private JCheckBox check1; private JCheckBox check2; private JCheckBox check3; private JCheckBox check4; private JRadioButton radio1; private JRadioButton radio2; private JRadioButton radio3; private ButtonGroup radioGroup; private JComboBox comboBox; private JLabel label1; private JLabel label2; private JPanel panel1; private JPanel panel2; private JPanel panel3; private JPanel panel4; private JPanel panel5; private JPanel panel6; private JPanel panel7; private JPanel panel8;

// constructor sets up GUI public PrinterFrame() { super( "Printer" );

// build left north panel label1 = new JLabel( "Printer: MyPrinter" ); panel1 = new JPanel(); panel1.setLayout( new FlowLayout( FlowLayout.LEFT ) ); panel1.add( label1 );

// build right east panel button1 = new JButton( "OK" ); button2 = new JButton( "Cancel" ); button3 = new JButton( "Setup..." ); button4 = new JButton( "Help" ); panel2 = new JPanel(); panel2.setLayout( new GridLayout( 4, 1, 5, 5 ) ); panel2.add( button1 ); panel2.add( button2 ); panel2.add( button3 ); panel2.add( button4 );

// build left south panel label2 = new JLabel( "Print Quality: " ); comboBox = new JComboBox(); comboBox.addItem( "High" ); check1 = new JCheckBox( "Print to File" ); panel3 = new JPanel(); panel3.setLayout( new FlowLayout( FlowLayout.CENTER, 10, 0 ) ); panel3.add( label2 ); panel3.add( comboBox ); panel3.add( check1 );

// build left east panel check2 = new JCheckBox( "Image" ); check3 = new JCheckBox( "Text" ); check4 = new JCheckBox( "Code" ); panel4 = new JPanel(); panel4.setLayout( new BorderLayout( ) ); panel4.add( check2, BorderLayout.NORTH ); panel4.add( check3, BorderLayout.CENTER ); panel4.add( check4, BorderLayout.SOUTH );

// build left west panel radio1 = new JRadioButton( "Selection", false ); radio2 = new JRadioButton( "All", true ); radio3 = new JRadioButton( "Applet", false ); panel5 = new JPanel(); panel5.setLayout( new BorderLayout() ); panel5.add( radio1, BorderLayout.NORTH ); panel5.add( radio2, BorderLayout.CENTER ); panel5.add( radio3, BorderLayout.SOUTH );

// group the radio buttons radioGroup = new ButtonGroup(); radioGroup.add( radio1 ); radioGroup.add( radio2 ); radioGroup.add( radio3 );

// build left center panel8 = new JPanel(); panel8.setLayout( new FlowLayout( FlowLayout.CENTER, 30, 0 ) ); panel8.setBackground( Color.WHITE ); panel8.add( panel4 ); panel8.add( panel5 );

// set up left panel panel6 = new JPanel(); panel6.setLayout( new BorderLayout() ); panel6.add( panel1, BorderLayout.NORTH ); panel6.add( panel8, BorderLayout.CENTER ); panel6.add( panel3, BorderLayout.SOUTH );

// set up layout panel7 = new JPanel(); panel7.setLayout( new FlowLayout( FlowLayout.CENTER, 10, 0 ) ); panel7.add( panel6 ); panel7.add( panel2 ); add( panel7 ); } // end PrinterFrame constructor } // end class PrinterFrame

Output:

image text in transcribed

Calculator 1st Number 32nd Number 5 Result 0.6 Add SubtractMuiply Divide

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

More Books

Students also viewed these Databases questions

Question

What is the baud rate of the standard 10-Mbps Ethernet?

Answered: 1 week ago

Question

1. Prepare a flowchart of Dr. Mahalees service encounters.

Answered: 1 week ago