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

    Default Help with my Program...GUI'S

    I have my program and everything works just fine, but I need to be able to enter the votes all in the same GUI, and have check mark boxes state the winner. So the GUI should look like this, this is what the final thing should look like when you are entering your votes!

    Enter the number of votes for piece 1: 80 check boxes go here
    Enter the number of votes for piece 2: 92 check boxes go here. Check mark
    Enter the number of votes for piece 3: 74 check boxes go here
    "Calculate Button" ---- Piece 2 is the winner.


    Java Code:
    import javax.swing.*;
    import javax.swing.JOptionPane;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.*;
    import javax.swing.JFrame;
    import javax.swing.JCheckBox;
    import java.awt.FlowLayout;
    
    
    class ArtPrizeDemo extends JFrame
    {
        int num;
        String result;
    public ArtPrizeDemo()
    {
    String firstpiece = JOptionPane.showInputDialog("Enter first piece of votes : " );
    int piece1 = Integer.parseInt(firstpiece);
    
    String secondpiece = JOptionPane.showInputDialog("Enter second piece of votes : " );
    int piece2 = Integer.parseInt(secondpiece);
    
    String thirdpiece = JOptionPane.showInputDialog("Enter third piece of votes : " );
    int piece3 = Integer.parseInt(thirdpiece);
    
    if(piece1>piece2 && piece1>piece3)
    {
        num = piece1;
        result = "piece 1";
    }
        else if(piece2>piece3 && piece2>piece1)
    {
        num = piece2;
        result = "piece 2";
    }
    if(piece3>piece1 && piece3>piece2)
    {
        num = piece3;
        result = "piece3 ";
        
    }
    JOptionPane.showMessageDialog(null," Enter the number of votes for piece 1 : " + piece1 + "\n" + " Enter the number of votes for piece 2 " + piece2 + "\n" + " Enter the number of votes for piece 3 : " + piece3+ "\n" + "Winner is " + result);
    
    
    }
    
    }
    
    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
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Hello.

    A few suggestions to help you get better help:

    1) Ask a question. As it stands your post above is a statement of your requirement and some code which implies that this is a "here's my code, please fix it for me" type question, and these never fly. You'll likely get specific helpful answers if you ask specific informative questions.

    2) Format your code well. Your code formatting is non-standard which will make it harder for others to read your code, decreasing their willingness to read it and help you, and also which may result in grade deductions from your instructors.

    For more suggestions that should help you get better answers here, please see the link: How to ask questions

    Much luck.

Similar Threads

  1. GUI's
    By lopder1 in forum New To Java
    Replies: 2
    Last Post: 11-12-2009, 01:33 AM
  2. GUI's and inputting doubles or ints
    By lopder1 in forum New To Java
    Replies: 19
    Last Post: 11-05-2009, 08:50 PM
  3. GUI's
    By ngc0202 in forum New To Java
    Replies: 7
    Last Post: 07-26-2009, 03:38 AM
  4. GUI's
    By diggitydoggz in forum New To Java
    Replies: 2
    Last Post: 12-22-2008, 09:19 PM
  5. Creating GUI's for simulators.
    By Modifier in forum New To Java
    Replies: 3
    Last Post: 11-20-2008, 12:35 AM

Posting Permissions

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