Swimming Pool Calculator

Swimming Pool Calculator

When I run the program the login window doesn't appear...Please help

1)LoginForm.java

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class Login extends JFrame implements ActionListener
{
JButton SUBMIT;
JPanel panel;
JLabel label1,label2;
final JTextField text1,text2;
Login()
{
label1 = new JLabel();
label1.setText("Username:");
text1 = new JTextField(15);

label2 = new JLabel();
label2.setText("Password:");
text2 = new JPasswordField(15);

SUBMIT=new JButton("SUBMIT");

panel=new JPanel(new GridLayout(3,1));
panel.add(label1);
panel.add(text1);
panel.add(label2);
panel.add(text2);
panel.add(SUBMIT);
add(panel,BorderLayout.CENTER);
SUBMIT.addActionListener(this);
setTitle("LOGIN FORM");
}
public void actionPerformed(ActionEvent ae) {
String value1=text1.getText();
String value2=text2.getText();
if (value1.equals("roseindia") && value2.equals("roseindia")) {
********PoolVolume page=new PoolVolume();******LOCAL PAGE VARIABLE NEVER USED*****
}
else{
System.out.println("enter the valid username and password");
JOptionPane.showMessageDialog(this,"Incorrect login or password","Error",JOptionPane.ERROR_MESSAGE);
}
}
}
class LoginForm{
public static void main(String arg[]) {
try {
Login frame=new Login();
frame.setSize(300,100);
frame.setVisible(true);
}
catch(Exception e)
{JOptionPane.showMessageDialog(null, e.getMessage());}
}
}

import java.io.*;
import java.text.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.text.DecimalFormat;

public class PoolVolume extends JFrame{
private JFrame mainFrame;
private JButton calcButton;
private JButton clearButton;
private JButton saveButton;
private JButton exitButton;
private JTextField length;
private JTextField width;
private JTextField average;
private JTextField volume;
private JLabel lengthLabel;
private JLabel widthLabel;
private JLabel averageLabel;
private JLabel volumeLabel;
public PoolVolume() {
this.setLayout(new BorderLayout());
mainFrame = new JFrame("Swimming Pool Volume Calculator");
calcButton = new JButton("Calculate volume");
clearButton = new JButton("Clear");
exitButton = new JButton("Exit");
saveButton=new JButton("Save");
length = new JTextField(5);
width = new JTextField(5);
average = new JTextField(5);
volume = new JTextField(5);
lengthLabel = new JLabel("Enter the length of the swimming pool: ");
widthLabel = new JLabel("Enter the width of the swimming pool: ");
averageLabel = new JLabel("Enter the average dept of the swimming pool: ");
volumeLabel = new JLabel("Swimming pool volume: ");
Container c =
mainFrame.getContentPane();
c.setLayout(
new FlowLayout());
c.add(lengthLabel, BorderLayout.SOUTH);
c.add(length);
c.add(
widthLabel);
c.add(width);
c.add(averageLabel);
c.add(average);
c.add(volumeLabel);
c.add(volume);
c.add(calcButton);
c.add(clearButton);
c.add(exitButton);
c.add(saveButton);
calcButton.setMnemonic('C');
clearButton.setMnemonic('l');
exitButton.setMnemonic('x');
mainFrame.setSize(400,300);
mainFrame.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {System.exit(0);}});

calcButtonHandler chandler =new calcButtonHandler();
calcButton.addActionListener(chandler);
clearButtonHandler lHandler =new clearButtonHandler();
clearButton.addActionListener(lHandler);
exitButtonHandler ehandler =new exitButtonHandler();
exitButton.addActionListener(ehandler);
saveButtonHandler shandler =new saveButtonHandler();
saveButton.addActionListener(shandler);
FocusHandler fhandler =new FocusHandler();
length.addFocusListener(fhandler);
width.addFocusListener(fhandler);
average.addFocusListener(fhandler);
volume.addFocusListener(fhandler);
mainFrame.setVisible(true);
}

class calcButtonHandler implements ActionListener {
public void actionPerformed(ActionEvent e) {
DecimalFormat num =new DecimalFormat(",###.##");
Double cLength, cWidth, cAverage, cVolume, Total;
String sLength, sWidth, sAverage, sVolume;
sLength =length.getText();
cLength = Double.parseDouble(sLength);
sWidth =width.getText();
cWidth = Double.parseDouble(sWidth);
sAverage =average.getText();
cAverage = Double.parseDouble(sAverage);
if(e.getSource() == calcButton) {
Total = cLength * cWidth * cAverage;
volume.setText(num.format(Total));
}
}
}
class clearButtonHandler implements ActionListener {
public void actionPerformed(ActionEvent e){
length.setText("");
width.setText("");
average.setText("");
volume.setText("");
length.grabFocus();
}
}

class exitButtonHandler implements ActionListener {
public void actionPerformed(ActionEvent e){
System.exit(0);
}
}

class saveButtonHandler implements ActionListener {
public void actionPerformed(ActionEvent e){
String value=volume.getText();
try{
File file = new File("output.txt");
FileWriter fstream = new FileWriter(file,true);
BufferedWriter out = new BufferedWriter(fstream);
out.write("The volume of Swimming Pool is "+value);
out.newLine();
out.close();
}
catch(Exception ex){}
}
}

class FocusHandler implements FocusListener {
public void focusGained(FocusEvent e) {
}
public void focusLost(FocusEvent e) {
}
}
public static void main(String args[]){
new PoolVolume();
}
}

View Answers

February 22, 2010 at 8:41 AM

Here is your problems. I think you do not need another class to run your login form just use main method in Login Class.I changed your code as follows
It works fine i ran it no problem.I will List code Below check that out.
The PoolVolume class not changed only Login Class changed by me.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class Login extends JFrame implements ActionListener
{
JButton SUBMIT;
JPanel panel;
JLabel label1,label2;
final JTextField text1,text2;
Login()
{
label1 = new JLabel();
label1.setText("Username:");
text1 = new JTextField(15);

label2 = new JLabel();
label2.setText("Password:");
text2 = new JPasswordField(15);

SUBMIT=new JButton("SUBMIT");

panel=new JPanel(new GridLayout(3,1));
panel.add(label1);
panel.add(text1);
panel.add(label2);
panel.add(text2);
panel.add(SUBMIT);
add(panel,BorderLayout.CENTER);
SUBMIT.addActionListener(this);
setTitle("LOGIN FORM");
}
public void actionPerformed(ActionEvent ae) {
String value1=text1.getText();
String value2=text2.getText();
if (value1.equals("roseindia") && value2.equals("roseindia")) {
PoolVolume page=new PoolVolume();
// If success then dispose login form
this.dispose();
}
else{
System.out.println("enter the valid username and password");
JOptionPane.showMessageDialog(this,"Incorrect login or password","Error",JOptionPane.ERROR_MESSAGE);
}
}


public static void main(String arg[]) {
try {
Login frame=new Login();
frame.setSize(300,100);
frame.setVisible(true);


}
catch(Exception e)
{JOptionPane.showMessageDialog(null, e.getMessage());}
}

}










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
calculator midlet
calculator midlet  give me code calculator midlet in bluetooth application with j2me
simple calculator program in javascript
simple calculator program in javascript  strong textsimple calculator in javascript
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
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
Calculator
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
Version of commons-pool>commons-pool dependency
List of Version of commons-pool>commons-pool dependency
Version of excalibur-pool>excalibur-pool dependency
List of Version of excalibur-pool>excalibur-pool dependency
ModuleNotFoundError: No module named 'Calculator'
ModuleNotFoundError: No module named 'Calculator'  Hi, My Python... 'Calculator' How to remove the ModuleNotFoundError: No module named 'Calculator' error? Thanks   Hi, In your python environment you
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
Version of excalibur-pool>excalibur-pool-api dependency
List of Version of excalibur-pool>excalibur-pool-api dependency
Version of excalibur-pool>excalibur-pool-impl dependency
List of Version of excalibur-pool>excalibur-pool-impl dependency
Version of excalibur-pool>excalibur-pool-instrumented dependency
List of Version of excalibur-pool>excalibur-pool-instrumented dependency
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
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
PHP Tax Calculator - PHP
PHP Tax Calculator  In my project i required a tax calculator that can calculate the property tax
calculator - Java Server Faces Questions
calculator  Some ideas for the project of calculator
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 /> >
ModuleNotFoundError: No module named 'pool'
ModuleNotFoundError: No module named 'pool'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'pool' How to remove the ModuleNotFoundError: No module named 'pool' error
How to write calculator in J2ME program?
How to write calculator in J2ME program?  How to write calculator in J2ME program
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
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
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
ModuleNotFoundError: No module named 'arithmetic-calculator'
ModuleNotFoundError: No module named 'arithmetic-calculator'  Hi...: No module named 'arithmetic-calculator' How to remove the ModuleNotFoundError: No module named 'arithmetic-calculator' error? Thanks   Hi
ModuleNotFoundError: No module named 'currency-calculator'
ModuleNotFoundError: No module named 'currency-calculator'  Hi, My... named 'currency-calculator' How to remove the ModuleNotFoundError: No module named 'currency-calculator' error? Thanks   Hi
ModuleNotFoundError: No module named 'Dewpoint-Calculator'
ModuleNotFoundError: No module named 'Dewpoint-Calculator'  Hi, My... named 'Dewpoint-Calculator' How to remove the ModuleNotFoundError: No module named 'Dewpoint-Calculator' error? Thanks   Hi
ModuleNotFoundError: No module named 'Dewpoint-Calculator'
ModuleNotFoundError: No module named 'Dewpoint-Calculator'  Hi, My... named 'Dewpoint-Calculator' How to remove the ModuleNotFoundError: No module named 'Dewpoint-Calculator' error? Thanks   Hi
ModuleNotFoundError: No module named 'Dewpoint-Calculator'
ModuleNotFoundError: No module named 'Dewpoint-Calculator'  Hi, My... named 'Dewpoint-Calculator' How to remove the ModuleNotFoundError: No module named 'Dewpoint-Calculator' error? Thanks   Hi
ModuleNotFoundError: No module named 'Dewpoint-Calculator'
ModuleNotFoundError: No module named 'Dewpoint-Calculator'  Hi, My... named 'Dewpoint-Calculator' How to remove the ModuleNotFoundError: No module named 'Dewpoint-Calculator' error? Thanks   Hi
ModuleNotFoundError: No module named 'distances-calculator'
ModuleNotFoundError: No module named 'distances-calculator'  Hi...: No module named 'distances-calculator' How to remove the ModuleNotFoundError: No module named 'distances-calculator' error? Thanks   Hi
ModuleNotFoundError: No module named 'engineering-calculator'
ModuleNotFoundError: No module named 'engineering-calculator'  Hi...: No module named 'engineering-calculator' How to remove the ModuleNotFoundError: No module named 'engineering-calculator' error? Thanks   Hi
ModuleNotFoundError: No module named 'fbp_calculator'
ModuleNotFoundError: No module named 'fbp_calculator'  Hi, My... named 'fbp_calculator' How to remove the ModuleNotFoundError: No module named 'fbp_calculator' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'jas-calculator'
ModuleNotFoundError: No module named 'jas-calculator'  Hi, My... named 'jas-calculator' How to remove the ModuleNotFoundError: No module named 'jas-calculator' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'jas-calculator'
ModuleNotFoundError: No module named 'jas-calculator'  Hi, My... named 'jas-calculator' How to remove the ModuleNotFoundError: No module named 'jas-calculator' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'loan-calculator'
ModuleNotFoundError: No module named 'loan-calculator'  Hi, My... named 'loan-calculator' How to remove the ModuleNotFoundError: No module named 'loan-calculator' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'matrix-calculator'
ModuleNotFoundError: No module named 'matrix-calculator'  Hi, My... named 'matrix-calculator' How to remove the ModuleNotFoundError: No module named 'matrix-calculator' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'nn_calculator'
ModuleNotFoundError: No module named 'nn_calculator'  Hi, My... 'nn_calculator' How to remove the ModuleNotFoundError: No module named 'nn_calculator' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'opacity_calculator'
ModuleNotFoundError: No module named 'opacity_calculator'  Hi, My... named 'opacity_calculator' How to remove the ModuleNotFoundError: No module named 'opacity_calculator' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'pomodoro-calculator'
ModuleNotFoundError: No module named 'pomodoro-calculator'  Hi, My... named 'pomodoro-calculator' How to remove the ModuleNotFoundError: No module named 'pomodoro-calculator' error? Thanks   Hi
ModuleNotFoundError: No module named 'pomodoro-calculator'
ModuleNotFoundError: No module named 'pomodoro-calculator'  Hi, My... named 'pomodoro-calculator' How to remove the ModuleNotFoundError: No module named 'pomodoro-calculator' error? Thanks   Hi
ModuleNotFoundError: No module named 'rdt_calculator'
ModuleNotFoundError: No module named 'rdt_calculator'  Hi, My... named 'rdt_calculator' How to remove the ModuleNotFoundError: No module named 'rdt_calculator' error? Thanks   Hi, In your python

Ads