Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4069284
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:28:54+00:00 2026-05-20T16:28:54+00:00

I’ve started to create a GUI that consists of a few tabs. Right now

  • 0

I’ve started to create a GUI that consists of a few tabs. Right now I am focusing on two of them. The Pool tab and the Hot Tub tab. When I first started I got everything to work fine on the pool tab. So I figured since all of the label and text box placement would be the same for the Hot Tub tab I would just copy the coding over. Well, I did that and tried naming all the labels and text boxes the same just with the number 2 after them. It’s not working. Now the Hot Tub tab works, but the Pool tab doesn’t, plus the text boxes are gone. I’m also having alignment issues with the text boxes too, but I think that has to do with the naming of the labels and text boxes, I’m not sure.

MAIN CLASS:

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

public class test extends JFrame implements ActionListener{
private JTabbedPane jtabbedPane;
private JPanel General;
private JPanel Pools;
private JPanel HotTub;

JTextField lengthText, widthText, depthText, volumeText;

public test(){
setTitle("Volume Calculator");
setSize(300, 200);

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

createGeneral();
createPools();

jtabbedPane = new JTabbedPane();
jtabbedPane.addTab("General", General);
jtabbedPane.addTab("Pool", Pools);
jtabbedPane.addTab("Hot Tub", HotTub);

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

JLabel dateLabel = new JLabel("Today's Date");
dateLabel.setBounds(10, 15, 150, 20);
General.add( dateLabel );

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

JButton Close = new JButton("Close");
Close.setBounds(20,50,80,20);
Close.addActionListener(this);
Close.setBackground(Color.white);
General.add(Close);
                         }

/*        CREATE POOL        */

public void createPools(){
    Pools = new JPanel();
    Pools.setLayout( null );
JLabel lengthLabel = new JLabel("Length of 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("Width of 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("Average Depth of 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's 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,20);
    calcVolume.addActionListener(this);
    calcVolume.setBackground(Color.white);
    Pools.add(calcVolume);

JButton Close = new JButton("Close");
    Close.setBounds(350,250,80,20);
    Close.addActionListener(this);
    Close.setBackground(Color.white);
    Pools.add(Close);
                       }


public void actionPerformed(ActionEvent event){
JButton button = (JButton)event.getSource();
String buttonLabel = button.getText();
if ("Close".equalsIgnoreCase(buttonLabel)){
Exit_pressed(); return;
    }
    if ("Calculate Volume".equalsIgnoreCase(buttonLabel)){
        Calculate_Volume(); return;
    }
        if ("Calculate Volume".equalsIgnoreCase(buttonLabel)){
            Calculate_Volume(); 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("Enter All 3 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("Enter All 3 Numbers"); return;
      }
                               }
public static void main(String[] args){
JFrame frame = new test();
frame.setSize(500, 350);
frame.setVisible(true);
}
}

HOT TUB CLASS:

import java.awt.Color;
import java.awt.Component;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;

public abstract class HotTub extends JFrame implements ActionListener{
    private JTabbedPane jtabbedPane;
    private Component HotTub;

    {

    jtabbedPane = new JTabbedPane();
    jtabbedPane.addTab("Hot Tub", HotTub);
    JPanel HotTub;
    JTextField lengthText, widthText, depthText, volumeText;
    /*        CREATE HOT TUB        */


        HotTub = new JPanel();
        HotTub.setLayout( null );
    JLabel lengthLabel = new JLabel("Length of hot tub (ft):");
        lengthLabel.setBounds(10, 15, 260, 20);
        HotTub.add( lengthLabel );
    lengthText = new JTextField();
        lengthText.setBounds(260, 15, 150, 20);
        HotTub.add( lengthText );
    JLabel widthLabel = new JLabel("Width of hot tub (ft):");
        widthLabel.setBounds(10, 60, 260, 20);
        HotTub.add( widthLabel );
    widthText = new JTextField();
        widthText.setBounds(260, 60, 150, 20);
        HotTub.add( widthText );
    JLabel depthLabel = new JLabel("Average Depth of hot tub (ft):");
        depthLabel.setBounds( 10, 100, 260, 20 );
        HotTub.add( depthLabel );
    depthText = new JTextField();
        depthText.setBounds(260, 100, 150, 20);
        HotTub.add( depthText );
    JLabel volumeLabel = new JLabel("The hot tub's volume is:(ft ^3");
        volumeLabel.setBounds(10, 200, 260, 20);
        HotTub.add( volumeLabel );
        volumeText = new JTextField();
        volumeText.setBounds(260, 200, 150, 20);
        volumeText.setEditable(false);
    HotTub.add(volumeText); 

    JButton calcVolume = new JButton("Calculate Volume");
        calcVolume.setBounds(150,250,150,20);
        calcVolume.addActionListener((ActionListener) this);
        calcVolume.setBackground(Color.white);
        HotTub.add(calcVolume);

    JButton Close = new JButton("Close");
        Close.setBounds(350,250,80,20);
        Close.addActionListener((ActionListener) this);
        Close.setBackground(Color.white);
        HotTub.add(Close);
                           }
}

Right now both the Pool tab and the Hot Tub tab are the same. No matter what tab I’m on, the same results show up on each tab. Is it a naming issue?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T16:28:55+00:00Added an answer on May 20, 2026 at 4:28 pm

    in createHotTub() method:

    replace HotTub.add( lengthText ); with HotTub.add( lengthText2 );

    replace HotTub.add( widthText ); with HotTub.add( widthText2 );

    replace HotTub.add( depthText ); with HotTub.add( depthText2 );

    replace HotTub.add( volumeText ); with HotTub.add( volumeText2 );

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I've started to create some Ruby unit tests that use Selenium RC to
I'm trying to create a Tkinter GUI that saves all entry box values into
I'm new to ruby and started to create my *nd toy app. I: Created
thanks in advance for the replies.... I have started to create a network topology
I started a grails application by grails create-app. For modularity, I feel like it
I started to do some experimentation with iisnode and expressjs to create a REST
I want to create a keyboard and mouse hook which will be started as
I wanted to create jquery plugin & started off creating a sample jquery plugin...But
I created a server program that will be started as root. After it is
I started with iPhone programming, and I found that iPhone has a clear picture

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.