I am having some trouble with my Java program. I completed a PoolVolume class project and am trying to add a login and password page before the PoolVolume class starts. I completed the login and password script but can not get the login page to access the next class page. I ran both codes and they work by themselves but will not work together. Can anyone take a look at it and let me know where I am going wrong and how to fix. I am just stumped!! Thank you!!
Login class and PoolVolume class are part of LoginForm Project
Login:
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("mike") && value2.equals("3180")) {
PoolVolume page=new PoolVolume();
}
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());}
}
}
***************Not going into the PoolVolume Page
Next Page
PoolVolume Class:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.text.*;
import java.text.DecimalFormat;
public class PoolVolume extends JFrame implements ActionListener{
private JFrame mainFrame;
private JTabbedPane jtabbedPane;
private JPanel general;
private JPanel pools;
private JPanel options;
private JComponent date;
JTextField lengthText, widthText, depthText, volumeText;
public PoolVolume(){
setTitle( "Montalbano Pools, Inc." );
setSize( 300, 200 );
setBackground( Color.blue);
JPanel topPanel = new JPanel();
topPanel.setLayout( new BorderLayout() );
getContentPane().add( topPanel );
createGeneral();
createPools();
createOptions();
jtabbedPane = new JTabbedPane();
jtabbedPane.addTab( "Date", general );
jtabbedPane.addTab( "Pool Volume Calculator", pools );
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:" );
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:" );
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:" );
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:" );
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 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)){
JOptionPane.showMessageDialog(null, "IF YOU WANT TO CHANGE THE NAME OF THE COMPANY, THEN BUY ME OUT!!!");
}
if ("Calculate Volume".equalsIgnoreCase(buttonLabel)){
Calculate_Volume(); return;
}
if ("Options".equalsIgnoreCase(buttonLabel)){
Options(); return;
}
}
private void Exit_pressed(){
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 Options(){}
public static void main(String[] args){
JFrame frame = new PoolVolume();
frame.setSize(525, 350);
frame.setVisible(true);
}
}