joseph mcgratton

Ranch Hand
+ Follow
since Feb 15, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by joseph mcgratton

hello,

thankyou james for your help. it could be because they are strings. I cant remember why, but something would work with integers so i switch between strings and integers. now i know where the problem is, ill be ok.

thanks again

joseph
19 years ago
Hello,

when i use Collection.sort(ArrayList) and get the results, it sorts in a non numerical order. instead of lowest first and highest last, it goes by first digits, so if there is 1, 2, 3, 121, 234 it sorts it like this:
1, 121, 2, 234, 3.

any ideas?

joseph
[ March 02, 2005: Message edited by: joseph mcgratton ]
19 years ago
hello and thankyou for your reply.

if you suggest collections, thats what ill research into next. i guess collections sort the highest value into ArrayList(0). Now that i know where to look, i should get this sorted soon

thankyou,

Joseph
19 years ago
Hello,

i have made an ArrayList (ie ArrayList one = new ArrayList() ). This list has 1 - 100 values (1 - 900) added to it. It works fine. How do i get the highest value from the array? I have been looking at the javasun basic tutorials and examples and cannot find what i need.

thankyou,

Joseph.
19 years ago
hello,

thankyou all for your help. i have got the problem solved a different way ( by accident). if i setText object eg "", the screen updates. Sorry for posting on the wrong forum. ill have to see what other forums are available. At the moment id only had this forum on my favorites (good helpful forum by the way ). Anyway, back another 2 hr slog to try and fix my loop problem.

Joseph.
19 years ago
hello,

thankyou for your reply. hopefully i can get it updating when it should

joseph.
19 years ago
hello,

i have a program with 2 jPanels. one contains a button, the other is initially blank. When the button is pressed, one of the jPanels has objects added to it. However, they dont show unless i resize the whole window. is there a way to update the panel with the objects without resizing?

thanks,

joseph.
19 years ago
hello,

i am currently writing a program that contains alot of simple deterministic algorithms.i have a problem with one of the algorithms. I know what this problem is so hopefullysomeone here can help. first let me set the scene by showing a test scenario with limitedoptions.

- there is a grid of squares. The left 3 columns are filled blue or yellow.
- Randomly generated somewhere on the grid is a red square.
- a simple algorithm "finds" the red square.
- this algoritm then fills all squares left of the red square orange until rules/constraints are met

- A) the line stops when it hits a blue square
- B) each orange square can either
B1) remain the same
B2) turn white + the square above turns orange

B1 + B2 are constrained (constraint 1) in that the square above must be white.
B1 + B2 are constrained (constraint 2)in that only four squares can be moved up.
This "maximum of four squares works as follows. If a square is moved up one place, a "counter" (orangeUp)becomes orangeUp+1, and then the next orange square is looked at.

Now here is the problem. if the algorithm reaches the last orange square that has a white square below or above (ie constraint 1), and orangeUp has not reached 4 (constraint 2), the algoritm repeats until constraint 2 has reached 4. This means that instead of the orange square moving up once, it moves up 1 - 4 times. this is an example. (w = white, o = orange, b = blue)

Bwwwwwww Bowwwwww
Bwwwwwww Bwwwwwww
Bwwwwwww Bwwwwwww
Bwooooww Bwwwwwww
Bowwwwor Bwooooor
Bwwwwwww Bwwwwwww
Bwwwwwww Bwwwwwww

example 1 example2

in example 1, the algoritm works - 4 squares are moved up. this is because the algoritm started near the beginning of the orange trail.

in example 2, the algoritm doesnt work - the last square moves up 4 spaces. this is because the algorithm started at the last viable orange square. Going through constraint 2, orangeUp must reach 4.

here is the small snippet of code involved. Please note that i am aware some syntax is missing in this snippet, but in the full code its all there.


i hope you understand this. At least ive identified the problem.
im sure it can be solved in 1 line of code but i need suggestions! thankyou for reading.

Joseph
19 years ago
hello thankyou for reply,

its frustrating that you can do that in seconds and it takes me hours to accomplish nothing
ive tried your method, and there are no errors when compiling. However nothing appears on the appropriate panel. dont worry ill get it sorted soon.

thankyou

joseph

[ February 28, 2005: Message edited by: joseph mcgratton ]
[ February 28, 2005: Message edited by: joseph mcgratton ]
19 years ago
hello,

just to let you know that i have got it working now as i want it to. thanks again. I do have another query though (you'd never guess id ask you a question lol). A week ago you mentioned you would show me how to create a grid of JTextAreas using a loop (so i dont have to type out many lines that could slow the program). Well that has been todays task and i am finding it complicated.
As far as i can see, i use a nested loop to go through the grid which has been previously defined. if the grid[row][col] being checked is empty, then a reference of a JTextArea is added. However, im not sure how to use the loop to set dimensions or XYConstraints, and also to create it in a specfic JPanel. I managed earlier to get some code with no errors that supposedly created JTextAreas in a grid yet nothing happend. Everything seems to boil down to manually creating the JTextAreas and constraints ( i gave up after 200 as the computer froze - jbuilder was using 486mb ram ).
its quite frustrating as i have alot of algorithms working in a smaller grid, but i need bigger grids ( 8x8 is not suffice ). Are you able to explain to me how i would go about this? Please note that i have looked up 2 books on such things as layouts, and am currently at the sun website on layout managers, but they only show simplistic areas like arranging 6 different size objects in a frame, which i can do. I have also been looking up TicTacTie, Chess and Battleships source code.
Basically there are two swing containers (JPanels - West and East) and i would like West filled with 20x20 grid of JTextAreas. (West is actually a JPanel within a ScrollPanel. Maybe you detail the basics, then i have a go to see what i can do , then any problems i post code? If you know of any webpages or articles that deal specifally with this problem ( using a loop to make a grid ) that is also fine - i just need something to work on as im stuck.
Again, the only method i have got to work is this.

1) Create grid[row][col] max.
2) Create 400 textarea manually
3) Create 400 textarea dimensions manually
4) Create 400 textarea xtconstraints manually
5) give each grid position one of the textareas manually.

( thats at least 1600 lines of code, probably followed by a computer crash, and probably followed with alot of swearing ).

thankyuo for reading,

Joseph

p.s my last effort is this;


it produces no errors.
nothing happens when the program is run.
[ February 28, 2005: Message edited by: joseph mcgratton ]
19 years ago
hello,

thankyou for your help tonight. I understand the method and see how it works. One problem is that the "gray" square is randomly generated, and not always in trhe same spot, but this would be eady enough to convert to the current location. What i will do is have a look at your method and see what i can do. If it works fine which it should, then ill use that. Another way to go about this is to add something like grid[row-2][col] (concentrating more on moving down) to the array list. Then making a 3rd option that uses grid[row][col-2](concentrating on moving right.
Overall though i think your way would be better, as my way could leave "gaps" (which is why i thought of an extra option to help reduce gaps).

thanks again, we (you :-) )got there in the end,

joseph
19 years ago
hello,

i will try to explain the program area in question by giving a testing scenario.

1) there is a 10x10 grid.
2) the outer squares (eg grid[0][0] >>> grid[0][9] etc are black. is beacuse i cant fix the Arrayoutofbounds exceptions.
3) this black border prevents outofbounds if i use color.black constraints.
4) one of the middle squares is gray. (it is the current square)
5) a jButton initiates a random number ( 1 or 2).
6) if the random number is one, a square below or to the right of that gray square becomes gray.
7) the square that became gray is now the current square.
8) a square below or to the right of the current square becomes gray.
9) 6, 7, 8 repeats until the "maximum is met". This maximum is decided by "i".

All these steps work as planned if i = 3, 3 new gray squares are made. if i = 4, 4 new gray squares are made.

however, if the random number generated (step 5) is two, the process repeats, but this time the directions are either up or left. Think of it as pathing. But with option 2, "i" does not seem to work. By this i mean that only 1 square ever turns gray. So if i = 3, 1 new gray square is made. if i = 4, 1 new gray square is made.

joseph
[ February 27, 2005: Message edited by: joseph mcgratton ]
19 years ago
Could the problem be that when i go through the grid in a loop, it goes down and right (like option 1)? meaning that grid[row-1][col] etc cant be applied as it is the reverse of the origonal loop?
19 years ago
here is a quick example of what i mean. 0 = green square. X = origonal gray square. x = generated gray square.

option 1 (grid[row+1][col] or grid [row][col+1])

00000 00000
00X00 0X000
00x00 0xx00
00xx0 00x00
00000 00000

option 2 (grid[row-1][col] or grid [row][col-1])

00000 00000
0xX00 00000
00000 00x00
00000 00X00
00000 00000

As you see, option 2 only goes through 1 square.
[ February 27, 2005: Message edited by: joseph mcgratton ]
19 years ago
hello,

thankyou for your reply. you mentioned about a border to stop outofbounds - i have already done this (colored black). i am completely baffled. if you look at both sets of code for the 2 options, they are identical, apart from the "+" or "-" sign. The prgram causes no exceptions. i have tested the options alot, such as fixing the grid so that they are not near edges. i have deleted the constraints. i have changed variable names. But the outcome is always the same - when grid[row+1][grid] or grid [row][col+1] the prgram runs properly and colors 3 squares. but when grid[row-1][col] or grid [row][col-1], the program only colors 1 square.

ill just have to leave it - it only means that "gray" can only go in 2 directions and not four.

thanks,

joseph
19 years ago