Results 1 to 13 of 13
  1. #1
    icedragon770 is offline Member
    Join Date
    Oct 2008
    Posts
    36
    Rep Power
    0

    Default using javax.swing.JOptionPane in array

    is there a way to use java swing in array?
    import javax.swing.JOptionPane;

    public class ReverseOrder
    {

    public static void main (String[] args)
    {
    String words;
    System.out.println ( "CSC-116 Homework Nine - Displaying Entered Values in Reverse" );

    int[] numbers = new int[5];
    for (int index = 0; index < numbers.length; index++)
    {

    words = JOptionPane.showInputDialog("Please enter an integer value");
    numbers = Integer.parse.Int(words);

    }

    System.out.println ("In Reverse, those values are:");

    for (int index = numbers.length-1; index >= 0; index--)
    System.out.println (numbers[index] + " ");
    }
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,563
    Rep Power
    23

    Default

    An array is a way to store/retrieve elements(primitives and objects) of the same type using an index. It works well in loops.
    swing is a family of GUI components.
    There can be arrays of components.

    How do you want to use an array?

    If you are getting compiler errors, copy and paste them here.

  3. #3
    icedragon770 is offline Member
    Join Date
    Oct 2008
    Posts
    36
    Rep Power
    0

    Default

    ReverseOrder.java:24: incompatible types
    found : int
    required: int[]
    numbers = Integer.parseInt(words) is the error

  4. #4
    icedragon770 is offline Member
    Join Date
    Oct 2008
    Posts
    36
    Rep Power
    0

    Default

    array to be number and words = JOptionPane.showInputDialog("Please enter an integer value"); to get this output
    System.out.println ("In Reverse, those values are:");

    for (int index = numbers.length-1; index >= 0; index--)
    System.out.println (numbers[index] + " ");

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

    Default

    Please do not spam folks with private messages. It's a good way to get on everyone's ignore list. Do it again and abuse will be reported.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,563
    Rep Power
    23

    Default

    incompatible types
    found : int
    required: int[]
    numbers = Integer.parseInt(words) is the error
    What don't you understand in this error message. It says the compiler found a type int and it was looking for a type int[]. There is also a ^ that you didn't post. Where was that?
    What type is numbers?
    What types does parseInt() return?
    Are they different? How can you make them the same?

  7. #7
    icedragon770 is offline Member
    Join Date
    Oct 2008
    Posts
    36
    Rep Power
    0

    Default

    i want to use java joption pan to insert 5 integers and want to print those number in reverse how do i do that?

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,563
    Rep Power
    23

    Default

    Use an array in a loop.
    Store the returned values into the array using the loop index.
    reverse the contents of the array
    print the contents of the array using a loop.

  9. #9
    icedragon770 is offline Member
    Join Date
    Oct 2008
    Posts
    36
    Rep Power
    0

    Default

    thanks norm

  10. #10
    icedragon770 is offline Member
    Join Date
    Oct 2008
    Posts
    36
    Rep Power
    0

    Default

    does it matter what loop it is norm?

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,563
    Rep Power
    23

    Default

    A for loop is more natural for indexing.

  12. #12
    icedragon770 is offline Member
    Join Date
    Oct 2008
    Posts
    36
    Rep Power
    0

    Default

    okay thanks norm

  13. #13
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

Similar Threads

  1. use of javax.swing.text.html
    By newbieal in forum New To Java
    Replies: 3
    Last Post: 10-09-2008, 06:45 PM
  2. Replies: 6
    Last Post: 07-10-2008, 07:28 PM
  3. String array for Choice, JOptionPane doesn't show
    By themburu in forum Java Applets
    Replies: 5
    Last Post: 05-29-2008, 01:10 PM
  4. Replies: 1
    Last Post: 08-01-2007, 06:10 AM
  5. map javax.swing.text.Element to javax.swing.text.View
    By elizabeth in forum New To Java
    Replies: 1
    Last Post: 07-30-2007, 07:02 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
  •