Solved

# How can I create this Array??

Posted on 2003-03-22
Medium Priority
284 Views
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
Question by:Greging
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 3

Expert Comment

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

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

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

Author Comment

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

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

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

ID: 9058537
Greging:
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

LVL 15

Expert Comment

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:

jimmack
EE Cleanup Volunteer
0

## Featured Post

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectioâ€¦
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how â€¦
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
###### Suggested Courses
Course of the Month10 days, 19 hours left to enroll