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

    Default Can anyone help me with my code?

    Can anyone help me with my code?
    Can anyone show me how I put checkboxes in my code so that when I push the "calcuate" button it will put a chackmark next to the art piece witht he most votes, and how do I get that calculate button in my program, b/c I have tried several ways and have been unsuccessful thus far. Appreciate it!




    Java Code:
    import javax.swing.JFrame;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.Scanner;
    
    public class ArtPrize
    {
    public static void main (String[] args)
    {
    int piece1, piece2, piece3, num = 0;
    
    Scanner scan = new Scanner (System.in);
    
    piece1 = scan.nextInt();
    piece2 = scan.nextInt();
    piece3 = scan.nextInt();
    
    if(piece1>piece2 && piece1>piece3)
    num = piece1;
    
    if(piece2>piece3 && piece2>piece1)
    num = piece2;
    
    if(piece3>piece1 && piece3>piece2)
    num = piece3; 
    
    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) {
    // TODO
    // USE YOUR LOGIC TO CHECK FOR MAXIMUM VOTES.
    }
    }
    
    private JLabel inputLabel, inputLabel2, inputLabel3, resultLabel;
    private JTextField ArtPrize;
    }
    
    public ArtPrize() 
    {
    inputLabel = new JLabel ("Enter the number of votes for piece 1:");
    inputLabel2 = new JLabel ("Enter the number of votes for piece 2:");
    inputLabel3 = new JLabel ("Enter the number of votes for piece 3:");
    resultLabel = new JLabel ("-----");
    
    ArtPrize = new JTextField (5);
    ArtPrize.addActionListener (new ArtPrizeListener());
    
    add (inputLabel);
    add (inputLabel2);
    add (inputLabel3);
    add (resultLabel);
    
    setPreferredSize (new Dimension(300, 200));
    setBackground (Color.white);
    }
    
    
    private class ArtListener implements ActionListener
    {
    public void actionPerformed (ActionEvent event)
    {
    
    
    JFrame frame = new JFrame ("Art Prize");
    frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
    
    ArtPrizePanel = new ArtPrizePanel();
    
    frame.getContentPane().add(panel);
    frame.pack();
    frame.setVisible(true);
    
    
    
    }
    }
    Last edited by Fubarable; 10-15-2010 at 04:51 AM. Reason: Moderator Edit: Code tags added but code unformatted to begin with!

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

    Default

    I added code tags, but it doesn't help your code as the code itself was not formatted at all. Please do yourself and us a favor, and edit your previous post so that it shows decently formatted code only, code that is easy for anyone to read. Then many someone will take the time to read it and help you. Up to you!

    Also, add code tags to your formatted code. My signature link can help.

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

    Default

    Java Code:
    import javax.swing.JFrame;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.Scanner;
    
    public class ArtPrize {
    
            private JLabel inputLabel, inputLabel2, inputLabel3, resultLabel;
            private JTextField ArtPrize;
            private JLabel inputLabel, inputLabel2, inputLabel3, resultLabel;
            private JTextField ArtPrize;
    
        public static void main (String[] args)
        {
            int piece1, piece2, piece3, num = 0;
            
            Scanner scan = new Scanner (System.in);
            
            piece1 = scan.nextInt();
            piece2 = scan.nextInt();
            piece3 = scan.nextInt();
            
            if(piece1>piece2 && piece1>piece3)
                num = piece1;
                
            if(piece2>piece3 && piece2>piece1)
                num = piece2;
                
            if(piece3>piece1 && piece3>piece2)
                num = piece3;    
                
            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) {
                             // TODO
                             // USE YOUR LOGIC TO CHECK FOR MAXIMUM VOTES.
                    }
                }
            
            
        }
    
            JFrame frame = new JFrame ("Art Prize");
            frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
            
            ArtPrizePanel = new ArtPrizePanel();
            
            frame.getContentPane().add(panel);
            frame.pack();
            frame.setVisible(true);
            
            {
                 inputLabel = new JLabel ("Enter the number of votes for piece 1:");
                 inputLabel2 = new JLabel ("Enter the number of votes for piece 2:");
                 inputLabel3 = new JLabel ("Enter the number of votes for piece 3:");
                 resultLabel = new JLabel ("-----");
                 
                 ArtPrize = new JTextField (5);
                 ArtPrize.addActionListener (new ArtPrizeListener());
                 
                 add (inputLabel);
                 add (inputLabel2);
                 add (inputLabel3);
                 add (resultLabel);
                 
                 setPreferredSize (new Dimension(300, 200));
                 setBackground (Color.white);
             } 
        
        }
    }

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

    Default

    OK, thanks for formatting your code so that now we can see it. What have you tried to do to solve the problem? I don't see a calculate button, and I see what looks like an unholy mix of Swing and console code. Is this supposed to be a Swing GUI app or a console app? If Swing, you'll want to get rid of the console code. You also will want to create a proper object with constructors fields and so forth.

Similar Threads

  1. Code to check if a piece of code is legal.
    By vahshir in forum New To Java
    Replies: 3
    Last Post: 08-30-2010, 04:21 AM
  2. Replies: 1
    Last Post: 03-04-2010, 11:19 AM
  3. Convert java code to midlet code
    By coldvoice05 in forum New To Java
    Replies: 1
    Last Post: 08-12-2009, 11:14 AM
  4. Convert java code to midlet code
    By coldvoice05 in forum Advanced Java
    Replies: 1
    Last Post: 08-09-2009, 01:21 PM
  5. Replies: 1
    Last Post: 04-26-2007, 03:52 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
  •