Page 1 of 2 12 LastLast
Results 1 to 20 of 33
  1. #1
    university123 is offline Member
    Join Date
    Oct 2010
    Posts
    33
    Rep Power
    0

    Default Java help...Checkboxes

    I have my code for my program here, and I am having trouble with two different things. First of all I can't get my check box to check when I hit calculate. Any one have any ideas? I have the check boxes in the code but it wont check when I hit calculate to show the largest number.

    Second, I have code for if there is a tie but it wont seem to work where ever I put it in my code. here it is!

    Does anyone have any suggestins on how to do this?

    Java Code:
    // String tieMessage = null;
    // 
    //      if (piece1 == piece2) {
    //          if (piece1 == piece3) {
    //              tieMessage = "It's a tie between pieces 1,2 and 3";
    //          } else {
    //              tieMessage = "It's a tie between pieces 1 and 2";
    //          }
    //      } else if (piece1 == piece3) {
    //          tieMessage = "It's a tie between pieces 1 and 3";
    //      } else if (piece3 == piece2) {
    //          tieMessage = "It's a tie between pieces 2 and 3";
    //      }
    // if (tieMessage == null) {

    Java Code:
    import javax.swing.*;
    import javax.swing.JOptionPane;
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.JFrame;
    import javax.swing.JCheckBox;
    import java.awt.FlowLayout;
    
    
    class ArtPrizeDemo extends JFrame
    {
    private JPanel panel; // A holding panel
    private JLabel messageLabel1; // A message to the user
    private JLabel messageLabel2; // A message to the user
    private JLabel messageLabel3; // A message to the user
    private JLabel result; // A message to the user
    private JTextField piece1; // To hold user input
    private JTextField piece2; // To hold user input
    private JTextField piece3; // To hold user input
    private JCheckBox box1;
    private JCheckBox box2;
    private JCheckBox box3;
    private JButton calculate;
    
    private final int WINDOW_WIDTH = 400; // Window width
    private final int WINDOW_HEIGHT = 200; // Window height
    int num;
    
    public ArtPrizeDemo()
    {
    // Set the title.
    setTitle("Art Prize");
    
    // Set the size of the window.
    setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
    
    // Specify an action for the close button.
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
    // Build the panel and add it to the frame.
    buildPanel();
    
    // Add the panel to the frame's content pane.
    add(panel);
    
    // Display the window.
    setVisible(true);
    }
    private void buildPanel()
    {
    panel= new JPanel();
    
    messageLabel1 = new JLabel("Enter the number of votes for piece 1:");
        piece1 = new JTextField(10);
            box1 = new JCheckBox(" ");
            
    messageLabel2 = new JLabel("Enter the number of votes for piece 2:");
        piece2 = new JTextField(10);
            box2 = new JCheckBox(" ");
            
    messageLabel3 = new JLabel("Enter the number of votes for piece 3:");
        piece3 = new JTextField(10);
            box3 = new JCheckBox(" ");
            
    calculate= new JButton("Calculate");
            
            panel.add(messageLabel1);
            panel.add(piece1);
            panel.add(box1);
            panel.add(messageLabel2);
            panel.add(piece2);
            panel.add(box2);
            panel.add(messageLabel3);
            panel.add(piece3);
            panel.add(box3);
            calculate.addActionListener(new calButtonListener());
            panel.add(calculate);
                      result = new JLabel(" ");
            panel.add(result);
            
            
        }
           
           
    private class calButtonListener implements ActionListener
    {
    
    public void actionPerformed(ActionEvent e)
    
    {
    
    String in;
    int p1,p2,p3;
    in=piece1.getText();
    p1=Integer.parseInt(in);
    in=piece2.getText();
    p2=Integer.parseInt(in);
    in=piece3.getText();
    p3=Integer.parseInt(in);
    
    if(p1>p2)
        {
            
    if(p1>p3)
        {
            
    result.setText("Piece 1 is the winner");
    box1.enable(true);
    
    }
    
    else
    
    {
    
    result.setText("Piece 3 is the winner");
    box3.enable(true);
    
    }
    
    }
    
    else
    
    {
    
    if(p2>p3)
    
    {
    
    result.setText("Piece 2 is the winner");
    box2.enable(true);
    }
    
    else
    
    {
    
    result.setText("Piece 3 is the winner");
    box3.enable(true);
    
    }
    
    }
    
    
    class ArtPrize
    {
    public static void main(String[] args)
    
    {
    ArtPrizeDemo frm = new ArtPrizeDemo();
    frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frm.setSize(350,100);
    frm.setVisible(true);
    
    
        }
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,797
    Rep Power
    19

    Default

    Plus points for using code tags, but does that mean you don't indent your code?
    Can't follow the flow otherwise.

  3. #3
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    4

    Default

    First let's take care of the checkbox issue. When you use the enable() method all it does if you set it to true is make it so you CAN click on it, it won't actually make it checked. You will have to use the setSelected() method in order to actually make the checkbox show up as checked.

    Second is your tie algorithm. You are trying to compare text fields using the == operator. They are not integers. So simply go into your algorithm and change "piece1" to p1, "piece2" to p2, etc... just like you did with your checkbox algorithm. Also, the placement. I put your tie code above your checkbox algorithm encasing the checkbox algorithm inside the end bracket of "if (tieMessage == null) {". The reason for doing this is because you want to see if things are a tie before you actually tell the user who won. Since you have setText() inside the checkbox code, your tie algorithm had to be first.

    Third is why you are not getting output like "...is a tie...". It's because you use the variable tieMessage but do not use the setText method to print it to the screen anywhere.
    Last edited by joshdgreen; 10-21-2010 at 06:09 PM.
    Sincerely, Joshua Green
    Please REP if I help :)

  4. #4
    university123 is offline Member
    Join Date
    Oct 2010
    Posts
    33
    Rep Power
    0

    Default

    I'm still having trouble with the "tie" scenario. I guess i'm confused as where I should be putting it, and what I should be changing it too.

    Java Code:
    import javax.swing.*;
    import javax.swing.JOptionPane;
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.JFrame;
    import javax.swing.JCheckBox;
    import java.awt.FlowLayout;
    
    
    class ArtPrizeDemo extends JFrame
    {
    private JPanel panel; // A holding panel
    private JLabel messageLabel1; // A message to the user
    private JLabel messageLabel2; // A message to the user
    private JLabel messageLabel3; // A message to the user
    private JLabel result; // A message to the user
    private JTextField piece1; // To hold user input
    private JTextField piece2; // To hold user input
    private JTextField piece3; // To hold user input
    private JCheckBox box1;
    private JCheckBox box2;
    private JCheckBox box3;
    private JButton calculate;
    
    private final int WINDOW_WIDTH = 400; // Window width
    private final int WINDOW_HEIGHT = 200; // Window height
    int num;
    
    public ArtPrizeDemo()
    {
    // Set the title.
    setTitle("Art Prize");
    
    // Set the size of the window.
    setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
    
    // Specify an action for the close button.
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
    // Build the panel and add it to the frame.
    buildPanel();
    
    // Add the panel to the frame's content pane.
    add(panel);
    
    // Display the window.
    setVisible(true);
    }
    private void buildPanel()
    {
    panel= new JPanel();
    
    messageLabel1 = new JLabel("Enter the number of votes for piece 1:");
        piece1 = new JTextField(10);
            box1 = new JCheckBox(" ");
            
    messageLabel2 = new JLabel("Enter the number of votes for piece 2:");
        piece2 = new JTextField(10);
            box2 = new JCheckBox(" ");
            
    messageLabel3 = new JLabel("Enter the number of votes for piece 3:");
        piece3 = new JTextField(10);
            box3 = new JCheckBox(" ");
            
    calculate= new JButton("Calculate");
            
            panel.add(messageLabel1);
            panel.add(piece1);
            panel.add(box1);
            panel.add(messageLabel2);
            panel.add(piece2);
            panel.add(box2);
            panel.add(messageLabel3);
            panel.add(piece3);
            panel.add(box3);
            calculate.addActionListener(new calButtonListener());
            panel.add(calculate);
                      result = new JLabel(" ");
            panel.add(result);
            
            
        }
           
           
    private class calButtonListener implements ActionListener
    {
    
    public void actionPerformed(ActionEvent e)
    
    {
    
    String in;
    int p1,p2,p3;
    in=piece1.getText();
    p1=Integer.parseInt(in);
    in=piece2.getText();
    p2=Integer.parseInt(in);
    in=piece3.getText();
    p3=Integer.parseInt(in);
    
    
    String tieMessage = null;
    
         if (piece1 == piece2) {
             if (piece1 == piece3) {
                 tieMessage = "It's a tie between pieces 1,2 and 3";
             } else {
                 tieMessage = "It's a tie between pieces 1 and 2";
             }
         } else if (piece1 == piece3) {
             tieMessage = "It's a tie between pieces 1 and 3";
         } else if (piece3 == piece2) {
             tieMessage = "It's a tie between pieces 2 and 3";
            
         }
    if (tieMessage == null) {
    }
    
         
    if(p1>p2)
        {
            
    if(p1>p3)
        {
            
    result.setText("Piece 1 is the winner");
    box1.setSelected(true);
    
    }
    
    else
    
    {
    
    result.setText("Piece 3 is the winner");
    box3.setSelected(true);
    
    }
    
    }
    
    else
    
    {
    
    if(p2>p3)
    
    {
    
    result.setText("Piece 2 is the winner");
    box2.setSelected(true);
    }
    
    else
    
    {
    
    result.setText("Piece 3 is the winner");
    box3.setSelected(true);
    
    }
    
    }
    
    }
    
    }
    
    }
    
    
    
    
    
    class ArtPrize
    {
    public static void main(String[] args)
    
    {
    ArtPrizeDemo frm = new ArtPrizeDemo();
    frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frm.setSize(350,100);
    frm.setVisible(true);
    
    
        }
    }

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Please edit your code above to fix the indentation. It's very hard to read, so fewer folks will take the time to read it.

    Edit: I see that a request for improved indentation fix has already been made, but you've chosen to ignore it, why? You're only hurting your chances of getting help.
    Last edited by Fubarable; 10-23-2010 at 03:02 AM.

  6. #6
    university123 is offline Member
    Join Date
    Oct 2010
    Posts
    33
    Rep Power
    0

    Default

    Java Code:
    import javax.swing.*;
    import javax.swing.JOptionPane;
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.JFrame;
    import javax.swing.JCheckBox;
    import java.awt.FlowLayout;
    
    
    class ArtPrizeDemo extends JFrame
    {
    private JPanel panel; // A holding panel
    private JLabel messageLabel1; // A message to the user
    private JLabel messageLabel2; // A message to the user
    private JLabel messageLabel3; // A message to the user
    private JLabel result; // A message to the user
    private JTextField piece1; // To hold user input
    private JTextField piece2; // To hold user input
    private JTextField piece3; // To hold user input
    private JCheckBox box1;
    private JCheckBox box2;
    private JCheckBox box3;
    private JButton calculate;
    
    private final int WINDOW_WIDTH = 400; // Window width
    private final int WINDOW_HEIGHT = 200; // Window height
    int num;
    
    public ArtPrizeDemo()
    {
    // Set the title.
    setTitle("Art Prize");
    
    // Set the size of the window.
    setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
    
    // Specify an action for the close button.
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
    // Build the panel and add it to the frame.
    buildPanel();
    
    // Add the panel to the frame's content pane.
    add(panel);
    
    // Display the window.
    setVisible(true);
    
        }
    
    private void buildPanel()
    
        {
            panel= new JPanel();
    
            messageLabel1 = new JLabel("Enter the number of votes for piece 1:");
            piece1 = new JTextField(10);
            box1 = new JCheckBox(" ");
            
            messageLabel2 = new JLabel("Enter the number of votes for piece 2:");
            piece2 = new JTextField(10);
            box2 = new JCheckBox(" ");
            
            messageLabel3 = new JLabel("Enter the number of votes for piece 3:");
            piece3 = new JTextField(10);
            box3 = new JCheckBox(" ");
            
            calculate= new JButton("Calculate");
            
            panel.add(messageLabel1);
            panel.add(piece1);
            panel.add(box1);
            panel.add(messageLabel2);
            panel.add(piece2);
            panel.add(box2);
            panel.add(messageLabel3);
            panel.add(piece3);
            panel.add(box3);
            calculate.addActionListener(new calButtonListener());
            panel.add(calculate);
                      result = new JLabel(" ");
            panel.add(result);
            
            
        }
           
           
    private class calButtonListener implements ActionListener
    {
    
    public void actionPerformed(ActionEvent e)
    
    {
    
        String in;
        int p1,p2,p3;
        in=piece1.getText();
        p1=Integer.parseInt(in);
        in=piece2.getText();
        p2=Integer.parseInt(in);
        in=piece3.getText();
        p3=Integer.parseInt(in);
    
    
        String tieMessage = null;
    
         if (piece1 == piece2) {
             if (piece1 == piece3) {
                 tieMessage = "It's a tie between pieces 1,2 and 3";
             } else {
                 tieMessage = "It's a tie between pieces 1 and 2";
             }
         } else if (piece1 == piece3) {
             tieMessage = "It's a tie between pieces 1 and 3";
         } else if (piece3 == piece2) {
             tieMessage = "It's a tie between pieces 2 and 3";
            
         }
         
         if (tieMessage == null) {
            }
         
          if(p1>p2)
            {
            
                if(p1>p3)
                {
            
                    result.setText("Piece 1 is the winner");
                    box1.setSelected(true);
    
                }
    
                    else
    
                    {
    
                        result.setText("Piece 3 is the winner");
                        box3.setSelected(true);
    
                    }
    
                }
    
                else
    
                {
    
                    if(p2>p3)
    
                    {
    
                        result.setText("Piece 2 is the winner");
                        box2.setSelected(true);
                    }
    
                    else
    
                    {
    
                        result.setText("Piece 3 is the winner");
                        box3.setSelected(true);
    
                    }
    
                }
    
            }
    
        }
    
    }
    
    
    
    
    
    class ArtPrize
    {
    public static void main(String[] args)
    
    {
    ArtPrizeDemo frm = new ArtPrizeDemo();
    frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frm.setSize(350,100);
    frm.setVisible(true);
    
    
        }
    }

  7. #7
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Java Code:
    if (piece1 == piece2) {

    As noted above this line (and the others like it) is comparing two JTextField instances for identity. They are not identical so "piece1==piece2" will always be false.

    I don't know what you are trying to do with that line (perhaps you could say?) but, whatever it is, don't do it that way.

  8. #8
    university123 is offline Member
    Join Date
    Oct 2010
    Posts
    33
    Rep Power
    0

    Default

    I need it to actually say this: It's a tie between pieces 1,2 and 3";
    when there is a tie!

  9. #9
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Yes, but what exactly do you intend this line to do?

    Java Code:
    if (piece1 == piece2) {

    As pointed out the condition is always false. But what was it that you intended when you wrote this particular line of code?

  10. #10
    university123 is offline Member
    Join Date
    Oct 2010
    Posts
    33
    Rep Power
    0

    Default

    Like I said, I thought it would give me what I wanted:

    It's a tie between pieces 1,2 and 3"
    It's a tie between pieces 1 and 2"
    It's a tie between pieces 1 and 3"
    "It's a tie between pieces 2 and 3"

    Those are the 4 statements that I need to put into my code that I can't seem to do! I have tried and everyone keeps saying the same thing. So I need to change it, but to what? Thats what I need to know!

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    piece1 and piece2 are JTextFields. Think of them as if they were cardboard boxes, and when you check if piece1 == piece2, you're checking if they are actual one and the same box. What are you trying to compare here, the boxes, or the numbers that are contained inside of the boxes? If the numbers, then extract them (you already know how per your code above), and compare the numbers that the boxes/JTextFields hold.

  12. #12
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    There seems to be a communication problem ... but that's OK!

    I understand what you wanted to get output expressing what was tied with what. That's not what I'm asking. It's just that I look at your code and see a condition that will never be true, so that output will never be output. Never.

    Hence my question. I'm thinking "what did the OP mean by if(piece1==piece2)?" because I figure that if I knew what you meant, I might be able to come up with some other way of expressing it. Some way that gives a figting chance for the output to actually appear.

    Java Code:
    if(piece1 == piece2) {
        // under what circumstances did you think you might get to here?

  13. #13
    university123 is offline Member
    Join Date
    Oct 2010
    Posts
    33
    Rep Power
    0

    Default

    OK I understand what you are saying, but I am just all confused on how to change it. I have tried several different ways and it hasn't worked yet!

  14. #14
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    4

    Default

    Quote Originally Posted by joshdgreen View Post
    Second is your tie algorithm. You are trying to compare text fields using the == operator. They are not integers. So simply go into your algorithm and change "piece1" to p1, "piece2" to p2, etc... just like you did with your checkbox algorithm. Also, the placement. I put your tie code above your checkbox algorithm encasing the checkbox algorithm inside the end bracket of "if (tieMessage == null) {". The reason for doing this is because you want to see if things are a tie before you actually tell the user who won. Since you have setText() inside the checkbox code, your tie algorithm had to be first.

    Third is why you are not getting output like "...is a tie...". It's because you use the variable tieMessage but do not use the setText method to print it to the screen anywhere.

    As I stated in the first comment ever to this thread. I addressed the same issue... yet you made no changes...
    Sincerely, Joshua Green
    Please REP if I help :)

  15. #15
    university123 is offline Member
    Join Date
    Oct 2010
    Posts
    33
    Rep Power
    0

    Default

    I know I havent made any changes b/c I dont know what you mean. I changed it to the code I have added and tried putting it in several different places but still it wont work. I guess i'm not understanding what you are trying to tell me. Plus I have people telling me the == wont work, so that is confusing me even more!!



    Java Code:
    String setText = null;
    
         if (p1 == p2) {
             if (p1 == p3) {
                 setText = "It's a tie between pieces 1,2 and 3";
             } else {
                 setText = "It's a tie between pieces 1 and 2";
             }
         } else if (p1 == p3) {
             setText = "It's a tie between pieces 1 and 3";
         } else if (p3 == p2) {
             setText = "It's a tie between pieces 2 and 3";
            
         }
         
         if (setText == null) {

  16. #16
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    4

    Default

    That code will work, and you have it in the right place in your code. The part that is wrong is the ending bracket of the statement below.

    Java Code:
         if (tieMessage == null) {
            }
    Sincerely, Joshua Green
    Please REP if I help :)

  17. #17
    university123 is offline Member
    Join Date
    Oct 2010
    Posts
    33
    Rep Power
    0

    Default

    Josh I don't mean to bug you but I moved that bracket all over and it still wouldn't work. If I give you my code can you bold it or show me where to exactly put it!

    Java Code:
    import javax.swing.*;
    import javax.swing.JOptionPane;
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.JFrame;
    import javax.swing.JCheckBox;
    import java.awt.FlowLayout;
    
    
    class ArtPrizeDemo extends JFrame
    {
    private JPanel panel; // A holding panel
    private JLabel messageLabel1; // A message to the user
    private JLabel messageLabel2; // A message to the user
    private JLabel messageLabel3; // A message to the user
    private JLabel result; // A message to the user
    private JTextField piece1; // To hold user input
    private JTextField piece2; // To hold user input
    private JTextField piece3; // To hold user input
    private JCheckBox box1;
    private JCheckBox box2;
    private JCheckBox box3;
    private JButton calculate;
    
    private final int WINDOW_WIDTH = 400; // Window width
    private final int WINDOW_HEIGHT = 200; // Window height
    int num;
    
    public ArtPrizeDemo()
    {
    // Set the title.
    setTitle("Art Prize");
    
    // Set the size of the window.
    setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
    
    // Specify an action for the close button.
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
    // Build the panel and add it to the frame.
    buildPanel();
    
    // Add the panel to the frame's content pane.
    add(panel);
    
    // Display the window.
    setVisible(true);
    
        }
    
    private void buildPanel()
    
        {
            panel= new JPanel();
    
            messageLabel1 = new JLabel("Enter the number of votes for piece 1:");
            piece1 = new JTextField(10);
            box1 = new JCheckBox(" ");
            
            messageLabel2 = new JLabel("Enter the number of votes for piece 2:");
            piece2 = new JTextField(10);
            box2 = new JCheckBox(" ");
            
            messageLabel3 = new JLabel("Enter the number of votes for piece 3:");
            piece3 = new JTextField(10);
            box3 = new JCheckBox(" ");
            
            calculate= new JButton("Calculate");
            
            panel.add(messageLabel1);
            panel.add(piece1);
            panel.add(box1);
            panel.add(messageLabel2);
            panel.add(piece2);
            panel.add(box2);
            panel.add(messageLabel3);
            panel.add(piece3);
            panel.add(box3);
            calculate.addActionListener(new calButtonListener());
            panel.add(calculate);
                      result = new JLabel(" ");
            panel.add(result);
            
            
        }
           
           
    private class calButtonListener implements ActionListener
    {
    
    public void actionPerformed(ActionEvent e)
    
    {
    
            String in;
            int p1,p2,p3;
            in=piece1.getText();
            p1=Integer.parseInt(in);
            in=piece2.getText();
            p2=Integer.parseInt(in);
            in=piece3.getText();
            p3=Integer.parseInt(in);
            
            
            String setText = null;
    
         if (p1 == p2) {
             if (p1 == p3) {
                 setText = "It's a tie between pieces 1,2 and 3";
             } else {
                 setText = "It's a tie between pieces 1 and 2";
             }
         } else if (p1 == p3) {
             setText = "It's a tie between pieces 1 and 3";
         } else if (p3 == p2) {
             setText = "It's a tie between pieces 2 and 3";
            
         }
         
         if (setText == null) {
            }
         
          if(p1>p2)
            {
            
                if(p1>p3)
                {
            
                    result.setText("Piece 1 is the winner");
                    box1.setSelected(true);
    
                }
    
                    else
    
                    {
    
                        result.setText("Piece 3 is the winner");
                        box3.setSelected(true);
                    
    
                    }
    
                }
    
                else
    
                {
    
                    if(p2>p3)
    
                    {
    
                        result.setText("Piece 2 is the winner");
                        box2.setSelected(true);
                    }
    
                    else
    
                    {
    
                        result.setText("Piece 3 is the winner");
                        box3.setSelected(true);
                    
    
                    }
    
                }
    
            }
    
        }
    
    }
    
    
    
    
    
    
    
    class ArtPrize
    {
    public static void main(String[] args)
    
    {
    ArtPrizeDemo frm = new ArtPrizeDemo();
    frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frm.setSize(350,100);
    frm.setVisible(true);
    
            
        }
    }

  18. #18
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    4

    Default

    Yeah, I need to switch to my Windows system though, so gimme a couple minutes.
    Sincerely, Joshua Green
    Please REP if I help :)

  19. #19
    university123 is offline Member
    Join Date
    Oct 2010
    Posts
    33
    Rep Power
    0

    Default

    OK thanks a ton!!

  20. #20
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    4

    Default

    You want it to look something like this. Take note of the code that I have bolded and make sure that you understand why I put that code where I did.

    Java Code:
        if (p1 == p2)
        {
             if (p1 == p3)
                 setText = "It's a tie between pieces 1,2 and 3";
             else	
                 setText = "It's a tie between pieces 1 and 2";
        }
        else if (p1 == p3)
            setText = "It's a tie between pieces 1 and 3";
        else if (p3 == p2)
            setText = "It's a tie between pieces 2 and 3";
         
        [COLOR="Red"][B]if (setText == null) 
        {[/B][/COLOR]
        	if(p1>p2)
        	{
                if(p1>p3)
                {  
                	result.setText("Piece 1 is the winner");
                    box1.setSelected(true);
                }
                else
                {
                    result.setText("Piece 3 is the winner");
                    box3.setSelected(true);
                }
        	}
        	else if (p2 > p3)
        	{
        		result.setText("Piece 2 is the winner");
        		box2.setSelected(true);
        	}
        	else
        	{
        		result.setText("Piece 3 is the winner");
        		box3.setSelected(true);
        	}
        [COLOR="Red"][B]}
        
        result.setText(setText);[/B][/COLOR]
    Last edited by joshdgreen; 10-23-2010 at 06:20 AM.
    Sincerely, Joshua Green
    Please REP if I help :)

Page 1 of 2 12 LastLast

Similar Threads

  1. ComboBox with CheckBoxes
    By heba.farouk in forum AWT / Swing
    Replies: 14
    Last Post: 06-09-2010, 11:03 AM
  2. CheckBoxes and JTables
    By lakshayghai in forum AWT / Swing
    Replies: 1
    Last Post: 03-16-2010, 08:01 PM
  3. How to use Mnemonic for CheckBoxes
    By Java Tip in forum javax.swing
    Replies: 0
    Last Post: 06-27-2008, 07:45 PM
  4. How to use Swing CheckBoxes
    By Java Tip in forum javax.swing
    Replies: 0
    Last Post: 06-27-2008, 07:44 PM
  5. Problem with checkboxes
    By carl in forum Java Applets
    Replies: 1
    Last Post: 08-06-2007, 08: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
  •