CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2011

    trouble with GUI

    Hey guys,
    this is the first GUI program I have been trying to write, I have been getting through it all so far, but once my GUI comes up I click on the button and nothing happens, any help is greatly appreciated, thanks in advance.

    import javax.swing.*;
    import BreezySwing.*;
    public class piGUI extends GBFrame{

    private JLabel iterationLabel;
    private JLabel numberLabel;
    private DoubleField iterationField;
    private DoubleField numberField;
    private JButton iterationButton;
    private double iteration;

    public piGUI(){

    iterationLabel = addLabel ("Iterations" ,1,1,1,1);
    numberLabel = addLabel ("Pi" ,1,2,1,1);
    iterationField = addDoubleField (0.0 ,2,1,1,1);
    numberField = addDoubleField (0.0 ,2,2,1,1);
    iterationButton = addButton (">>>>>" ,3,1,1,1);}

    public void buttonClicked (JButton buttonObj){

    double answer;
    double extent = 0.0;
    answer = (numberField.getNumber());
    extent = (numberField.getNumber());

    for (int i=1; i < extent; i++) {

    if(answer % 2 == 1)
    answer = answer * 4;

    public static void main (String[] args){
    piGUI theGUI = new piGUI();
    theGUI.setSize (250, 100);

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999

    Re: trouble with GUI

    Please post code using the CODE tags (see my sig) to retain formatting so it is readable.

    OK... firstly, I seriously recommend that you don't use something like BreezySwing until you've learned how to code a GUI using the standard library, so you know how it all hangs together behind the scenes. See Creating a GUI with Swing.

    That said, when your GUI is displayed, both double fields are 0.0, so when you press the button, the button handler code sees it's zero and will just skip the loop - as you have coded it to do.

    Also, in that handler, you put the content of 'numberField' into both variables 'answer' and 'extent', ignoring 'iterationField' - are you sure you wanted to do that? I would suggest that 'numberField' is possibly the least informative name you could give to a numeric field, and this has probably contributed to your confusion. Give it a meaningful name - perhaps to do with its label (e.g. 'piField').

    Also, you are using a double (floating point) number for the number of iterations - an integer concept. Does it make sense to input a fraction of an iteration?

    Also, you should use the Java Naming Convention, or people might not read your code at all. At the very least, class names should begin with uppercase letters and method & variable names should begin with lowercase letters.

    Before software can be reusable it first has to be usable...
    R. Johnson
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Tags for this Thread

Posting Permissions

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

Click Here to Expand Forum to Full Width