Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How can I create this Array??

Posted on 2003-03-22
9
Medium Priority
?
291 Views
Last Modified: 2010-03-31
Guys, I need help. I want to create a "simple" applet where a user enter a number of values up to 100 in a textfield, let say, which will inhabit 100 cells in a 25 by 4 array. I want to keep track of those values by using a 2D array P[27][6] with entries are 1, 2, 3, and 4. How can I produce that?
0
Comment
Question by:Greging
8 Comments
 
LVL 3

Expert Comment

by:wide_awake
ID: 8187151
If I understand what you're looking for, there are a number of ways to do this.

One way is to have 100 text boxes, and the user fills in each one they want.  Then you store the numbers into your array.

Another way is to have a text area, and have the user enter a comma-separated list of numbers, i.e. "1, 2, 1, 1, 1, 2, 3, ...".  Then you could use a string tokenizer to extract the individual numbers and store them in your array.  To do this, you'd say

StringTokenizer st = new StringTokenizer(inputString, ",");
for(int i=0;i<25;i++)
{
   for(int j=0;j<4;j++)
   {
      if(st.hasMoreTokens())
      {
         P[i][j] = Integer.parseInt(st.nextToken().trim());
      }
   }
}

This will fill in as much of the array as is supplied in the text field.

-Mark.
0
 

Author Comment

by:Greging
ID: 8187218
Good point, but I dont think that "StringTokenizer" will work for me though. Here's part of my own pseudocode for generating this array:

for i = 1 to 4
  for j = 1 to 25
    if P(i,j) => 1 and <=4


      for m = i-1 to i+1
        for n = j-1 to j+1
          if P(m,n) = 0

          end if
        end for
      end for
    end if
  end for
end for  


i'm having trouble putting this one in an applet.



0
 
LVL 3

Expert Comment

by:wide_awake
ID: 8188834
I'm not sure where you're having trouble.

Are you having trouble devising a way to get input from a user?  storing the input in an array?  performing calculations on the resulting input?

-Mark.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Greging
ID: 8189778
I having trouble with devising a way to get input from a user, storing and displaying input in an array, and having alittle bit of difficulty setting up an applet.
0
 
LVL 3

Accepted Solution

by:
wide_awake earned 120 total points
ID: 8190690
Here's a tutorial to get you started on Applets:
http://java.sun.com/docs/books/tutorial/uiswing/components/applet.html

For more general info on creating user interfaces, try here:
http://java.sun.com/docs/books/tutorial/uiswing/index.html

Once you're comfortable with the basics of Swing and Applets, the rest should be easy.

-Mark.
0
 

Expert Comment

by:thomasjn
ID: 8193900
hi this is a suggestion...

make the array as the index and try to have one text field and five button... four button for better navigation

      one to move horizontally on the left side thru' the column. the other horizontally on the right thru' the column. one to move up thru the rows and the fourth to move down thru' the rows.

      now u can have the user to navigate to the cell he wants to enter the data enter the number and save it using the fifth button. u can initially give a automatic navigation till all the values are enter by entering the data and clicking the fifth button. after entering the data
the user can use the navigation button to change the values. if needed. if possible use the JTable to provide a preview of the values he has entered

/Thomas.
0
 

Expert Comment

by:CleanupPing
ID: 9058537
Greging:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9730781
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept wide_awake's comment as answer.

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jimmack
EE Cleanup Volunteer
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month10 days, 8 hours left to enroll

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question