Here is my assignment:
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 final 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 final project.
Final Project Overview
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 final 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.
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.
Customers TabThe 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.
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.
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.
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 TabThe 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:
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 TubWhen 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.
Oval Tub
When Oval Tub is selected, the width field is opened up:
The formula used to calculate the volume is
(Pi * (length/2 * 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).
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:The Length Calc tab offers the user a length converter (millimeters, meters, yards, feet, and inches).
Here is where I am having problems: (by the way...I am using NetBeans)
- The size that I am setting for my JTextFields are not setting correctly.
- How can I place the JLabels where I want them to be placed. For example: I want some sort of text or JTextField/textAreaField after some of my JButtons.
I know I have more questions, but right now I'm just trying to get the general layout of this program before trying to get the functionality running. I have screenshots, but I don't know how to place it on here. - All I am asking for is a little push in the right direction. Maybe some sample codes that may work with my code. If anybody is willing to help work on this with me, please message me.
This is the code that I have so far:
package finalproject;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.*;
import java.awt.event.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.awt.event.FocusListener;
public class FinalProject extends JFrame {
public FinalProject(){ //constructor for the tabbed frame
//creating the title
setTitle("Pools, Hot Tubs, and Spas: CIS355 Final Project");
setSize(400,400); //set size
//creating the object
JTabbedPane jtp = new JTabbedPane();
//creating the template on the windowed application
getContentPane().add(jtp);
JPanel jp1 = new JPanel();//creating 1st tab (General)
JPanel jp2 = new JPanel();//creating 2nd tab (Options)
JPanel jp3 = new JPanel();//creating 3rd tab (Customers)
JPanel jp4 = new JPanel();//creating 4th tab (Contractors)
JPanel jp5 = new JPanel();//creating 5th tab (Pools)
JPanel jp6 = new JPanel();//creating 6th tab (Hot Tubs)
JPanel jp7 = new JPanel();//creating 7th tab (Temp Calc)
JPanel jp8 = new JPanel();//creating 8th tab (Length Calc)
//setting information within each tab
JLabel label1 = new JLabel();
Date myDate = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String myDateString = sdf.format(myDate);
label1.setText("Today's Date: " + myDate);
jp1.add(label1);
JLabel label2 = new JLabel("Change Company Name:");
JTextField options = new JTextField(30);
options.setSize(200,150);
jp2.add(label2);
jp2.add(options);
JLabel label3 = new JLabel();
JTextField customers = new JTextField(30);
customers.setSize(350,200);
JLabel message = new JLabel("File customer.txt does not exist yet -");
JLabel message2 = new JLabel("will be created when you add customers!");
jp3.add(customers);
jp3.add(label3);
JLabel label4 = new JLabel();
jp4.add(label4);
JLabel plength = new JLabel("Enter the pool's length(ft): ");
JTextField PLength = new JTextField(8);
JLabel pwidth = new JLabel("Enter the pool's width(ft): ");
JTextField PWidth = new JTextField(8);
JLabel pdepth = new JLabel("Enter the pool's depth(ft): ");
JTextField PDepth = new JTextField(8);
JLabel PVol = new JLabel("The pool's volume is(ft^3): ");
jp5.add(plength);
jp5.add(PLength);
jp5.add(pwidth);
jp5.add(PWidth);
jp5.add(pdepth);
jp5.add(PDepth);
JLabel label6 = new JLabel();
jp6.add(label6);
JLabel label7 = new JLabel();
jp7.add(label7);
JLabel label8 = new JLabel();
jp8.add(label8);
//adding the tabs
jtp.addTab("General", jp1);
jtp.addTab("Options", jp2);
jtp.addTab("Customers", jp3);
jtp.addTab("Contractors", jp4);
jtp.addTab("Pools", jp5);
jtp.addTab("Hot Tubs", jp6);
jtp.addTab("Temp Calc", jp7);
jtp.addTab("Length Calc", jp8);
//creating new button
JButton exit = new JButton("Exit");
exit.setMnemonic('x');
jp1.add(exit);
exit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
});
JButton NewName = new JButton("Set New Name");
JButton Exit2 = new JButton("Exit");
jp2.add(NewName);
NewName.setMnemonic('s');
jp2.add(Exit2);
Exit2.setMnemonic('x');
Exit2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
});
JButton Exit3 = new JButton("Exit");
JButton AddCustomer = new JButton("Add Customer");
JButton Refresh = new JButton("Refresh");
jp3.add(Exit3);
Exit3.setMnemonic('x');
jp3.add(AddCustomer);
AddCustomer.setMnemonic('a');
jp3.add(Refresh);
jp3.add(message);
jp3.add(message2);
Refresh.setMnemonic('r');
Exit3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
});
JButton Exit4 = new JButton("Exit");
JButton AddContractor = new JButton("Add Contractor");
JButton Refresh2 = new JButton("Refresh");
jp4.add(Exit4);
Exit4.setMnemonic('x');
jp4.add(AddCustomer);
AddCustomer.setMnemonic('a');
jp4.add(Refresh);
Refresh.setMnemonic('r');
Exit4.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
});
JButton CalcVol = new JButton("Calculate Volume");
JButton Exit5 = new JButton("Exit");
jp5.add(CalcVol);
CalcVol.setMnemonic('c');
jp5.add(Exit5);
jp5.add(PVol);
JTextField pvol = new JTextField(8);
jp5.add(pvol);
Exit5.setMnemonic('x');
Exit5.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
});
JButton CalcVol2 = new JButton("Calculate Volume");
JButton Exit6 = new JButton("Exit");
jp6.add(CalcVol2);
CalcVol2.setMnemonic('c');
jp6.add(Exit6);
Exit6.setMnemonic('x');
Exit6.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
});
JButton Convert = new JButton("Convert");
JButton Exit7 = new JButton("Exit");
jp7.add(Convert);
Convert.setMnemonic('c');
jp7.add(Exit7);
Exit7.setMnemonic('x');
Exit7.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
});
JButton Convert2 = new JButton("Convert");
JButton Exit8 = new JButton("Exit");
jp8.add(Convert2);
Convert.setMnemonic('c');
jp8.add(Exit8);
Exit8.setMnemonic('x');
Exit8.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
});
FocusListener clearFields = new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
}
@Override
public void focusGained(FocusEvent e) {
}
};
//Adding Action Listener that reacts to the test button called "Press"
ButtonHandler phandler = new ButtonHandler();
NewName.addActionListener(phandler);
setVisible(true);//setting true so it can be seen
}
private static class ButtonHandler implements ActionListener{
@Override
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(null,"New Company Name Saved", "What happened?", JOptionPane.INFORMATION_MESSAGE);
}
public ButtonHandler() {
}
}
public static void main(String[] args) {
FinalProject finalProject = new FinalProject();
}
}