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 6352461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:12:35+00:00 2026-05-24T22:12:35+00:00

import java.io.*; import javax.swing.*; import java.awt.event.*; import java.awt.*; import java.text.DecimalFormat; public class Final extends

  • 0
import java.io.*;
import javax.swing.*;

import java.awt.event.*;
import java.awt.*;
import java.text.DecimalFormat;

public class Final extends JFrame 
{
private JButton calcButton, exitButton;
private JButton pcalcButton, pexitButton;
private JTextField plength, pwidth, pdepth, pvolume;
private JTextField hlength, hwidth, hdepth, hvolume;
private JLabel lengthLabel, widthLabel, depthLabel, volumeLabel;
private JRadioButton roundrButton, ovalrButton;

public  Final()
{
super( "Final" );

JTabbedPane tab = new JTabbedPane();
// constructing the first panel
JPanel p1 = new JPanel(new GridLayout(5,1));
pcalcButton = new JButton("Calculate Volume");
pexitButton = new JButton("Exit");
plength = new JTextField(5);
pwidth = new JTextField(5);
pdepth = new JTextField(5);
pvolume = new JTextField(5);
lengthLabel = new JLabel("Enter the pool's length (ft):");
widthLabel = new JLabel("Enter the pool's width (ft):");
depthLabel = new JLabel("Enter the pool's depth (ft):");
volumeLabel = new JLabel("The pool's volume (ft^3):");
p1.add(lengthLabel);
p1.add(plength);
p1.add(widthLabel);
p1.add(pwidth);
p1.add(depthLabel);
p1.add(pdepth);
p1.add(volumeLabel);
p1.add(pvolume);
p1.add(pcalcButton);
p1.add(pexitButton);
tab.addTab( "Pools", null, p1, " Panel #1" );

calcButtonHandler chandler =new calcButtonHandler();
pcalcButton.addActionListener(chandler);
exitButtonHandler ehandler =new exitButtonHandler();
pexitButton.addActionListener(ehandler);
FocusHandler fhandler =new FocusHandler();
plength.addFocusListener(fhandler);
pwidth.addFocusListener(fhandler);
pdepth.addFocusListener(fhandler);
pvolume.addFocusListener(fhandler);

// constructing the second panel
JPanel p2 = new JPanel(new GridLayout(6,1));
ButtonGroup tubtype = new ButtonGroup();
roundrButton = new JRadioButton("Round", true);
roundrButton.setActionCommand("round");
tubtype.add(roundrButton);
ovalrButton = new JRadioButton("Oval", false);
ovalrButton.setActionCommand("oval");
tubtype.add(ovalrButton);
calcButton = new JButton("Calculate Volume");
exitButton = new JButton("Exit");
hlength = new JTextField(5);
hwidth = new JTextField(5);
hdepth = new JTextField(5);
hvolume = new JTextField(5);
lengthLabel = new JLabel("Enter the tub's length (ft):");
widthLabel = new JLabel("Enter the tub's width (ft):");
depthLabel = new JLabel("Enter the tub's depth (ft):");
volumeLabel = new JLabel("The tub's volume (ft^3):");
p2.add(roundrButton);
p2.add(ovalrButton);
p2.add(lengthLabel);
p2.add(hlength);
p2.add(widthLabel);
p2.add(hwidth);
p2.add(depthLabel);
p2.add(hdepth);
p2.add(volumeLabel);
p2.add(hvolume);
p2.add(calcButton);
p2.add(exitButton);
tab.addTab( "Hot Tubs", null, p2, " Panel #1" );

calcButtonHandler2 ihandler =new calcButtonHandler2();
calcButton.addActionListener(ihandler);
exitButtonHandler ghandler =new exitButtonHandler();
exitButton.addActionListener(ghandler);
FocusHandler hhandler =new FocusHandler();
hlength.addFocusListener(hhandler);
hwidth.addFocusListener(hhandler);
hdepth.addFocusListener(hhandler);
hvolume.addFocusListener(hhandler);

// add JTabbedPane to container
getContentPane().add( tab );
setSize( 550, 500 );
setVisible( true );
} 
public class calcButtonHandler implements ActionListener {
public void actionPerformed(ActionEvent e) {
    DecimalFormat num =new DecimalFormat(",###.##");
    double sLength, sWidth, sdepth, Total;

    sLength = Double.parseDouble(plength.getText());

    sWidth = Double.parseDouble(pwidth.getText());

    sdepth = Double.parseDouble(pdepth.getText());

    if(e.getSource() == pcalcButton) {
        Total = sLength * sWidth * sdepth;
        pvolume.setText(num.format(Total));
        try{
            String value=pvolume.getText();
            File file = new File("output.txt");
            FileWriter fstream = new FileWriter(file,true);
            BufferedWriter out = new BufferedWriter(fstream);
            out.write("Length= "+sLength+", Width= "+sWidth+", Depth= "+sdepth+" so the volume of Swimming Pool is "+value);
            out.newLine();
            out.close();
        }
        catch(Exception ex){}
    }
}
}

public class calcButtonHandler2 implements ActionListener {
public void actionPerformed(ActionEvent g) {
    DecimalFormat num =new DecimalFormat(",###.##");
    double cLength, cWidth, cdepth, Total;

    cLength = Double.parseDouble(hlength.getText());

    cWidth = Double.parseDouble(hwidth.getText());

    cdepth = Double.parseDouble(hdepth.getText());

    try
    {

        if(roundrButton.isSelected())//**roundrButton cannot be resolved
        {
            Total = Math.PI * Math.pow(cLength / 2.0, 2) * cdepth;
        }
        else
    {
            Total = Math.PI * Math.pow(cLength * cWidth, 2) * cdepth;
    }
        hvolume.setText(""+num.format(Total));
    }
 catch(Exception ex){}
}
}
}



public class exitButtonHandler implements ActionListener { //**The public type exitButtonHandler must be defined in its own file
    public void actionPerformed(ActionEvent g){
        System.exit(0);
    }
}
public class FocusHandler implements FocusListener { //**The public type FocusHandler must be defined in its own file
    public void focusGained(FocusEvent e) {
    }
    public void focusLost(FocusEvent e) {
    }


public static void main( String args[] )
{
    Final tabs = new Final();
    tabs.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}

}

I am getting 3 errors, denoted by the //** next to the lines. Please help me to figure out the problems I am having.

  • 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-24T22:12:36+00:00Added an answer on May 24, 2026 at 10:12 pm

    Change calcButtonHandler2 definition to accept a reference to roundButton from where it’s defined.

    public class calcButtonHandler2 implements ActionListener {
    
        private final JRadioButton roundrButton;
    
        public calcButtonHandler(JRadioButton roundrButton)
        {
            this.roundrButton= roundrButton;
        }
        ....
    }
    

    and pass in the reference when you create an instance of calcButtonHandler2

    calcButtonHandler chandler =new calcButtonHandler(roundrButton);
    

    And as for the last two error, move the class declarations to separate files as called out by the compilation error or remove the public keyword from their definitions (I would recommend the first method).

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

Sidebar

Related Questions

import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Gui extends JFrame { private JFrame
Here I found this code: import java.awt.*; import javax.swing.*; public class FunWithPanels extends JFrame
Here is the code: import javax.swing.*; import java.awt.event.*; import java.awt.*; public class TestGrid {
package test; import java.awt.*; import java.awt.event.*; import java.awt.geom.Ellipse2D; import java.awt.image.BufferedImage; import javax.swing.*; public class
import java.awt.*; import javax.swing.*; import java.awt.geom.*; import java.awt.event.*; import javax.swing.border.*; public class ChangeButtonShape {
import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.FileNotFoundException; import java.io.IOException; import javax.swing.JButton; import javax.swing.JFrame;
import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; public class
Here is the code: import javax.swing.SwingUtilities; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JLabel; import java.awt.event.*;
Here is my code: import javax.swing.*; import java.awt.*; public class PanelModel { public static
Consider: import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.crypto.*; import javax.crypto.spec.*; import java.security.*; import

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.