Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By DarrylBurke

Thread: Loop Failure with Swing.

  1. #1
    Lethedethius is offline Member
    Join Date
    Jan 2012
    Posts
    3
    Rep Power
    0

    Default Loop Failure with Swing.

    I'm going to shoot myself guys... been working this loop all night with no luck. Can someone correct my fatal flaw, I know I have the loop done wrong...
    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package gui_attempt.pkg2;
    import java.io.IOException;
    import javax.swing.*;
    import javax.imageio.ImageIO;
    import java.awt.*;
    import java.net.*;
    
    /**
     *
     * @author School
     */
    public class GUI_ATTEMPT2
    {
        public static void main(String[] args) throws IOException {
                //Lets play with some pictures
        //This will ask the tough questions    
        int ask[];
        ask = new int[4];
        //         while (i <= ask.length )
    
             //  This for loop keeps asking the questions until there is a positive value for each question.
    
             
             for( int i = 0; i <= 0; i++){
             JOptionPane.showMessageDialog(null, "All questions asked should be answered in pounds. Please put a positive number");
             ask[0] = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter your weight" + " "));
             int weight = 0; 
             ask[0] = weight;
             ask[1] = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter the weight of your car" + " "));
             int car = 0;
             ask[1] = car;
             ask[2] = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter the weight of your bicycle" + " "));
             int bike = 0;
             ask[2] = bike;
             ask[3] = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter the weight of your Wife, BE HONEST!" + " "));
             int wife = 0;
             ask[3] = wife;
             if(ask.length > 1 && ask.length < 99999){
             
                 JOptionPane.showMessageDialog(null, "All questions asked should be answered in pounds. Please put a positive number");
             ask[0] = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter your weight" + " "));
             ask[1] = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter the weight of your car" + " "));
             ask[2] = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter the weight of your bicycle" + " "));
             ask[3] = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter the weight of your Wife, BE HONEST!" + " "));
             }
             }
             
             double moon = 0.166;
             double mercury = 0.378;
             double jupiter = 2.364;
             
             
             //pics
             final ImageIcon earthicon = new ImageIcon(new URL("http://holydiscussion.org/images/Earth-icon.png"));
             final ImageIcon moonicon = new ImageIcon(new URL("http://holydiscussion.org/images/Moon-icon.png"));
             final ImageIcon jupitericon = new ImageIcon(new URL("http://holydiscussion.org/images/Jupiter-icon.png"));
             final ImageIcon mercuryicon = new ImageIcon(new URL("http://holydiscussion.org/images/Mercury-icon.png"));
             //stores the tough questions plus answers in this array.
             JOptionPane.showMessageDialog(null, "On the Earth your inputs would be:\nYour weight: " + ask[0] + "lbs\nThe weight of your vehicle: " + ask[1] + "lbs\nThe weight of your bicycle: " + ask[2] + "lbs\nAnd Finally the weight of your wife:" + ask[3] + "lbs", "Earth", JOptionPane.INFORMATION_MESSAGE, earthicon);
             JOptionPane.showMessageDialog(null, "That was obvious, now to the moon!");
             JOptionPane.showMessageDialog(null, "On the moon your much lighter! \nYour weight: " + ask[0] * moon + "lbs\nVehicle: " + ask[1] * moon + "lbs\nBicycle: " + ask[2] * moon + "lbs\nWife: " + ask[3] * moon + "lbs", "THATS ONE SMALL STEP FOR MAN!", JOptionPane.INFORMATION_MESSAGE, moonicon);
             JOptionPane.showMessageDialog(null, "Doesn't that make her feel better now?");
             JOptionPane.showMessageDialog(null, "On Mercury your a bit lighter! \nYour weight: " + ask[0] * mercury + "lbs\nVehicle: " + ask[1] * mercury + "lbs\nBicycle: " + ask[2] * mercury + "lbs\nWife: " + ask[3] * mercury + "lbs", "DANG ITS HOT ON THIS HUNK OF JUNK PLANET!!", JOptionPane.INFORMATION_MESSAGE, mercuryicon);
             JOptionPane.showMessageDialog(null, "She's still doing good!");
             JOptionPane.showMessageDialog(null, "On Jupiter your pretty heavy due to the gravitational pull! \nYour weight: " + ask[0] * jupiter + "lbs\nVehicle: " + ask[1] * jupiter + "lbs\nBicycle: " + ask[2] * jupiter + "lbs\nWife: " + ask[3] * jupiter + "lbs", "This thing is big and useless!", JOptionPane.INFORMATION_MESSAGE, jupitericon);
             JOptionPane.showMessageDialog(null, "Ok time for her to go on a crash diet!");
    
             
    
    
        //JFrame a window here, to let them know something is running.
        JFrame frame = new JFrame("James Earth Weight to Other Planets Converter");
        JLabel hello = new JLabel("Hello, welcome to my converter programs first attempt\n Below should appear all the values you have entered.");
        JLabel Earth = new JLabel("On the Earth your inputs would be:\nYour weight: " + ask[0] + "lbs\nThe weight of your vehicle: " + ask[1] + "lbs\nThe weight of your bicycle: " + ask[2] + "lbs\nAnd Finally the weight of your wife:" + ask[3] + "lbs");
        JLabel Mercury = new JLabel("");
        JLabel Jupiter = new JLabel("");
        frame.getContentPane().add(hello);
        frame.getContentPane().add(Earth);
    
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(800,500);
        frame.setVisible(false);
        //Lets tell this person it's in POUNDS, NOT KILOS!
        //Ask the hard questions!
    
        
        //This will ask the tough questions
    
             
        }
    }
    Last edited by Lethedethius; 01-30-2012 at 06:57 AM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Loop Failure with Swing.

    Recommended reading:
    How to ask questions the smart way
    SSCCE

    db
    pbrockway2 likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Lethedethius is offline Member
    Join Date
    Jan 2012
    Posts
    3
    Rep Power
    0

    Default Re: Loop Failure with Swing.

    With all respect intended, are you trying to be a troll? Let me ask my question the retarded way-I'm having problems with a loop that will keep it so if you enter in the the weight as a negative value or 99999 you have to keep re-entering it before you can continue to the next question- the first one works, your weight, but before you can move on to car or bike or wife it just bypasses it and continues to the GUI, using 0 as the value (minus your weight), is that better? How bout a little help and less statements that make people want to choke you.

    Recommended reading for you:

    What your doing.

    Good day sir, now can someone please help me out here?

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Loop Failure with Swing.

    Quote Originally Posted by Lethedethius View Post
    With all respect intended, are you trying to be a troll? ... How bout a little help and less statements that make people want to choke you.

    Recommended reading for you:

    What your doing.
    Sure, that's going to make members here want to help you. Not.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,809
    Rep Power
    19

    Default Re: Loop Failure with Swing.

    Quote Originally Posted by Lethedethius View Post
    With all respect intended, are you trying to be a troll?
    You never actually asked a question.
    You simply posted code with no hint as to what your problem was.
    That implies you expected someone here to run that code or stick it into an IDE to see what the problem was.
    That isn't going to happen.

    WHen you have a problem you need to provide information about what the problem is.
    Your OP was akin to phoning a garage and saying "my car doesn't work, why?"

Similar Threads

  1. IF ELSE program failure.
    By Domenatrice in forum New To Java
    Replies: 4
    Last Post: 11-12-2011, 07:48 AM
  2. How to loop forever in Swing-based Java app
    By GuiRitter in forum AWT / Swing
    Replies: 10
    Last Post: 04-28-2011, 10:16 AM
  3. Help uninstall! failure
    By minty115 in forum New To Java
    Replies: 5
    Last Post: 03-01-2011, 04:07 AM
  4. Inside a Timer thread loop,how to refresh a JTable in swing
    By neha_negi in forum Threads and Synchronization
    Replies: 3
    Last Post: 09-04-2009, 01:45 AM
  5. Animation failure...
    By lordbob75 in forum New To Java
    Replies: 10
    Last Post: 05-11-2009, 02:06 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
  •