Hi, I am trying to write an application that will calculate the volume of a pool with fixed length and width. The user will be prompted to enter 2 values for depth. The application should draw a cross-section of the pool using length, deep end and shallow end. A part of the assignment is asking for a user defined method to draw the cross-section of the pool. I am having difficulties with this part. Here's my code: ( lines 15-18)

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import static javax.swing.JFrame.EXIT_ON_CLOSE;

public class SwimmingPool extends JFrame

  implements ActionListener {
  private JPanel panel;
  private JButton button;
  private int length = 20;
  private int width = 5;
  int x = 10;
  int y = 10;
  private void drawPool( Graphics g, int x, int y, int deepEnd, int shallowEnd, int length){
      Graphics paper = panel.getGraphics();
      paper.drawPool( x, y,  deepEnd,  shallowEnd, length);
  public static void main(String[] args) {
    SwimmingPool frame = new SwimmingPool();
    frame.setSize(600, 600);

  private void createGUI() {
    Container window = getContentPane();
    window.setLayout(new FlowLayout() );
    panel = new JPanel();
    panel.setPreferredSize(new Dimension(500,500));
    button = new JButton("Press me");
  public void actionPerformed(ActionEvent event) {
    int deepEnd;
    int shallowEnd;
    double volume;
    Graphics paper = panel.getGraphics();

    String inputString;//used to read an input

    inputString = JOptionPane.showInputDialog("Deep End: ");
    deepEnd = Integer.parseInt(inputString);
    inputString = JOptionPane.showInputDialog("Shallow End: ");
    shallowEnd = Integer.parseInt(inputString);

    volume = ((deepEnd+shallowEnd)/2) * length * width;
    JOptionPane.showMessageDialog(null," voulme:" + volume);



and what is the question?

A part of the assignment is asking for a user defined method to draw the cross-section of the pool. I am having difficulties with this part.
Does that answer your question?

no, that does not answer my question.
that is not the question you are asking. that is the question asked to you.
so, what is it you're having a problem with?

I keep getting an error at line 17. It says cannot find symbol method drawPool. How can I correctly define a method and get it to work? Looking at my code, where do you think I made a mistake?

You have not defined a drawPool method, swo obviously you cannot call it! You need to write a method that will use one or more draw... methods from the Graphics class to draw the pool cross-section - eg call drawLine four times to draw the top surface, botton, deep end side and shallow end side.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.