Results 1 to 6 of 6
  1. #1
    decgaid06 is offline Member
    Join Date
    Mar 2011
    Posts
    21
    Rep Power
    0

    Default Help me with my GUI program please!

    Guys please help me on my program, this is a GUI java program, and I'm having problem every time I run it. It doesn't give me any output on every given I enter, it got an error always. This is a Confidence Interval of know variance, that's the title of my program.. I want it to give me an output every time I press the calculate button. Here's the code..

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;


    public class MyProgram2 extends JFrame implements ActionListener{
    JLabel heading = new JLabel("Given:");
    JLabel sSize = new JLabel("Sample Size");
    JLabel sMean = new JLabel("Sample Mean");
    JLabel var = new JLabel("Variance");
    JLabel ConfInt = new JLabel("Confidence Interval");
    JLabel ans = new JLabel("Two sided");

    JTextField textA = new JTextField(7);
    JTextField textB = new JTextField(7);
    JTextField textC = new JTextField(7);
    JTextField textD = new JTextField(7);
    JTextField textE = new JTextField(7);
    JTextField textF = new JTextField(7);
    JTextField ConfInttext = new JTextField(7);
    JTextField resultA = new JTextField(7);
    JTextField resultB = new JTextField(7);

    JButton calculate = new JButton("Calculate");

    JPanel hedpanel = new JPanel();
    JPanel row1 = new JPanel();
    JPanel row2 = new JPanel();
    JPanel row3 = new JPanel();
    JPanel row4 = new JPanel();
    JPanel result = new JPanel();
    JPanel butpanel = new JPanel();
    double a;
    double b;
    double c;
    double d;
    double e;
    double f;
    double g;
    double finalans;
    double h;
    double i;
    double j;
    double k;
    double l;
    double m;
    double n;
    double finalans2;

    public MyProgram2(){
    setTitle("Confidence Interval of two Population Mean");
    resultA.setEditable(false);
    resultB.setEditable(false);
    setLayout(new FlowLayout());

    //Add component to Panel

    hedpanel.add(heading);

    row1.add(sSize);
    row1.add(textA);
    row1.add(textB);

    row2.add(sMean);
    row2.add(textC);
    row2.add(textD);

    row3.add(var);
    row3.add(textE);
    row3.add(textF);
    row4.add(ConfInt);
    row4.add(ConfInttext);

    result.add(ans);
    result.add(resultA);
    result.add(resultB);

    butpanel.add(calculate);

    //Frame
    add(hedpanel);
    add(row1);
    add(row2);
    add(row3);
    add(row4);
    add(result);
    add(calculate);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    calculate.addActionListener(this);
    }
    //the Application
    public void calcCIL(){
    finalans = (c-d)-g*Math.sqrt((Math.pow(e,2)/a)+(Math.pow(f,2)/b));
    }
    public void calcCIR(){
    finalans2 = (j-k)+n*Math.sqrt((Math.pow(l,2)/h)+(Math.pow(m,2)/i));
    }
    public void actionPerformed(ActionEvent evt){
    String userIn;
    userIn = textA.getText();
    a = Integer.parseInt(userIn);
    h = Integer.parseInt(userIn);

    userIn = textB.getText();
    b = Integer.parseInt(userIn);
    i = Integer.parseInt(userIn);

    userIn = textC.getText();
    c = Integer.parseInt(userIn);
    j = Integer.parseInt(userIn);

    userIn = textD.getText();
    d = Integer.parseInt(userIn);
    k = Integer.parseInt(userIn);

    userIn = textE.getText();
    e = Integer.parseInt(userIn);
    l = Integer.parseInt(userIn);

    userIn = textF.getText();
    f = Integer.parseInt(userIn);
    m = Integer.parseInt(userIn);

    userIn = ConfInt.getText();
    g = Integer.parseInt(userIn);
    n = Integer.parseInt(userIn);

    resultA.setText(finalans+"");
    repaint();
    calcCIL();
    resultB.setText(finalans2+"");
    repaint();
    calcCIR();

    }
    public static void main(String[] args){
    MyProgram2 prog = new MyProgram2();
    prog.setSize(350, 290);
    prog.setResizable(false);
    prog.setVisible(true);

    }
    }

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    With lots of GUI code it's helpful to us if you wrap your code in code tags.

  3. #3
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default

    Quote Originally Posted by decgaid06 View Post
    Guys please help me on my program, this is a GUI java program, and I'm having problem every time I run it. It doesn't give me any output on every given I enter, it got an error always.

    the identifiers used in the code are very poor and a confusion can quickly happen. so the code is tryiing to convert the content of a jlabel in an integer

    userIn = ConfInt.getText()

    and this will not work. i guess

    userIn = ConfInt.getText()

    should be right.

  4. #4
    decgaid06 is offline Member
    Join Date
    Mar 2011
    Posts
    21
    Rep Power
    0

    Default

    @j2me64: Maybe you're right... I'm just new to java, and this is just my basic subject. But, I can't still understand the errors there... It still doesn't work the thing you suggest ConfInt.getText();

  5. #5
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Commenting what your variables mean and using meaningful variable names can definitely help you out a lot.

    Do you know how to do the basic action handling? Like having two text fields and a button that adds the two items and displays the answer in a label.

  6. #6
    decgaid06 is offline Member
    Join Date
    Mar 2011
    Posts
    21
    Rep Power
    0

    Default

    Yes, I know how to do basic action handling... I tried that, and I just did the same as that one... But there's something wrong with this... I think the problem there is the formula... I'll just check it out again... And Thanks for your help..

    I appreciate your immediate reply on my concern...

Similar Threads

  1. changing my program to array working program
    By Chewart in forum New To Java
    Replies: 39
    Last Post: 11-18-2009, 06:53 PM
  2. Execute A program from a Program!
    By Moncleared in forum Advanced Java
    Replies: 2
    Last Post: 02-22-2009, 04:17 PM
  3. Executing a program within a program
    By gibsonrocker800 in forum New To Java
    Replies: 5
    Last Post: 05-12-2008, 08:24 AM
  4. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  5. Replies: 0
    Last Post: 10-04-2007, 09:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •