Piet Souris

Bartender
+ Follow
since Mar 08, 2009
Forum Moderator
Netherlands
Cows and Likes
Cows
Total received
156
In last 30 days
0
Total given
110
Likes
Total received
872
Received in last 30 days
8
Total given
100
Given in last 30 days
1
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Piet Souris

Well, it is up to OP of course, but I find working with ints pretty limiting.
1 day ago
To prevent the problems that Carey described, why don't you use doubles instead of ints?

And there are ready made classes that will do all the work for you: see Rectangle(2D), and Point(2D).
1 day ago
Don't set the size of a JFrame yourself. Let its containing JComponents decide their own value, and then use: frame.pack();

For instance:
1 week ago
In my reply I hinted to using a special DocumentFilter, that lets you inspect upfront the changes in spe, and that enables you to reject certain changes. Its use is more complicated than you have now, though.
2 weeks ago
hi Don,

first question: the x and y are the topleft coordinates of a rectangle. The rectangle bounces off the right border when its right side reaches 500. So you should test for:


And the red rectangle does not move at all. See the paintComponent method, look at r2. Can you spot why it doesn't move?

And to make the bouncing off the border independent of the panel size, use something like:

Same for the y-coordinate. 'this' refers to the panel in question

Then the problem that that red rectangle is only shown partly. I'm not sure why that is so, but a general advice is:

do not set the size of a JFrame yourself. Let the panels for themselve decide how big they should be (and in many  cases even that is unnecessary: its layoutmanager will decide the size of a panel).

So, in the constructor of objectframe. I have this:

and the constructor of the objectPanel is now:

2 weeks ago
You're welcome!
2 weeks ago
No, you already have the required loop that fills the array. Just do Arrays.sort after that loop.

By the way: to print an array, use System.out.println(Arrays.toString(array));
2 weeks ago
hi Hector,

welcome to the Ranch and enjoy the stay!

There's nothing wrong with your sorting, but to see the effect, it might be wise to fill the array first with random numbers, and then do the sorting.
2 weeks ago
The problem is that you have two fields rectanlgle, but in your paintComponent you use two different (local) rectangles. The field rectangles do not get changed, so that is why the rectangles that you see overlap and contimue their way.

So, in your paintComponent, just do:
My advice: make everything zero-based, so no messing around with row1 and row1. I would read the input and first put it in a List. Then check for the minimum value. Is that say 2, withdraw 2 from all the numbers in the list and then build the quickfind array.

Then check for the consistenr use of this zaro-based stuff. If you need help with that, then please supply the gui as well.
2 weeks ago
Another way is to make sure that a TreeNode knows how to determine its value. So, say, for a ConstantNode that would be just the value, for an AddNode that would be the sum of left.evaluate + right.evaluate.
So, given a Tree, all you need to do is: root.evaluate();

And for things like: a = 2 + 3, you could have an "assignmentNode", like Carey describes, but perhaps easier is to maintain a Map<String, TreeNode> so that when encountering the expression 'a = b + 2', you can look up b and protest if it is not in the map.
2 weeks ago
As you see, we have been translating those maps with its value into Predicates. So, what is a 'list of conditions' and how can the Predicates be determined from that? Please, give a really comprehensive example.
2 weeks ago
Yes, I see, that is a nice one! First thing that came up to me:

Suppose you have the Predicates p1, p2,... and you create a Map<Predicate, String>.

And then you have this method:

You could then have this code:

But there are probably easier methods thinkable!
2 weeks ago
It is still not clear to me what you mean. You write:

"If 3 conditions are there and 2 passes the filter"

You mean two employees that meet the three conditions, or employees that meet two of the three conditions?

"whereas I would want 2 output of the filter for the 2 successful conditions".

Can you explain what you mean here?
2 weeks ago

Mike Simmons wrote:Hm, Piet assumes you want some sort of combination of different filter results (...)


I assume nothing. My first example uses the Predicates default method 'and' where you are using the 'allMatch'. The second code snippet is just an example.
2 weeks ago