Page 750 - Introduction to Programming with Java: A Problem Solving Approach
P. 750
716 Chapter 17 GUI Programming—Component Layout, Additional GUI Components
/**************************************************************
*
MathCalculator.java
Dean & Dean
This program uses embedded layout managers to display
the square root and logarithm of a user-entered number.
**************************************************************/
*
*
*
*
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MathCalculator extends JFrame
{
private static final int WIDTH = 380;
private static final int HEIGHT = 110;
private JTextField xBox;
// user's input value
private JTextField xSqrtBox; // generated square root
private JTextField xLogBox; // generated logarithm
//***********************************************************
public MathCalculaAtopr(a)go PDF Enhancer {
setTitle("Math Calculator");
setSize(WIDTH, HEIGHT);
setDefaultCloseOperation(EXIT_ON_CLOSE);
createContents();
setVisible(true);
// end MathCalculator constructor
//***********************************************************
}
// Create components and add to window.
private void createContents()
{
JPanel xPanel;
// holds
x label and its text box
"sqrt x" label and its text box
"log x" label and its text box
2));
JPanel xSqrtPanel; // holds
JPanel xLogPanel; // holds
JLabel xLabel;
JButton xSqrtButton;
JButton xLogButton;
Listener listener;
setLayout(new GridLayout(2,
Figure 17.9a MathCalculator program—part A