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);
frame.createGUI();
frame.setVisible(true);
}
private void createGUI() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container window = getContentPane();
window.setLayout(new FlowLayout() );
panel = new JPanel();
panel.setPreferredSize(new Dimension(500,500));
panel.setBackground(Color.white);
window.add(panel);
button = new JButton("Press me");
window.add(button);
button.addActionListener(this);
}
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);
}
}