I need urgently your help. Anyone can help how to Write a Java GUI program that accepts three user inputs (use text fields) with three check boxes. The check boxes determine whether the area, circumference and/or the volume of a circle/sphere is/are calculated. If only one check box is selected, your program should calculate and display only the area of the circle based on the 2 user inputs. If two check boxes are selected, your program shall calculate and display both the area and circumference, while selecting all three check boxes calculate and display the area, circumference and volume of the circle.

Recommended Answers

All 5 Replies

There are lots of people here who will freely give their time to help you become the best Java programmer you can be. There's nobody here who is interested in helping you cheat or doing your homework for you.

DaniWeb Member Rules (which you agreed to when you signed up) include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/community/rules

Post what you have done so far and someone will help you from there.

commented: Well said. Maybe we should use this as a boilerplate response to homework. :) +11
import java.awt.*;
    import java.text.*;
    import javax.swing.*;
    import java.awt.event.*;

    public class CircleGUI extends JFrame {
        double clx = 0.0, cly = 0.0, circumrx = 0.0, circumry = 0.0; 
        ButtonHandler buttonHandler;
        JLabel lClx, lCly, lCircumrx, lCircumry, lRadius, lArea, lCircumference;
        JTextField tClx, tCly, tCircumrx, tCircumry, tRadius, tArea, tCircumference;
        JButton bReset, bCompute;
        Container c;
        JPanel pNorth, pWest, pCenter, pSouth;
        public CircleGUI(){
            lClx = new JLabel("Center X");
            lCly = new JLabel("Center Y");
            lCircumrx = new JLabel("Circumference X");
            lCircumry = new JLabel("Circumference Y");
            lRadius = new JLabel("Radius");
            lArea = new JLabel("Area");
            lCircumference = new JLabel("Circumference");
            tClx = new JTextField();
            tCly = new JTextField();
            tCircumrx = new JTextField();
            tCircumry = new JTextField();
            tRadius = new JTextField();
            tArea = new JTextField();
            tCircumference= new JTextField();
            bReset = new JButton("Reset");
            bCompute = new JButton("Compute");
            pNorth = new JPanel();
            pWest = new JPanel();
            pCenter = new JPanel();
            pSouth = new JPanel();
            c = getContentPane();

            c.setLayout(new BorderLayout());
            pNorth.setLayout(new GridLayout(2,4));
            pWest.setLayout(new GridLayout(4,2));
            pCenter.setLayout(new GridLayout(4,2));
            pSouth.setLayout(new GridLayout(1,2));

            c.add(pNorth, BorderLayout.NORTH);
            c.add(pWest, BorderLayout.WEST);
            c.add(pCenter, BorderLayout.CENTER);
            c.add(pSouth, BorderLayout.SOUTH);

            pNorth.add(lClx);
            pNorth.add(tClx);
            pNorth.add(lCly);
            pNorth.add(tCly);
            pNorth.add(lCircumrx);
            pNorth.add(tCircumrx);
            pNorth.add(lCircumry);
            pNorth.add(tCircumry);
            pWest.add(lRadius);
            pWest.add(lArea);
            pWest.add(lCircumference);
            pCenter.add(tRadius);
            pCenter.add(tArea);
            pCenter.add(tCircumference);
            pSouth.add(bReset);
            pSouth.add(bCompute);

            buttonHandler = new ButtonHandler();
            bReset.addActionListener(buttonHandler);
            bCompute.addActionListener(buttonHandler);
            setSize(400, 200);
            setLocation(100, 100);
            setResizable(false);
            setTitle("Circle GUI");
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setVisible(true);
        }
private class ButtonHandler implements ActionListener {
            public void actionPerformed(ActionEvent ae) {
                if (ae.getSource().equals(bCompute)) {
                    try {
                        DecimalFormat df=new DecimalFormat("##.##");
                        clx = Double.parseDouble(tClx.getText());
                        cly = Double.parseDouble(tCly.getText());
                        circumrx = Double.parseDouble(tCircumrx.getText());
                        circumry = Double.parseDouble(tCircumry.getText());
                        double p1=circumrx-clx;
                        double p2=circumry-cly;
                        double pp1=p1*p1;
                        double pp2=p2*p2;
                        double s=pp1+pp2;
                        double radius=Math.sqrt(s);
                        double area=3.14*radius*radius;
                        double circumference=2*3.14*radius;
                        tRadius.setText(df.format(radius));
                        tArea.setText(df.format(area));
                        tCircumference.setText(df.format(circumference));
                    }
                    catch (Exception e) {
                        JOptionPane.showMessageDialog(null, "Fix your input");
                        return;
                    }
                }
                else {
                    tClx.setText("");
                    tCly.setText("");
                    tCircumrx.setText("");
                    tCircumry.setText("");
                    tRadius.setText("");
                    tArea.setText("");
                    tCircumference.setText("");
                }
            }
        }
        public static void main(String[] args) {
            CircleGUI newApp = new CircleGUI();
        }
    }

I didn't read all that, but it certainly looks reasonable. Do you have a particular question or problem?

yes, my problem is how to Write a Java GUI program that accepts three user inputs (use text fields) with three check boxes. The check boxes determine whether the area, circumference and/or the volume of a circle/sphere is/are calculated. If only one check box is selected, your program should calculate and display only the area of the circle based on the 2 user inputs. If two check boxes are selected, your program shall calculate and display both the area and circumference, while selecting all three check boxes calculate and display the area, circumference and volume of the circle.

I give up.

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.