SimpleCalculator - /* In this applet, the user can type in...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/* In this applet, the user can type in two real numbers. The user can click on buttons labled +, - , *, and / to perform basic arithmetic operations on the numbers. When the user clicks on a button the answer is displayed. The applet should be about 200 by 120 pixels. */ * import java.awt.*; import java.awt.event.*; import java.applet.*; i public class SimpleCalculator extends Applet implements ActionListener { p TextField xInput, yInput; // Input boxes for the numbers. Label answer; // Label for displaying the answer, or an // error message if appropriate. public void init() { setBackground(Color.lightGray); /* Create the input boxes, and make sure that the background color is white. (On some platforms, it is automatically.) */ xInput = new TextField("0"); xInput.setBackground(Color.white); yInput = new TextField("0"); yInput.setBackground(Color.white); /* Create panels to hold the input boxes and lables "x =" and "y = ". By using a BorderLayout with the TextField in the Center position, the TextField will take up all the space
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

SimpleCalculator - /* In this applet, the user can type in...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online