Results 1 to 4 of 4
Thread: Can anyone help me with my code?
- 10-15-2010, 04:31 AM #1
Member
- Join Date
- Oct 2010
- Posts
- 33
- Rep Power
- 0
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!
-
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.
- 10-15-2010, 05:05 AM #3
Member
- Join Date
- Oct 2010
- Posts
- 33
- Rep Power
- 0
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); } } }
-
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
-
Code to check if a piece of code is legal.
By vahshir in forum New To JavaReplies: 3Last Post: 08-30-2010, 04:21 AM -
can any one pls send me a sample code for calling a jsp code in swings
By sniffer139 in forum AWT / SwingReplies: 1Last Post: 03-04-2010, 11:19 AM -
Convert java code to midlet code
By coldvoice05 in forum New To JavaReplies: 1Last Post: 08-12-2009, 11:14 AM -
Convert java code to midlet code
By coldvoice05 in forum Advanced JavaReplies: 1Last Post: 08-09-2009, 01:21 PM -
Generating Code Automatically Using Custom code Template In Eclipse
By JavaForums in forum EclipseReplies: 1Last Post: 04-26-2007, 03:52 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks