Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Swimming Pool Calculator
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Christina
Swimming Pool Calculator
3 Answer(s)      4 years and 7 months ago
Posted in : Java Beginners


Okay, so I tried making the program with this coding:

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import java.text.SimpleDateFormat;


public class SwimmCalc extends JFrame implements ActionListener{
private JTabbedPane jtabbedPane;
private JPanel general;
private JPanel pools;
private JPanel hotTubs;
private JPanel tempCalc;
private JPanel customers;
private JPanel options;
private JComponent date;
JTextField lengthText, widthText, depthText, volumeText;

public MainPool(){
setTitle( "Pools," );
setSize( 300, 200 );
setBackground( Color.blue);

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

createGeneral();
createPools();
createHotTubs();
createTempCalc();
createCustomers();
createOptions();

jtabbedPane = new JTabbedPane();
jtabbedPane.addTab( "General", general );
jtabbedPane.addTab( "Pools", pools );
jtabbedPane.addTab( "Hot Tubs", hotTubs );
jtabbedPane.addTab( "Temp Calculator", tempCalc );
jtabbedPane.addTab( "Customers", customers );
jtabbedPane.addTab( "Options", options );

topPanel.add(jtabbedPane, BorderLayout.CENTER );
}
public void createGeneral(){
general = new JPanel();
general.setLayout( null );

JLabel dateLabel = new JLabel( "Todays Date" );
dateLabel.setBounds( 10, 15, 150, 20 );
general.add( dateLabel );

JFormattedTextField date = new JFormattedTextField(
java.util.Calendar.getInstance().getTime());
date.setEditable(false);
date.setBounds(150,15,150,20);
general.add(date);

JButton quit = new JButton("Quit");
quit.setBounds(10,80,150,30);
quit.addActionListener(this);
quit.setBackground(Color.red);
general.add(quit);
}
public void createPools(){
pools = new JPanel();
pools.setLayout( null );

JLabel lengthLabel = new JLabel( "Enter the length of swimming pool(ft):" );
lengthLabel.setBounds( 10, 15, 260, 20 );
pools.add( lengthLabel );

lengthText = new JTextField();
lengthText.setBounds( 260, 15, 150, 20 );
pools.add( lengthText );

JLabel widthLabel = new JLabel( "Enter the width of the swimming pool(ft):" );
widthLabel.setBounds( 10, 60, 260, 20 );
pools.add( widthLabel );

widthText = new JTextField();
widthText.setBounds( 260, 60, 150, 20 );
pools.add( widthText );

JLabel depthLabel = new JLabel( "Enter the average depth the swimming pool(ft):" );
depthLabel.setBounds( 10, 100, 260, 20 );
pools.add( depthLabel );

depthText = new JTextField();
depthText.setBounds( 260, 100, 150, 20 );
pools.add( depthText );

JLabel volumeLabel = new JLabel( "The pool volume is:(ft ^3" );
volumeLabel.setBounds( 10, 200, 260, 20 );
pools.add( volumeLabel );

volumeText = new JTextField();
volumeText.setBounds( 260, 200, 150, 20 );
volumeText.setEditable(false);
pools.add( volumeText );
JButton calcVolume = new JButton("Calculate Volume");
calcVolume.setBounds(150,250,150,30);
calcVolume.addActionListener(this);
calcVolume.setBackground(Color.yellow);
pools.add(calcVolume);

JButton quit = new JButton("Quit");
quit.setBounds(350,250,80,30);
quit.addActionListener(this);
quit.setBackground(Color.red);
pools.add(quit);
}
public void createHotTubs(){
hotTubs = new JPanel();
hotTubs.setLayout( new GridLayout( 3, 2 ) );
hotTubs.add( new JLabel( "Field 1:" ) );
hotTubs.add( new TextArea() );
hotTubs.add( new JLabel( "Field 2:" ) );
hotTubs.add( new TextArea() );
hotTubs.add( new JLabel( "Field 3:" ) );
hotTubs.add( new TextArea() );
}
public void createTempCalc(){
tempCalc = new JPanel();
tempCalc.setLayout( null );
JLabel tempLabel = new JLabel( "Enter temperature:" );
tempLabel.setBounds( 10, 15, 260, 20 );
tempCalc.add( tempLabel );

JTextField temp = new JTextField();
temp.setBounds( 260, 15, 150, 20 );
tempCalc.add( temp );

JLabel resultsLabel = new JLabel( "Calculated Temp:" );
resultsLabel.setBounds( 10, 60, 260, 20 );
tempCalc.add( resultsLabel );

JTextField results = new JTextField();
results.setBounds( 260, 60, 150, 20 );
results.setEditable(false);
tempCalc.add( results );

JButton calcVol = new JButton("Calculate Volume");
calcVol.setBounds(100,115,150,30);
calcVol.addActionListener(this);
calcVol.setBackground(Color.yellow);
tempCalc.add(calcVol);

JButton quit = new JButton("Quit");
quit.setBounds(250,115,80,30);
quit.addActionListener(this);
quit.setBackground(Color.red);
tempCalc.add(quit);
}
public void createCustomers(){}
public void createOptions()
{
options = new JPanel();
options.setLayout( null );
JLabel labelOptions = new JLabel( "Change Company Name:" );
labelOptions.setBounds( 150, 50, 150, 20 );
options.add( labelOptions );

JTextField newTitle = new JTextField();
newTitle.setBounds( 150, 70, 150, 20 );
options.add( newTitle );

JButton newName = new JButton("Set New Name");
newName.setBounds(100,115,150,30);
newName.addActionListener(this);
newName.setBackground(Color.yellow);
options.add(newName);

JButton quit = new JButton("Quit");
quit.setBounds(250,115,80,30);
quit.addActionListener(this);
quit.setBackground(Color.red);
options.add(quit);
}
public void actionPerformed(ActionEvent event){
JButton button = (JButton)event.getSource();
String buttonLabel = button.getText();
if ("Quit".equalsIgnoreCase(buttonLabel)){
Exit_pressed(); return;
}
if ("Set New Name".equalsIgnoreCase(buttonLabel)){
New_Name(); return;
}
if ("Calculate Volume".equalsIgnoreCase(buttonLabel)){
Calculate_Volume(); return;
}
if ("Customers".equalsIgnoreCase(buttonLabel)){
Customers(); return;
}
if ("Calculate Volume".equalsIgnoreCase(buttonLabel)){
Calculate_Volume(); return;
}
if ("Options".equalsIgnoreCase(buttonLabel)){
Options(); return;
}
}
private void Exit_pressed(){
System.exit(0);
}
private void New_Name(){
System.exit(0);
}
private void Calculate_Volume(){
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;
}
}
private void Customers(){}
private void Options(){}
public static void main(String[] args){
JFrame frame = new MainPool();
frame.setSize(525, 350);
frame.setVisible(true);
}

}


However there is an error at line 20 saying the return type is missing?? Any help please?!?!

Advertisement
View Answers

April 6, 2010 at 11:50 AM


Hi Friend,

You have defined the class name 'SwimmCalc' and you have declared the constructor with different name. Therefore, you have got that error. We have modified your code:

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import java.text.SimpleDateFormat;

public class SwimmCalc extends JFrame implements ActionListener{
private JTabbedPane jtabbedPane;
private JPanel general;
private JPanel pools;
private JPanel hotTubs;
private JPanel tempCalc;
private JPanel customers;
private JPanel options;
private JComponent date;
JTextField lengthText, widthText, depthText, volumeText;

public SwimmCalc(){
setTitle( "Pools," );
setSize( 300, 200 );
setBackground( Color.blue);

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

createGeneral();
createPools();
createHotTubs();
createTempCalc();
createCustomers();
createOptions();

jtabbedPane = new JTabbedPane();
jtabbedPane.addTab( "General", general );
jtabbedPane.addTab( "Pools", pools );
jtabbedPane.addTab( "Hot Tubs", hotTubs );
jtabbedPane.addTab( "Temp Calculator", tempCalc );
jtabbedPane.addTab( "Customers", customers );
jtabbedPane.addTab( "Options", options );

topPanel.add(jtabbedPane, BorderLayout.CENTER );
}
public void createGeneral(){
general = new JPanel();
general.setLayout( null );

JLabel dateLabel = new JLabel( "Todays Date" );
dateLabel.setBounds( 10, 15, 150, 20 );
general.add( dateLabel );

JFormattedTextField date = new JFormattedTextField(
java.util.Calendar.getInstance().getTime());
date.setEditable(false);
date.setBounds(150,15,150,20);
general.add(date);

JButton quit = new JButton("Quit");
quit.setBounds(10,80,150,30);
quit.addActionListener(this);
quit.setBackground(Color.red);
general.add(quit);
}
public void createPools(){
pools = new JPanel();
pools.setLayout( null );

JLabel lengthLabel = new JLabel( "Enter the length of swimming pool(ft):" );
lengthLabel.setBounds( 10, 15, 260, 20 );
pools.add( lengthLabel );

lengthText = new JTextField();
lengthText.setBounds( 260, 15, 150, 20 );
pools.add( lengthText );

JLabel widthLabel = new JLabel( "Enter the width of the swimming pool(ft):" );
widthLabel.setBounds( 10, 60, 260, 20 );
pools.add( widthLabel );

widthText = new JTextField();
widthText.setBounds( 260, 60, 150, 20 );
pools.add( widthText );

JLabel depthLabel = new JLabel( "Enter the average depth the swimming pool(ft):" );
depthLabel.setBounds( 10, 100, 260, 20 );
pools.add( depthLabel );

depthText = new JTextField();
depthText.setBounds( 260, 100, 150, 20 );
pools.add( depthText );

JLabel volumeLabel = new JLabel( "The pool volume is:(ft ^3" );
volumeLabel.setBounds( 10, 200, 260, 20 );
pools.add( volumeLabel );

volumeText = new JTextField();
volumeText.setBounds( 260, 200, 150, 20 );
volumeText.setEditable(false);
pools.add( volumeText );


April 6, 2010 at 11:55 AM


continue..

JButton calcVolume = new JButton("Calculate Volume");
calcVolume.setBounds(150,250,150,30);
calcVolume.addActionListener(this);
calcVolume.setBackground(Color.yellow);
pools.add(calcVolume);

JButton quit = new JButton("Quit");
quit.setBounds(350,250,80,30);
quit.addActionListener(this);
quit.setBackground(Color.red);
pools.add(quit);
}
public void createHotTubs(){
hotTubs = new JPanel();
hotTubs.setLayout( new GridLayout( 3, 2 ) );
hotTubs.add( new JLabel( "Field 1:" ) );
hotTubs.add( new TextArea() );
hotTubs.add( new JLabel( "Field 2:" ) );
hotTubs.add( new TextArea() );
hotTubs.add( new JLabel( "Field 3:" ) );
hotTubs.add( new TextArea() );
}
public void createTempCalc(){
tempCalc = new JPanel();
tempCalc.setLayout( null );
JLabel tempLabel = new JLabel( "Enter temperature:" );
tempLabel.setBounds( 10, 15, 260, 20 );
tempCalc.add( tempLabel );

JTextField temp = new JTextField();
temp.setBounds( 260, 15, 150, 20 );
tempCalc.add( temp );

JLabel resultsLabel = new JLabel( "Calculated Temp:" );
resultsLabel.setBounds( 10, 60, 260, 20 );
tempCalc.add( resultsLabel );

JTextField results = new JTextField();
results.setBounds( 260, 60, 150, 20 );
results.setEditable(false);
tempCalc.add( results );

JButton calcVol = new JButton("Calculate Volume");
calcVol.setBounds(100,115,150,30);
calcVol.addActionListener(this);
calcVol.setBackground(Color.yellow);
tempCalc.add(calcVol);

JButton quit = new JButton("Quit");
quit.setBounds(250,115,80,30);
quit.addActionListener(this);
quit.setBackground(Color.red);
tempCalc.add(quit);
}
public void createCustomers(){}
public void createOptions()
{
options = new JPanel();
options.setLayout( null );
JLabel labelOptions = new JLabel( "Change Company Name:" );
labelOptions.setBounds( 150, 50, 150, 20 );
options.add( labelOptions );

JTextField newTitle = new JTextField();
newTitle.setBounds( 150, 70, 150, 20 );
options.add( newTitle );

JButton newName = new JButton("Set New Name");
newName.setBounds(100,115,150,30);
newName.addActionListener(this);
newName.setBackground(Color.yellow);
options.add(newName);

JButton quit = new JButton("Quit");
quit.setBounds(250,115,80,30);
quit.addActionListener(this);
quit.setBackground(Color.red);
options.add(quit);
}
public void actionPerformed(ActionEvent event){
JButton button = (JButton)event.getSource();
String buttonLabel = button.getText();
if ("Quit".equalsIgnoreCase(buttonLabel)){
Exit_pressed(); return;
}
if ("Set New Name".equalsIgnoreCase(buttonLabel)){
New_Name(); return;
}
if ("Calculate Volume".equalsIgnoreCase(buttonLabel)){
Calculate_Volume(); return;
}
if ("Customers".equalsIgnoreCase(buttonLabel)){
Customers(); return;
}
if ("Calculate Volume".equalsIgnoreCase(buttonLabel)){
Calculate_Volume(); return;
}
if ("Options".equalsIgnoreCase(buttonLabel)){
Options(); return;
}
}


April 6, 2010 at 11:55 AM


continue..

private void Exit_pressed(){
System.exit(0);
}
private void New_Name(){
System.exit(0);
}
private void Calculate_Volume(){
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;
}
}
private void Customers(){}
private void Options(){}
public static void main(String[] args){
JFrame frame = new SwimmCalc();
frame.setSize(525, 350);
frame.setVisible(true);
}

}

Thanks


Related Tutorials/Questions & Answers:
swimming pool calculator
swimming pool calculator  i'm writing a program to calculate the measurements of a swimming pool & a hot tub. and then the user can enter... of swimming pool(ft):"); lengthLabel.setBounds(10, 15, 260, 20
Swimming Pool Calculator - Java Beginners
PoolVolume() { mainFrame = new JFrame("Swimming Pool Volume Calculator...Swimming Pool Calculator  I have to write a program to calculate the volume of a swimming pool. The assignment is as follows: This Swimming Pool
Advertisements
Swimming Pool Calculator - Java Beginners
()); mainFrame = new JFrame("Swimming Pool Volume Calculator"); calcButton = new...Swimming Pool Calculator  When I run the program the login window... JTextField(5); lengthLabel = new JLabel("Enter the length of the swimming pool
Swimming Pool Calculator - Java Beginners
Swimming Pool Calculator  Okay, so I tried making the program... ); JLabel lengthLabel = new JLabel( "Enter the length of swimming pool(ft... of the swimming pool(ft):" ); widthLabel.setBounds( 10, 60, 260, 20 ); pools.add
POOL
a variety of services to customers who own swimming pools, including cleaning and filling pools. Create pool class that calculates the price of a service call... on the amount of time it will take to fill a customer's pool with water. Table below
Calculator
Calculator  need a simple java program to degin a CALCULATOR without using ADVANCED JAVA....   Calculator in Java Swing
Java swimming application
Java swimming application  In deep water associates operate a business that offers a variety of services to customers who own swimming pools, including cleaning and filling pools. Create pool class that calculates the price
Pool Chlorine
Pool Chlorine  *** Deleted by Admin ***** Pool Chlorine Watson's of Cincinnati is a toy store for adults offering above ground pools, pool supplies, Envisions Home Theater electronics, home theater furniture, casual patio
Pool Chemicals
Pool Chemicals  **delted by admin *** a toy store **deleted by admin** offering above ground pools, pool supplies, Envisions Home Theater electronics, home theater furniture, casual patio furniture, spas & hot tubs etc
calculator midlet
calculator midlet  give me code calculator midlet in bluetooth application with j2me
threads & autorelease pool
threads & autorelease pool  How to set autorelease pool for NSThread method in Objective C?   [NSThread detachNewThreadSelector:@selector... {   NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];   //Do stuff   [pool release
Calculator class
Calculator class  I am a beginner in Eclipse. I have to do a program called calculator that adds numbers. This is my code so far: //Margaret //ICS... class Calculator extends JFrame implements ActionListener { JTextField text
simple calculator program in javascript
simple calculator program in javascript  strong textsimple calculator in javascript
Java-Connection Pool - JDBC
Java-Connection Pool  How can I create a connection pool. My database is MS SQL server 2000(username-sa, pwd-admin) and my application server is Weblogic 8. Which is the best approach to create a connection pool? Kindly help
Java-Connection Pool - JDBC
Java-Connection Pool  How can I create a connection pool. My database... is Weblogic 8. Which is the best approach to create a connection pool?  Hi friend,import java.sql.*;import java.io.*;public class ConnectionPool
Enhancement for connection pool in DBAcess.java
Enhancement for connection pool in DBAcess.java  package spo.db... database connection pool."); else return connection1; } public... have try to make some modification to improve current connection pool
thread program for calculator implementation
thread program for calculator implementation  Hi i'm prem i need calculator progrm in java that are implemented by Thread interface.....pls strong text
base calculator.. - Java Beginners
base calculator..  Help, i need some help about a base calculator.. i don't know how to start
A connection pool with multiple user ID.
A connection pool with multiple user ID.  Can I set up a connection pool with multiple user IDs? The single ID we are forced to use causes problems when debugging the DBMS
Program for Calculator - Swing AWT
Program for Calculator  write a program for calculator?  Hi Friend, Please visit the following link: http://www.roseindia.net/java/example/java/swing/calculator-in-swing.shtml Hope that it will be helpful
calculator - Java Interview Questions
calculator  create calculator by java code  Hi Friend, Please visit the following link: http://www.roseindia.net/java/example/java/swing/calculator-in-swing.shtml Thanks
how to writw connection pool coding
how to writw connection pool coding  java connection poolprint("code sample
Questions about Java's String pool
Questions about Java's String pool  Questions about Java's String pool
PHP Tax Calculator - PHP
PHP Tax Calculator  In my project i required a tax calculator that can calculate the property tax
simple calculator - Java Beginners
simple calculator  how can i create a simple calculator using java codes?  Hi Friend, Please visit the following link: http://www.roseindia.net/java/example/java/swing/calculator-in-swing.shtml Thanks
Calculator - JSP-Servlet
Calculator  Dear Deepak Sir, Calculator program is avilable in Jsp... calculator program in jsp function checkValue(){ var msg...; } Simple calculator program in jsp /> >
calculator - Java Server Faces Questions
calculator  Some ideas for the project of calculator
matrix calculator - Java Beginners
matrix calculator  hi..... can you help me in writing source code of matrix calculator in java... i know you are the best you can do it!!! show yourself
Scientific Calculator - Java Beginners
Scientific Calculator  Develop a scientific calculator using even-driven programming paradigm of Java.? Thanks in ADVANCE  Hi Friend, Please visit the following link: http://www.roseindia.net/tutorial/java
How to write calculator in J2ME program?
How to write calculator in J2ME program?  How to write calculator in J2ME program
 

 

 

DMCA.com