Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Need help putting GUI in program!

  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help putting GUI in program!

    I have a program that works fine already, I just have to make a GUI for it and have no idea what I am doing lol. I need it to look like the picture I have attached. Can anyone please help! Much appreciated!

    import java.io.PrintStream;
    import javax.swing.JOptionPane;
     
     
    public class DivisibleByTwo
    {
        public static void main(String args[])
        {
            int first = Integer.parseInt(JOptionPane.showInputDialog("Enter starting integer."));
            int second = Integer.parseInt(JOptionPane.showInputDialog("Enter ending integer."));
            if(first > second)
            {
                int temp = first;
                first = second;
                second = temp;
            }
            System.out.println((new StringBuilder()).append("The integers divisible by 2 in the range ").append(first).append(" to ").append(second).append(" are:\n").toString());
            for(int l = first; l <= second; l++)
                if(l % 2 == 0)
                    System.out.printf("\t\t%5d\n", new Object[] {
                        Integer.valueOf(l)
                    });
     
            System.exit(0);
        }
    }
    Attached Images Attached Images


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Need help putting GUI in program!


  3. #3
    Junior Member
    Join Date
    May 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help putting GUI in program!

    I have a basic understanding of creating a GUI but Im having a real hard time turning an already made program into one that has a GUI. Any help please?

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Need help putting GUI in program!

    I have a basic understanding of creating a GUI
    Then what have you tried? Did you try to create a JFrame with a layout similar to the picture you attached? That's one place where you can start...

  5. #5
    Junior Member
    Join Date
    May 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help putting GUI in program!

    I have to put "extends JFrame
    implements ActionListener" in right? But do I put it right after "public class DivisibleByTwo" or what? I'm just having trouble incorporating the gui stuff into the code I already have. Thanks

  6. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Need help putting GUI in program!

    Quote Originally Posted by greyfox175 View Post
    I have to put "extends JFrame
    implements ActionListener" in right? But do I put it right after "public class DivisibleByTwo" or what? I'm just having trouble incorporating the gui stuff into the code I already have. Thanks
    This means you should go back and read the tutorial I linked above - it might seem overwhelming but if you search you will find the components you need, and tutorials showing you how to use them. My advice: start from scratch and break your problem down - strip out the logic from your original code and turn it into a method which can be accessed regardless of whether you use the command line, a gui, whatever (this is a very important concept to learn). Then write your GUI - as I said break the problem down - first work on the layout, then work on the Actions, then work on linking those actions to the logic

Similar Threads

  1. Help with class program!!! STUCK! Program not doing what I Want!!!
    By sketch_flygirl in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 4th, 2011, 07:29 AM
  2. Reading a file, then putting it in an array
    By Gondee in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 16th, 2010, 11:11 AM
  3. Putting text fields in an array
    By Movies32 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 10th, 2010, 07:46 PM