CIS355A landscaping calculator tabbed program (Java)

 Program is mostly written, just need to correct the error and get the program to display correctly.  Each tab must be in it’s own tab… I’m having an issue with getting ride of one errors and then of course the logical errors I can’t find!

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

Course Project Examples

This document provide a sample of what is possible, and could lead to a project worth the maximum grade of 100% Something to think about! Do not think this is what you have to do to get the maximum number of points. It is just a sample! You are only bound by your programming ability. Please do not try and do more than you are capable of. Think, plan, design and code YOUR project. This is your opportunity to show off your skills!

Overall Appearance

Tabs should be used in this application. At a minimum, 4 fully functioning tabs should be designed – the Pools tab, the Hot Tubs tab, the customer tab and the Contractors tab.

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

General Tab

The first tab simply displays the current date. An Exit button is provided in this tab, as well as all others. (For all buttons throughout the application, mnemonic values are set.)

Options Tab

The user should be able to change the company name in the Options tab. If the user returns to this tab later, the name should be displayed in the title of the window frame.

Customers Tab

The Customers tab allows the user to add new customers and checks for the existence of the customer.txt file in the directory where the program is located. If the file does not exist, the program tells the customer in the

Message Area

at the bottom. The

Customer Display

will give a brief explanation of the user’s options.

Message Area
Customer Display


Add Customer

When the user clicks Add Customer, an entry window should appear. If the customer.txt file does not exist, the program tells the customer in the Message Area at the bottom.

Message Area

In this window, the user can enter customers; the information entered will be stored as entered.

Clicking Add Customer will attempt to write the information to customer.txt. The user should receive an indication when a customer is added successfully.

Successful customer addition

After a customer has been added and the Customers window is closed, the user can click Refresh to refresh the Customer Display area, which will display the contents of the customer.txt file.

Contractor Tab

The Contractor tab functions in exactly the same way as the Customers tab. The filename for contractors is contract.txt.

Pools Tab

The Pools tab should perform a calculation.

After a length, width, and depth have been entered, the user can click Calculate Volume and the program will display the calculated volume (length * width * depth in cubic feet).

Exception handling is used here to catch exceptions, including incomplete forms, invalid entries, and combinations of these.


Incomplete forms:

Message Area

Fields not filled out


Invalid input:

Message Area

Invalid Input


Combination invalid input/incomplete input:

Hot Tubs Tab

The Hot Tubs tab allows for round and oval tubs’ volumes to be calculated.

Round Tub

When Round Tub is selected, the user cannot fill out the width field since we’re dealing with a circle. After filling out the length and depth fields, the Calculate Volume button will display the volume (Pi * ((length/2)^2) * depth). The width is automatically set to the same value as the length, and the user is informed.

Again, exception handling is used here.

Automatically set to same value as length

Oval Tub

When Oval Tub is selected, the width field is opened up:

The formula used to calculate the volume is (Pi * (length * width)^2) * depth.

As with the Pools tab, the same error messages should be displayed in case of no input/invalid values.

Temp Calc Tab

The Temp Calc tab offers a temperature converter (Celsius <-> Fahrenheit).

Opposite values

The user enters a temperature, and selects either C or F. The field after the Result display will display the opposite (if C is selected, field will display F; if F is selected, field will display C).

No input:

Value automatically set to zero in case of no input/invalid input

The Length Calc tab offers the user a length converter (millimeters, meters, yards, feet, and inches).

“Feet” was filled out; all other values are automatically populated

6

37

DeVryUniversity

Online CIS355A

Course Project Guide

Business Systems Programming I–Course Project

· Project Description

·

Analysis and Design

·

User’s Manual

·

Minimum Requirements

·

Sample Extended Requirements

Project Description

The importance of a graphical user interface in programming is paramount in being successful in the business industry. This project incorporates GUI techniques with other tools that you have learned about in this class.

Here is your assignment: You work for a Landscape architect. They have asked you to be a part of their team as they need a computer programmer, analyst, and designer to aid them in calculating engineering specification. Specifically, you have been assigned to the Pools, Hot Tubs and Spas section of their landscaping team. Your skills will be needed in creating a GUI program that calculates engineering specifications.

This assignment is due in Week 7, but it is suggested that you begin working on the course project assignment in Week 5, which should give you ample time to complete the project.  You will find that all the lectures, Quick Test Programs, and Lab assignments will prepare you for the course project.

Analysis and Design

In week 4, you will complete the analysis and design for the project.  You will use the information described in Chapter Two (pages 48-49) to create the Analysis and Design documentation.  You will create the following items:

1. Request for New Application

2. Problem Analysis

3. List and description of the requirements

4. Interface Storyboard/drawing

5. Design Flowchart or pseudo code

The Analysis and Design document will be a single MS Word document, which contains all descriptions and drawings.

User’s Manual

Include a User’s Manual: a Word document, with screenshots, that explains how to run your application. Your mark will depend both on the program quality, and the quality of the User’s Manual.
Here are some more detailed guidelines about the User’s Manual:

· It does not need to be long, probably not more than 10 pages, including screenshots.

· Write it at the expected user’s level – not too technical.

· Detail all the functionality that the application provides. Best, structure you presentation top-down way.

· For each function, show what it its purpose and sample execution, with a screenshot.

Minimum Requirements

This example would be the bare minimum to obtain a passing grade (no more than a 75%):

This Swimming Pool Calculator is one that is very simple to use. As you can see, it is a user interface that will allow the user to enter the desired length, width, and average depth of a pool and the program will calculate the volume of that pool based on the entered information. This information is then stored in a file that can be viewed. The interface contains four text boxes for the user to enter information along with a calculate and an exit button.

Entering Length of Pool

The length of the pool is entered here.

The user will be able to enter the length of the pool(in feet) in the text box shown above. To enter information in the box, the user must click in the desired box. The curser will appear allowing the user to enter the appropriate information. To get to the next box, all the user needs to do is either click with the mouse the next box, or the user can hit the tab button on their keyboard. Either method will move the cursor to the next input.

Entering the Width of the Pool

The width of the pool is entered here.

As with the length box, the width box is used in the same fashion. The user will enter the width of the Pool(in feet) using the keyboard. The user will then have the option to move to the next box by either using the mouse and clicking in the average box, or they can use the tab key on their keyboard. Either way will move the cursor to the average depth box.

Entering the Average Depth

The average depth is entered here.

The user will now enter the average depth of the Pool(in feet). This needs to be as exact a measurement as possible. If the user only wants to know an about figure then the measurements do not need to be as accurate. The more accurate the user needs the volume to be, the more accurate the measurements need to be. If a mistake is made, all the user needs to do is click the backspace button on their keyboard and the entered information will be deleted.

Calculating the Volume

The calculate button is clicked to calculate the volume of the pool.

This is where the volume will be displayed

The final step is for the user to calculate the volume of the Pool. This can be done in two ways. First, the user can click the calculate button to calculate the volume of the pool. Second, the user can use their keyboard and press Ctrl+C and the program will calculate the volume.

Retrieving Data.Txt file

The Data.txt file is found here.

The Data.txt file can be retrieved by going into the workspace file using Windows Explorer. Once there the user can click on the Data file to retrieve the contents. The contents will be in Word pad form, and will look like the following page.

The Data from the user input as it appears in the Data.txt file.

From this point, the user can either review the document or can change any information. If the user desired, they could make this document a read only document by going into the security settings in Windows and setting the access. This should only be done by the administrator.

Exiting the program

The program can also be closed by clicking here.

Exit the program by clicking here.

To exit the program, the user can do one of two things. First, the user can click on the Exit button. This will close the program. Two, the user can use the keyboard and click Ctrl+X. Third, the user can click on the red X at the top of the interface. Any of these methods will allow the program to close.
Below are some hints:
……
volume = length * width * depth; //Will calculate the volume of the pool
volumeField.setText(num.format(volume)); //Will display the volume of the pool for the user
{

//Will write to the Data.txt file
try{

FileWriter fileW = new FileWriter(“Data.txt”, true);
System.out.println(“Writing data to Data.txt file”);
fileW.write(“length:”);
fileW.write(lengthField.getText());
fileW.write(“,”);
fileW.write(” “);
fileW.write(“width:”);
fileW.write(widthField.getText());
fileW.write(“,”);
fileW.write(” “);
fileW.write(“avg depth:”);
fileW.write(depthField.getText());
fileW.write(“,”);
fileW.write(” “);
fileW.write(“volume:”);
fileW.write(volumeField.getText());
fileW.write(“,”);
fileW.close();

FileReader fileR = new FileReader(“Data.txt”);
BufferedReader buffIn = new BufferedReader(fileR);

String textData = buffIn.readLine();
System.out.println(textData);
buffIn.close();
System.out.println(“\n”);

}
catch(IOException e1)
{
JOptionPane.showMessageDialog(null,e1.getMessage(), “ERROR”,2); //Will display error message if unable to write to file
}

}

Sample Extended Requirements

The following screenshots provide a sample of what is possible, and could lead to a project worth the maximum grade of 100%. Something to think about!!! Do not think this is what you have to do to get the maximum number of points. It is just a sample! You are only bound by your programming ability. Please do not try and do more than you are capable of. Think, plan, design and code YOUR course project. This is your opportunity to show off your skills!

General Interface

The first panel simply displays today’s date – I opted to not give the user the option to change this, as it uses the system date. Since this is to be a generic tool, we give the user the option to set the company name in the Options tab; doing so will change “Enter a company name in the Options tab” to the company name. An Exit button is provided in all tabs. Mnemonic values are set for all buttons throughout the application. I opted for a few different error-catching options rather than a consistent one throughout the application, just to show some extra functionality. All tabs can easily be set to behave identically.

Options tab

This tab allows the user to enter a company name. Hitting Set New Name will change the window’s title to whatever was entered.
The result:

Customers tab

General

This tab allows the user to add new customers. It will display the existing customers in the main area.

Functionality

General

The program checks for the existence of the customer.txt file in the directory where the program is located. If the file does not exist, the program tells the customer in the Message Area at the bottom. The Customer Display will give a brief explanation of options.

Customer Display
Message Area

Add Customer

In this window, the user can enter customers. Again, the Message Area will display program message. The State selection contains a list of all US state abbreviations. No error checking is performed here, as we are dealing with strings – the information will be stored literally as entered.Message Area

Selecting Add Customer will attempt to write the information to customer.txt. If the file is write-protected, the Message Area will inform the user. If the file does not exist, it is created. If the file already exists and can be written to, the information will be appended to the file. Fields are not emptied when focused on (this can easily be changed).

Successful customer addition

Below is an example of the situation where the file already exists and can be written to; notice the message in the Message Area:

The Delete File option gives the user the option to delete the customer.txt file. If the file does not exist, the Message Area will inform the user after Yes has been selected. If No is selected, the Customer File Deletion window simply closes.

After a customer has been added and the Customers window is closed, the user selects Refresh to refresh the Customer Display area, which will display the contents of the customer.txt file. It can be changed to automatically refresh the contents, but I preferred to give the user some more control.

Contractor tab

The Contractor tab functions in exactly the same way as the Customers tab. The file name for contractors is contractor.txt.

Pools tab

General

This tab allows for pool volume calculation. It assumes pools are rectangular (round- and oval-shaped pools/tubs can be calculated in the Hot Tubs tab.

Functionality

After a length, width, and depth have been entered, the user clicks Calculate Volume and the program will display the calculated volume (length * width * depth in cubic feet).

Anomalies caught are no input and invalid input. The user is limited to entering only numbers and periods.
No input:

Fields not filled out
Message Area

Invalid input:

Message Area
Invalid Input

Combination invalid input/no input:

Hot Tubs tab

General

This tab allows for round and oval tubs’ volumes to be calculated.

Functionality

When Round Tub is selected, the user cannot fill out the width field, as it should be the same as the length (since we’re dealing with a circle). After filling out the length and tub fields, the Calculate Volume button will display the volume (Pi * ((length/2)^2) * depth). The width is automatically set to the same value as the length, and the user is informed.
Again, invalid input is caught (only numbers and periods are allowed), and the program will display the same error messages as the Pools tab.

Automatically set to same value as length

When Oval Tub is selected, the width field is opened up:

Again, the same error messages are displayed in case of no input/invalid values.
Formula used is Pi * (length * .5) * (width * .5) * depth;

Temp Calc tab

General

This tab offers a temperature converter (Celsius <-> Fahrenheit).

Functionality

Opposite values

The user enters a temperature, and selects either C or F. The field after the Result display will display the opposite (if C is selected, field will display F; if F is selected, field will display C). I took a different approach for the System Messages here, but the principle is the same. In this tab, the temperature value will be automatically set to zero in case of invalid input or no input.

No input:

Value automatically set to zero in case of no input/invalid input

Length Calc tab

General

This tab offers the user a length converter (millimeters, meters, yards, feet, and inches).

Functionality

The user fills out one of the fields (only numerical values and the period are allowed), and hits Convert. Only one of the fields can be filled out at any time (changing the focus will delete the other fields).

“Feet” was filled out; all other values are automatically populated

The end…

In order to get full credit which is 100 points, you need to provide a lot of extra functionalities. I prepared the following 4 examples to assist you.

1. The JTabbedPane class
2. Checkboxes and radio buttons
3. Lists and combo boxes
4. Scrollbars and sliders

The JTabbedPane Class

If you’ve ever dealt with the Control Panel in Windows, you already know what a JTabbedPane is. It’s a container with labeled tabs. When you click on a tab, a new set of controls is shown in the body of the JTabbedPane. In Swing, JTabbedPane is simply a specialized container.

Each tab has a name. To add a tab to the JTabbedPane, simply call addTab(). You’ll need to specify the name of the tab as well as a component that supplies the tab’s contents. Typically, it’s a container holding other components.
Even though the JTabbedPane only shows one set of components at a time, be aware that all the components on all the pages are in memory at one time. If you have components that hog processor time or memory, try to put them into some “sleep” state when they are not showing.

The following example create five tabs, each tab have their own components.

import java.awt.*;
import javax.swing.*;
public class TabDemo extends JFrame
{
public TabDemo()
{
super( “JTabbedPane Demo ” );
JTabbedPane tab = new JTabbedPane();
// constructing the first panel
JLabel l1 = new JLabel( “Welcome to CIS355A”, SwingConstants.CENTER );
JPanel p1 = new JPanel();
p1.add( l1 );
tab.addTab( “Tab#1″, null, p1, ” Panel #1″ );
// constructing the second panel
JLabel l2 = new JLabel(“Welcome to JTabbedPaneDemo”, SwingConstants.CENTER);
JPanel p2 = new JPanel();
p2.setBackground( Color.blue );
p2.add( l2 );
tab.addTab( “Tab#2″, null, p2, ” Panel #2″ );
// constructing the third panel
JLabel l3 = new JLabel( ” Java is sooooooooooo fun!” );
JPanel p3 = new JPanel();
p3.setLayout( new BorderLayout() );
p3.add( new JButton( “J” ), BorderLayout.NORTH );
p3.add( new JButton( “A” ), BorderLayout.WEST );
p3.add( new JButton( “V” ), BorderLayout.EAST );
p3.add( new JButton( “A” ), BorderLayout.SOUTH );
p3.add( l3, BorderLayout.CENTER );
tab.addTab( “Tab#3″, null, p3, ” Panel #3″ );
// constructing the fourth panel
JLabel l4 = new JLabel( “panel four” );
JPanel p4 = new JPanel();
p4.setBackground( Color.black );
JLabel digits = new JLabel( “Java” );
digits.setFont( new Font( “Serif”, Font.ITALIC, 50 ) );
digits.setForeground( Color.blue );
p4.add( digits );
tab.addTab( “Tab#4″, null, p4, ” Panel #4″ );
// constructing the last panel
JLabel l5 = new JLabel( “panel five” );
JLabel l6 = new JLabel( “The end!” );
JPanel p5 = new JPanel();
p5.add( l6 );
tab.addTab( “Tab#5″, null, p5, ” Panel #5″ );
// add JTabbedPane to container
getContentPane().add( tab );
setSize( 250, 200 );
setVisible( true );
}
public static void main( String args[] )
{
TabDemo demo = new TabDemo();
demo.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
}
Checkboxes and Radio Buttons

A checkbox is a labeled toggle switch. Each time the user clicks it, its state toggles between checked and unchecked. Swing implements the checkbox as a special kind of button. Radio buttons are similar to checkboxes, but they are normally used in groups. Clicking on one radio button in the group automatically turns the others off. They are named for the mechanical preset buttons on old car radios (like some of us had in high school).

Checkboxes and radio buttons are represented by instances of JCheckBox and JRadioButton, respectively. Radio buttons can be tethered together using an instance of another class called ButtonGroup . By now you’re probably well into the swing of things (no pun intended) and could easily master these classes on your own. We’ll use an example to illustrate a different way of dealing with the state of components and to show off a few more things about containers.

A JCheckBox sends ItemEvent s when it’s pushed. Because a checkbox is a kind of button, it also fires ActionEvents when checked. For something like a checkbox, we might want to be lazy and check on the state of the buttons only at some later time, such as when the user commits an action. For example, when filling out a form you may only care about the user’s choices when the submit button is pressed.

DriveThrough prints the results when we press the Place Order button. Therefore, we can ignore all the events generated by our checkboxes and radio buttons and listen only for the action events generated by the regular button.
//file: DriveThrough.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class DriveThrough
{
public static void main(String[] args) {
JFrame frame = new JFrame(“Lister v1.0”);

JPanel entreePanel = new JPanel( );
final ButtonGroup entreeGroup = new ButtonGroup( );
JRadioButton radioButton;
entreePanel.add(radioButton = new JRadioButton(“Beef”));
radioButton.setActionCommand(“Beef”);
entreeGroup.add(radioButton);
entreePanel.add(radioButton = new JRadioButton(“Chicken”));
radioButton.setActionCommand(“Chicken”);
entreeGroup.add(radioButton);
entreePanel.add(radioButton = new JRadioButton(“Veggie”, true));
radioButton.setActionCommand(“Veggie”);
entreeGroup.add(radioButton);

final JPanel condimentsPanel = new JPanel( );
condimentsPanel.add(new JCheckBox(“Ketchup”));
condimentsPanel.add(new JCheckBox(“Mustard”));
condimentsPanel.add(new JCheckBox(“Pickles”));

JPanel orderPanel = new JPanel( );
JButton orderButton = new JButton(“Place Order”);
orderPanel.add(orderButton);

Container content = frame.getContentPane( );
content.setLayout(new GridLayout(3, 1));
content.add(entreePanel);
content.add(condimentsPanel);
content.add(orderPanel);

orderButton.addActionListener(new ActionListener( ) {
public void actionPerformed(ActionEvent ae) {
String entree =
entreeGroup.getSelection( ).getActionCommand( );
System.out.println(entree + ” sandwich”);
Component[] components = condimentsPanel.getComponents( );
for (int i = 0; i < components.length; i++) { JCheckBox cb = (JCheckBox)components[i]; if (cb.isSelected( )) System.out.println("With " + cb.getText( )); } } }); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); frame.setSize(300, 150); frame.setVisible(true); } } DriveThrough lays out three panels. The radio buttons in the entreePanel are tied together through a ButtonGroup object. We add() the buttons to a ButtonGroup to make them mutually exclusive. The ButtonGroup object is an odd animal. One might expect it to be a container or a component, but it isn't; it's simply a helper object that allows only one RadioButton to be selected at a time. In this example, the button group forces you to choose a beef, chicken, or veggie entree, but not more than one. The condiment choices, which are JCheckBoxes, aren't in a button group, so you can request any combination of ketchup, mustard, and pickles on your sandwich. When the Place Order button is pushed, we receive an ActionEvent in the actionPerformed() method of our inner ActionListener. At this point, we gather the information in the radio buttons and checkboxes and print it. actionPerformed() simply reads the state of the various buttons. We could have saved references to the buttons in a number of ways; this example demonstrates two. First, we find out which entree was selected. To do so, we call the ButtonGroup's getSelection() method. This returns a ButtonModel, upon which we immediately call getActionCommand(). This returns the action command as we set it when we created the radio buttons. The action commands for the buttons are the entrée names, which is exactly what we need. To find which condiments were selected, we use a more complicated procedure. The problem is that condiments aren't mutually exclusive, so we don't have the convenience of a ButtonGroup. Instead, we ask the condiments JPanel for a list of its components. The getComponents() method returns an array of references to the container's child components. We'll use this to loop over the components and print the results. We cast each element of the array back to JCheckBox and call its isSelected() method to see if the checkbox is on or off. If we were dealing with different types of components in the array, we could determine each component's type with the instanceof operator. Or, more generally, we could maintain references to the elements of our form in some explicit way (a map by name,perhaps). Lists and Combo Boxes JLists and JComboBoxes are a step up on the evolutionary chain from JButtons and JLabels. Lists let the user choose from a group of alternatives. They can be configured to force a single selection or allow multiple choices. Usually, only a small group of choices is displayed at a time; a scrollbar lets the user move to the choices that aren't visible. The user can select an item by clicking on it. She can expand the selection to a range of items by holding down Shift and clicking on another item. To make discontinuous selections, the user can hold down the Control key instead of the Shift key (on a Mac, this is the Command key). A combo box is a cross-breed between a text field and a list. It displays a single line of text (possibly with an image) and a downward pointing arrow on one side. If you click on the arrow, the combo box opens up and displays a list of choices. You can select a single choice by clicking on it. After a selection is made, the combo box closes up; the list disappears, and the new selection is shown in the text field. Like other components in Swing, lists and combo boxes have data models that are distinct from visual components. The list also has a selection model that controls how selections may be made on the list data. Lists and combo boxes are similar because they have similar data models. Each is simply an array of acceptable choices. This similarity is reflected in Swing, of course: the type of a JComboBox's data model is a subclass of the type used for a JList's data model. The next example demonstrates this relationship. The following example creates a window with a combo box, a list, and a button. The combo box and the list use the same data model. When you press the button, the program writes out the current set of selected items in the list. Here's the code for the example: //file: Lister.java import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Lister { public static void main(String[] args) { JFrame frame = new JFrame("Lister v1.0"); // create a combo box String [] items = { "uno", "due", "tre", "quattro", "cinque", "sei", "sette", "otto", "nove", "deici", "undici", "dodici" }; JComboBox comboBox = new JComboBox(items); comboBox.setEditable(true); // create a list with the same data model final JList list = new JList(comboBox.getModel( )); // create a button; when it's pressed, print out // the selection in the list JButton button = new JButton("Per favore"); button.addActionListener(new ActionListener( ) { public void actionPerformed(ActionEvent ae) { Object[] selection = list.getSelectedValues( ); System.out.println("-----"); for (int i = 0; i < selection.length; i++) System.out.println(selection[i]); } }); // put the controls the content pane Container c = frame.getContentPane( ); JPanel comboPanel = new JPanel( ); comboPanel.add(comboBox); c.add(comboPanel, BorderLayout.NORTH); c.add(new JScrollPane(list), BorderLayout.CENTER); c.add(button, BorderLayout.SOUTH); frame.setSize(200, 200); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); frame.setVisible(true); } } The combo box is created from an array of strings. This is a convenience—behind the scenes, the JComboBox constructor creates a data model from the strings you supply and sets the JComboBox to use that data model. The list is created using the data model of the combo box. This works because JList expects to use a ListModel for its data model, and the ComboBoxModel used by the JComboBox is a subclass of ListModel. The button's action event handler simply prints out the selected items in the list, which are retrieved with a call to getSelectedValues(). This method actually returns an object array, not a string array. List and combo box items, like many other things in Swing, are not limited to text. You can use images, drawings, or some combination of text and images. You might expect that selecting one item in the combo box would select the same item in the list. In Swing components, selection is controlled by a selection model. The combo box and the list have distinct selection models; after all, you can select only one item from the combo box while it's possible to select multiple items from the list. Thus, while the two components share a data model, they have separate selection models. We've made the combo box editable. By default, it would not be editable: the user could choose only one item in the drop-down list. With an editable combo box, the user can type in a selection, as if it were a text field. Noneditable combo boxes are useful if you just want to offer a limited set of choices; editable combo boxes are handy when you want to accept any input but offer some common choices. There's a great class tucked away in the last example that deserves some recognition. It's JScrollPane. In Lister, you'll notice we created one when we added the List to the main window. JScrollPane simply wraps itself around another Component and provides scrollbars as necessary. The scrollbars show up if the contained Component's preferred size (as returned by getPreferredSize() ) is greater than the size of the JScrollPane itself. The following example combins all the above choice boxes and layout managers in one application – Language. import java.awt.*; import javax.swing.*; public class Language extends JFrame { private JButton button1, button2, button3, button4; private JCheckBox check1, check2, check3, check4; private JRadioButton radio1, radio2, radio3; private ButtonGroup radioGroup; private JComboBox comboBox; private JLabel label1, label2; private JPanel panel1, panel2, panel3, panel4, panel5,panel6, panel7, panel8; public Language() { super( "Language Choice" ); // build left north panel label1 = new JLabel( "My favorite language" ); panel1 = new JPanel(); panel1.setLayout( new FlowLayout( FlowLayout.LEFT ) ); panel1.add( label1 ); // build right east panel button1 = new JButton( "Reset" ); button2 = new JButton( "Clear" ); button3 = new JButton( "Confirm" ); 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( "Class " ); comboBox = new JComboBox(); comboBox.addItem( "CIS170" ); comboBox.addItem( "CIS247" ); comboBox.addItem( "CIS355" ); check1 = new JCheckBox( "Currently taking" ); 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( "C++" ); check3 = new JCheckBox( "C#" ); check4 = new JCheckBox( "Java", true ); 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 panel5 = new JPanel(); panel5.setLayout( new BorderLayout() ); panel5.add( radio1 = new JRadioButton( "Strongly Recommend",true ), BorderLayout.NORTH ); panel5.add( radio2 = new JRadioButton( "Recommend", false ), BorderLayout.CENTER ); panel5.add( radio3 = new JRadioButton( "Not Recommend", false ), 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 ); // setup left panel panel6 = new JPanel(); panel6.setLayout( new BorderLayout() ); panel6.add( panel1, BorderLayout.NORTH ); panel6.add( panel8, BorderLayout.CENTER ); panel6.add( panel3, BorderLayout.SOUTH ); // setup layout panel7 = new JPanel(); panel7.setLayout( new FlowLayout( FlowLayout.CENTER, 10, 0 ) ); panel7.add( panel6 ); panel7.add( panel2 ); getContentPane().add( panel7 ); setSize( 500, 160 ); setVisible( true ); } // end constructor public static void main( String args[] ) { Language myChoice = new Language(); myChoice.setDefaultCloseOperation( EXIT_ON_CLOSE ); } } Scrollbars and Sliders JScrollPane is such a handy component that you may not ever need to use scrollbars by themselves. In fact, if you ever do find yourself using a scrollbar by itself, chances are you really want to use another component called a slider. There's not much point in describing the appearance and functionality of scrollbars and sliders. Instead, let's jump right in with an example that includes both components. The following case shows a simple example with both a scrollbar and a slider. //file: Slippery.java import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class Slippery { public static void main(String[] args) { JFrame frame = new JFrame("Slippery v1.0"); Container content = frame.getContentPane( ); JPanel main = new JPanel(new GridLayout(2, 1)); JPanel scrollBarPanel = new JPanel( ); final JScrollBar scrollBar = new JScrollBar(JScrollBar.HORIZONTAL, 0, 48, 0, 255); int height = scrollBar.getPreferredSize( ).height; scrollBar.setPreferredSize(new Dimension(175, height)); scrollBarPanel.add(scrollBar); main.add(scrollBarPanel); JPanel sliderPanel = new JPanel( ); final JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 255, 128); slider.setMajorTickSpacing(48); slider.setMinorTickSpacing(16); slider.setPaintTicks(true); sliderPanel.add(slider); main.add(sliderPanel); content.add(main, BorderLayout.CENTER); final JLabel statusLabel = new JLabel("Welcome to Slippery v1.0"); content.add(statusLabel, BorderLayout.SOUTH); // wire up the event handlers scrollBar.addAdjustmentListener(new AdjustmentListener( ) { public void adjustmentValueChanged(AdjustmentEvent e) { statusLabel.setText("JScrollBar's current value = " + scrollBar.getValue( )); } }); slider.addChangeListener(new ChangeListener( ) { public void stateChanged(ChangeEvent e) { statusLabel.setText("JSlider's current value = " + slider.getValue( )); } }); frame.pack( ); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); frame.setVisible(true); } } All we've really done here is added a JScrollBar and a JSlider to our main window. If the user adjusts either of these components, the current value of the component is displayed in a JLabel at the bottom of the window. The JScrollBar and JSlider are both created by specifying an orientation, either HORIZONTAL or VERTICAL. You can also specify the minimum and maximum values for the components, as well as the initial value. The JScrollBar supports one additional parameter, the extent. The extent simply refers to what range of values is represented by the slider within the scroll bar. For example, in a scrollbar that runs from 0 to 255, an extent of 128 means that the slider will be half the width of the scrollable area of the scrollbar. JSlider supports the idea of tick marks, lines drawn at certain values along the slider's length. Major tick marks are slightly larger than minor tick marks. To draw tick marks, just specify an interval for major and minor tick marks, and then paint the tick marks: slider.setMajorTickSpacing(48); slider.setMinorTickSpacing(16); slider.setPaintTicks(true); JSlider also supports labeling the ticks with text strings, using the setLabelTable() method. Responding to events from the two components is straightforward. The JScrollBar sends out AdjustmentEvents every time something happens; the JSlider fires off ChangeEvents when its value changes. In our simple example, we display the new value of the changed component in the JLabel at the bottom of the window. Grading scales of Course Project The following grading rubrics are provided for each major phase of the Course Project. 1. User's Manual Points Description Sufficient length to describe the application 4 Manual contains explanation in detail of all relevant areas of the application Contains screen shots of the key interface components 4 Images of each section of the application Operations are explained 4 Detailed operation of each section of the application Written to the user's level and is not technical 4 Must not contain code or any other technical items irrelevant to the users Analysis and design contain sufficient detail to begin construction 4 Application analysis and design contains enough details about the application Subtotal 20   2. Minimum Requirements Points Description Standard header included 2 Must contain program's name, student name, and description of the program Program compiles 2 Program does not have any error Program executes 2 Program runs without any error Created main form 3 Main method exists Created length label 3 Length label Created length textbox 3 Length input text box Created width label 3 Width label Created width textbox 3 Width input text box Created depth label 3 Depth label Created depth textbox 3 Depth input text box Created volume label 3 Volume label Created volume textbox 3 Volume input text box. Make sure this field is read only. Created Calculate button 3 Calculate Volume button Created Calculate button event handler 3 Code to handle the Calculate Volume button. Must handle non-numeric input and null input. Created Exit button 3 Exit button Created Exit button event handler 3 Code to handle the Exit button. Must exit the application and terminate the program. Correct output is displayed 10 When values are entered, the correct results are shown. If no values or non-numeric values are entered, the proper error message should display. Subtotal 55   3. Extended Requirements Points Description Included at least two additional tabs 5 There must be two or more additional tabs as shown under the Course Project Interface document. Each operation is implemented in its own class 10 Each button and/or text field event handler code must be implemented in its own class. Extended operations and classes work as expected 10 The implemented extra tabs must work as expected. Subtotal 25   Course Project Total Points Description Complete Project 100 User's Manual, Pools tab, and Extended Requirements

package wk7;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.text.DecimalFormat;
import javax.swing.*;
public class LandscapingCalculator extends JFrame {
private static final long serialVersionUID = 1L;
private JTabbedPane tab;
private JPanel topPanel;
final JPanel Customers;
final JPanel Contractors;

final JPanel HotTubs;
public LandscapingCalculator() {
super(” Landscaping Calculator”);

tab = new JTabbedPane();
getRootPane().add(tab);
// add tabs to tab
tab.addTab(“Customers”, new Customers());
tab.addTab(“Contractors”, new Contractors());
tab.addTab(“Pools”, new Pools());
tab.addTab(“Hot Tubs”, new HotTubs());

topPanel = new JPanel();
topPanel.setLayout(new BorderLayout());
getContentPane().add(topPanel);
topPanel.add(tab, BorderLayout.CENTER);

setSize(425, 250);
setBackground(Color.blue);
setVisible(true);

}
public static void main(String[] args) {
LandscapingCalculator calcFrame = new LandscapingCalculator();
calcFrame.setSize(425, 250);
calcFrame.setVisible(true);
calcFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
class Customers extends JPanel {
private static final long serialVersionUID = 1L;
public Customers() {
JTextField custName;
JTextField custCity;
JTextField custState;
JTextField custZip;
JTextField custPhone;
JTextField custAdd;
final JTextArea custArea = new JTextArea(6, 30);
final JTextArea custMessage;
JTextArea custAddMessage;
// Add customer button
JButton addCustomer = new JButton(“Add Customer”);
addCustomer.setMnemonic(0);

// Customer Panel
JPanel custPanel = new JPanel();
custArea.setText(“Select Add Customer to add customer. Select Refresh to refresh this pane.”);
custArea.setForeground(Color.orange);
custArea.setLineWrap(true);
custArea.setWrapStyleWord(true);
JButton custRefButton = new JButton(“Refresh”);
custRefButton.setMnemonic(0);
custMessage = new JTextArea(2, 30);
custMessage.setLineWrap(true);
custMessage.setWrapStyleWord(true);
addCustomer.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { // action if button is
// used
new Customer(“Customer”);
}// end actionPerformed()//end action performed
}); // end performed action
custPanel.add(custArea);
custPanel.add(addCustomer);
custPanel.add(custRefButton);
custPanel.add(custMessage);
custRefButton.setMnemonic(‘R’);
custRefButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
custMessage.setText(“”);
try {
File custOpen = new File(“customer.txt”);
FileReader custAreaIn = new FileReader(custOpen);
custArea.read(custAreaIn, custOpen.toString());
custMessage
.setText(“The file exists and can be read from.”);
} catch (IOException e3) {
custMessage.setText(“The file could not be read. ”
+ e3.getMessage());
}
}
});
add(custPanel);
}
class Customer extends JPanel {
private static final long serialVersionUID = 1L;
private String[] states = { “AL”, “AK”, “AZ”, “AR”, “CA”, “CO”, “CT”,
“DE”, “FL”, “GA”, “HI”, “ID”, “IL”, “IN”, “IA”, “KS”, “KY”,
“LA”, “ME”, “MD”, “MA”, “MI”, “MN”, “MS”, “MO”, “MT”, “NE”,
“NV”, “NH”, “NJ”, “NM”, “NY”, “NC”, “ND”, “OH”, “OK”, “OR”,
“PA”, “RI”, “SC”, “SD”, “TN”, “TX”, “UT”, “VT”, “VA”, “WA”,
“WV”, “WI”, “WY” };
private JComboBox StateList = new JComboBox(states);
private JTextField NameText = new JTextField(25);
private JTextField AddressText = new JTextField(25);
private JTextField CityText = new JTextField(25);
private JTextField ZipText = new JTextField(9);
private JTextField PhoneText = new JTextField(10);
private JTextField PopMessageText = new JTextField(30);
private AddCustButtonHandler addCusHandler = new AddCustButtonHandler();
public Customer(String name) {
popUpWindow(name);
}
// Customer and Contractor Pop Up Window
public void popUpWindow(final String name) {
// add components to contractor Pop up window
final JFrame popWindow;
popWindow = new JFrame(name);
popWindow.setSize(425, 350);
popWindow.setLocation(100, 100);
popWindow.setVisible(true);
//popWindow.setDefaultCloseOperation(EXIT_ON_CLOSE);
Container c = new Container();
popWindow.add(c);
c.setLayout(new FlowLayout());
JPanel one = new JPanel();
JPanel two = new JPanel();
JPanel three = new JPanel();
JPanel four = new JPanel();
JPanel five = new JPanel();
JPanel six = new JPanel();
one.add(new JLabel(name + ” Name “));
one.add(NameText);
two.add(new JLabel(“Address “));
two.add(AddressText);
three.add(new JLabel(“City “));
three.add(CityText);
four.add(new JLabel(“State “));
StateList.setSelectedIndex(0);
four.add(StateList);
four.add(new JLabel(“ZIP”));
four.add(ZipText);
four.add(new JLabel(“Phone”));
four.add(PhoneText);
JButton addName = new JButton(“Add ” + name);
addName.setMnemonic(‘A’);
JButton close = new JButton(“Close”);
close.setMnemonic(‘C’);
JButton deleteFile = new JButton(“Delete File”);
deleteFile.setMnemonic(‘D’);
five.add(addName);
five.add(close);
five.add(deleteFile);
PopMessageText.setEditable(false);
PopMessageText.setHorizontalAlignment(JTextField.CENTER);
// message.setOpaque(false);
six.add(PopMessageText);
c.add(one);
c.add(two);
c.add(three);
c.add(four);
c.add(five);
c.add(six);
deleteFile.setToolTipText(“Delete File”);
addName.setToolTipText(“Add ” + name);
close.setToolTipText(“Close”);
if (name == “Customer”)
addName.addActionListener(addCusHandler); // registers listener
close.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
NameText.setText(“”);
AddressText.setText(“”);
CityText.setText(“”);
ZipText.setText(“”);
PhoneText.setText(“”);
PopMessageText.setText(“”);
popWindow.dispose();
}
});
deleteFile.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
PopMessageText.setText(“”);
if (name == “Customer”) {
File file = new File(“Customer.txt”);
boolean cusFileDeleted = file.delete();
if (cusFileDeleted) {
PopMessageText
.setText(“Customer file has been deleted”);
} else {
PopMessageText
.setText(“There was an erron in deleting file”);
}
}
}
});
}// end Pop up window
// Class handler to add customer information to a file
class AddCustButtonHandler implements ActionListener {
public void actionPerformed(ActionEvent addCusHandler) {
int StateIndex;
try {
File file = new File(“Customer.txt”);
boolean success = file.createNewFile();
if (success) {
PopMessageText
.setText(“Customer.txt file created file added”);
} else if (file.canWrite()) {
PopMessageText
.setText(“Writing data to Customer.txt, file added”);
} else {
PopMessageText
.setText(“Cannot create file: Customer.txt”);
}
try {
FileWriter fileW = new FileWriter(“Customer.txt”, true);
fileW.write(NameText.getText());
fileW.write(“,”);
fileW.write(AddressText.getText());
fileW.write(“,”);
fileW.write(CityText.getText());
fileW.write(“,”);
StateIndex = StateList.getSelectedIndex();
fileW.write(states[StateIndex]);
fileW.write(“,”);
fileW.write(ZipText.getText());
fileW.write(“,”);
fileW.write(PhoneText.getText());
fileW.write(“\r\n”);
fileW.close();
PopMessageText
.setText(“A new Customer has been added!”);
FileReader fileR = new FileReader(“Customer.txt”);
BufferedReader buffIn = new BufferedReader(fileR);
buffIn.readLine();
buffIn.close();
}
// Error message if unable to write to file
catch (IOException e1) {
JOptionPane.showMessageDialog(null, e1.getMessage(),
“ERROR”, 2);
}
NameText.setText(“”);
AddressText.setText(“”);
CityText.setText(“”);
ZipText.setText(“”);
PhoneText.setText(“”);
} catch (IOException e1) {
}
}// end actionPerformed method
}// end customer btnHandler
}
}
class Contractors extends JPanel {
private static final long serialVersionUID = 1L;
// contractor variables
JTextField contName;
JTextField contCity;
JTextField contState;
JTextField contZip;
JTextField contPhone;
JTextField contAdd;
public Contractors() {
setLayout(new FlowLayout());
final JTextArea contArea = new JTextArea(6, 30);
final JTextArea contMessage;
JTextArea contAddMessage;
JButton addContractor = new JButton(“Add Contractor”);
addContractor.setMnemonic(‘a’);
// Contractor Panel
JPanel contPanel2 = new JPanel();
contArea.setText(“Select Add Contractor to add contractor. Select Refresh to refresh this pane.”);
contArea.setForeground(Color.orange);
contArea.setLineWrap(true);
contArea.setWrapStyleWord(true);
JButton contRefButton = new JButton(“Refresh”);
contMessage = new JTextArea(2, 30);
contMessage.setLineWrap(true);
contMessage.setWrapStyleWord(true);
addContractor.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { // action if button is
// used
new Contractors();
}// end actionPerformed()//end action performed
}); // end performed action
contPanel2.add(contArea);
contPanel2.add(addContractor);
contPanel2.add(contRefButton);
contPanel2.add(contMessage);
contRefButton.setMnemonic(‘R’);
contRefButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
contMessage.setText(“”);
try {
File contOpen = new File(“contractor.txt”);
FileReader contAreaIn = new FileReader(contOpen);
contArea.read(contAreaIn, contOpen.toString());
contMessage
.setText(“The file exists and can be read from.”);
} catch (IOException e3) {
contMessage.setText(“The file could not be read. ”
+ e3.getMessage());
}
}
});
add(contPanel2);
}
class createContractor extends JPanel {
private String[] states = { “AL”, “AK”, “AZ”, “AR”, “CA”, “CO”, “CT”,
“DE”, “FL”, “GA”, “HI”, “ID”, “IL”, “IN”, “IA”, “KS”, “KY”,
“LA”, “ME”, “MD”, “MA”, “MI”, “MN”, “MS”, “MO”, “MT”, “NE”,
“NV”, “NH”, “NJ”, “NM”, “NY”, “NC”, “ND”, “OH”, “OK”, “OR”,
“PA”, “RI”, “SC”, “SD”, “TN”, “TX”, “UT”, “VT”, “VA”, “WA”,
“WV”, “WI”, “WY” };
private JComboBox StateList = new JComboBox(states);
private JTextField NameText = new JTextField(25);
private JTextField AddressText = new JTextField(25);
private JTextField CityText = new JTextField(25);
private JTextField ZipText = new JTextField(9);
private JTextField PhoneText = new JTextField(10);
private JTextField PopMessageText = new JTextField(30);
private static final long serialVersionUID = 1L;
private AddContButtonHandler addContHandler = new AddContButtonHandler();
public createContractor(String name) {
popUpWindow(name);
}
// Customer and Contractor Pop Up Window
public void popUpWindow(final String name) {
// add components to contractor Pop up window
final JFrame popWindow;
popWindow = new JFrame(name);
popWindow.setSize(425, 350);
popWindow.setLocation(100, 100);
popWindow.setVisible(true);
Container c = new Container();
popWindow.add(c);
c.setLayout(new FlowLayout());
JPanel one = new JPanel();
JPanel two = new JPanel();
JPanel three = new JPanel();
JPanel four = new JPanel();
JPanel five = new JPanel();
JPanel six = new JPanel();
one.add(new JLabel(name + ” Name “));
one.add(NameText);
two.add(new JLabel(“Address “));
two.add(AddressText);
three.add(new JLabel(“City “));
three.add(CityText);
four.add(new JLabel(“State “));
StateList.setSelectedIndex(0);
four.add(StateList);
four.add(new JLabel(“ZIP”));
four.add(ZipText);
four.add(new JLabel(“Phone”));
four.add(PhoneText);
JButton addName = new JButton(“Add ” + name);
addName.setMnemonic(‘A’);
JButton close = new JButton(“Close”);
close.setMnemonic(‘C’);
JButton deleteFile = new JButton(“Delete File”);
deleteFile.setMnemonic(‘D’);
five.add(addName);
five.add(close);
five.add(deleteFile);
PopMessageText.setEditable(false);
PopMessageText.setHorizontalAlignment(JTextField.CENTER);
// message.setOpaque(false);
six.add(PopMessageText);
c.add(one);
c.add(two);
c.add(three);
c.add(four);
c.add(five);
c.add(six);
deleteFile.setToolTipText(“Delete File”);
addName.setToolTipText(“Add ” + name);
close.setToolTipText(“Close”);
if (name == “Contractor”)
addName.addActionListener(addContHandler); // registers listener
close.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
NameText.setText(“”);
AddressText.setText(“”);
CityText.setText(“”);
ZipText.setText(“”);
PhoneText.setText(“”);
PopMessageText.setText(“”);
popWindow.dispose();
}
});
deleteFile.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
PopMessageText.setText(“”);
if (name == “Contractor”) {
File file = new File(“Contractor.txt”);
boolean contFileDeleted = file.delete();
if (contFileDeleted) {
PopMessageText
.setText(“Contractor file has been deleted”);
} else {
PopMessageText
.setText(“There was an erron in deleting file”);
}
}
}
});
} // end Pop up window
// Class handler to add contractor information to a file
class AddContButtonHandler implements ActionListener {
public void actionPerformed(ActionEvent addContHandler) {
int StateIndex;
try {
File file = new File(“Contractor.txt”);
boolean success = file.createNewFile();
if (success) {
PopMessageText
.setText(“Contractor.txt file created file added”);
} else if (file.canWrite()) {
PopMessageText
.setText(“Writing data to Contractor.txt, file added”);
} else {
PopMessageText
.setText(“Cannot create file: Contractor.txt”);
}
try {
FileWriter fileW = new FileWriter(“Contractor.txt”,
true);
fileW.write(NameText.getText());
fileW.write(“,”);
fileW.write(AddressText.getText());
fileW.write(“,”);
fileW.write(CityText.getText());
fileW.write(“,”);
StateIndex = StateList.getSelectedIndex();
fileW.write(states[StateIndex]);
fileW.write(“,”);
fileW.write(ZipText.getText());
fileW.write(“,”);
fileW.write(PhoneText.getText());
fileW.write(“\r\n”);
fileW.close();
PopMessageText
.setText(“A new Contractor has been added!”);
FileReader fileR = new FileReader(“Contractor.txt”);
BufferedReader buffIn = new BufferedReader(fileR);
buffIn.readLine();
buffIn.close();
}
catch (IOException e1) {
JOptionPane.showMessageDialog(null, e1.getMessage(),
“ERROR”, 2); // Will display error message if
// unable
// to write to file
}
NameText.setText(“”);
AddressText.setText(“”);
CityText.setText(“”);
ZipText.setText(“”);
PhoneText.setText(“”);
} catch (IOException e1) {
}
}
}
}
}// end of Constructor class
abstract class Pools extends JPanel{
private static final long serialVersionUID = 1L;
JButton calcVolume;
JButton quit;
JPanel Pools;
JTextField lengthText, widthText, depthText, volumeText;

public Pools() {
setLayout(new FlowLayout());
Pools = new JPanel();
Pools.setLayout(null);

JLabel lengthLabel = new JLabel(
“Enter the pool’s length(ft): “);
lengthLabel.setBounds(20, 15, 160, 20);
Pools.add(lengthLabel);
lengthText = new JTextField();
lengthText.setBounds(170, 15, 150, 20);
Pools.add(lengthText);

JLabel widthLabel = new JLabel(
“Enter the pool’s width(ft): “);
widthLabel.setBounds(20, 60, 160, 20);
Pools.add(widthLabel);

widthText = new JTextField();
widthText.setBounds(170, 60, 150, 20);
Pools.add(widthText);

JLabel depthLabel = new JLabel(
“Enter the pool’s depth(ft): “);
depthLabel.setBounds(20, 100, 160, 20);
Pools.add(depthLabel);
depthText = new JTextField();
depthText.setBounds(170, 100, 150, 20);
Pools.add(depthText);

JLabel volumeLabel = new JLabel(
“The pool volume is:(ft ^3): “);
volumeLabel.setBounds(20, 180, 160, 20);
Pools.add(volumeLabel);
volumeText = new JTextField();
volumeText.setBounds(170, 180, 150, 20);
volumeText.setEditable(false);
Pools.add(volumeText);
JButton calcVolume = new JButton(“Calculate Volume”);
calcVolume.setMnemonic(0);
calcVolume.setBounds(80, 130, 150, 30);
calcVolume.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0){
//calc_volume method for Pools
String lengthString, widthString, depthString;
int length = 0;
int width = 0;
int depth = 0;
lengthString = lengthText.getText();
widthString = widthText.getText();
depthString = depthText.getText();
if (lengthString.length() < 1 || widthString.length() < 1 || depthString.length() < 1) { volumeText.setText("Error! Must enter in all three numbers!!"); return; } length = Integer.parseInt(lengthString); width = Integer.parseInt(widthString); depth = Integer.parseInt(depthString); if (length != 0 || width != 0 || depth != 0) { volumeText.setText((length * width * depth) + ""); } else { volumeText.setText("Error! Must Enter in all three numbers!!"); return; } } }); JButton exit = new JButton("Exit"); exit.setMnemonic(1); exit.setBounds(250, 130, 80, 30); exit.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { System.exit(0); } }); Pools.add(calcVolume); Pools.add(exit); }// end Pools constructor }// end Pools Class class HotTubs extends JPanel { private static final long serialVersionUID = 1L; private JButton calcVolume; private JButton quit; private JPanel HotTubs; JTextField lengthText, widthText, depthText, volumeText; public HotTubs() { setLayout(new FlowLayout()); HotTubs = new JPanel(); HotTubs.setLayout(null); final JTextArea labelTubStatus = new JTextArea(6, 30); final JTextArea textFieldTubResult = new JTextArea(6, 30); final JTextArea textFieldTubWidth = new JTextArea(6, 30); final JRadioButton rdbtnRoundTub = new JRadioButton("RoundTub"); rdbtnRoundTub.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { textFieldTubWidth.setEditable(false); } }); rdbtnRoundTub.setSelected(true); rdbtnRoundTub.setBounds(79, 7, 109, 23); HotTubs.add(rdbtnRoundTub); JRadioButton rdbtnOvalTub = new JRadioButton("Oval Tub"); rdbtnOvalTub.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { textFieldTubWidth.setEditable(true); } }); rdbtnOvalTub.setBounds(201, 7, 109, 23); HotTubs.add(rdbtnOvalTub); ButtonGroup radioBtnGroup = new ButtonGroup(); radioBtnGroup.add(rdbtnRoundTub); radioBtnGroup.add(rdbtnOvalTub); JButton btnCalculateVlmn = new JButton("Calculate Volume"); btnCalculateVlmn.setMnemonic('C'); btnCalculateVlmn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { double width = 0, length = 0, depth = 0, volume = 0; try { if (rdbtnRoundTub.isSelected()) { volume = Math.PI * Math.pow(length / 2.0, 2) * depth; } else { volume = Math.PI * Math.pow(length * width, 2) * depth; } // double volume = calculate volume; DecimalFormat formatter = new DecimalFormat("#,###,###.###"); textFieldTubResult.setText("" + formatter.format(volume)); } catch (NumberFormatException e) { labelTubStatus .setText("Please make sure that all fields are filled and contain valid input!"); } } }); btnCalculateVlmn.setBounds(47, 115, 141, 23); HotTubs.add(btnCalculateVlmn); } }// end HotTub Class

Still stressed from student homework?
Get quality assistance from academic writers!

Order your essay today and save 25% with the discount code LAVENDER