Peter Seeger

Greenhorn
+ Follow
since Aug 14, 2018
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
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Peter Seeger

Stephan van Hulst wrote:Two questions. Why are you using a random index, and why are you checking for listeners in the first place?


I want to make a TicTacToe "AI" that places an "O" on a random, free button.
5 years ago
I tried to check an array of buttons for buttons without action listeners. This is with what I came up:

But the buttons the program selects through this project sometimes have, and sometimes they dont have an action listener.
Thank for your help!
5 years ago

Carey Brown wrote:This seems overly complex. Can you describe in English what your overall requirements are?


Sorry I am just experenting with some things. Still appreciate your patience! I want someting in a for loop to run through every time (Yes, that works!) But the variable that you are counting up to end the loop at some point should only increase e.g every five times.
5 years ago
Oh, sorry didn't know this was a problem:

So, thats the entire code!
5 years ago
I want to do this because I want to add multiple arrays to one ArrayList to manage them better. Here is what I tried so far:

Size is how big the steps should be in that I want to count up, but it is also how many loops should be going through without counting up.
I don't know if I just searched the wrong thing but I couldn't find anything...
Thank you!
5 years ago
I had a return statement in the original code, maybe I should have included it in here. And thank you for your tipps!
5 years ago

Stephan van Hulst wrote:Because some people find that bad practice. Don't ask me why. I think it's silly and usually disable this warning in my IDE.

In your particular case it kind of makes sense though. Why does your method take a buttonArray parameter when you're going to overwrite the passed value immediately? Java is pass-by-value and method parameters can't be used to change the variable in the calling code.

Another thing that doesn't make sense is that your method is called setArrayLists, but it doesn't set anything and it doesn't work with ArrayLists.


Yeah like this it doesn't make sense but this is just a shortened part of may code, but thank you very much!
5 years ago
I want to know if it is a good idea to assign an array like this:

Because I then I get the warning "The parameter buttonArray should not be assigned". But why is this bad?
Thank you!
5 years ago
I was trying to get a random, enabled button from an array of buttons but the solution I came up with is not very elegant:

The problem is, that it can be possible that the computer doesn't find such a button. Yes it is very unlikely but not impossible. So how can I do this better?
Thank you!
5 years ago

Piet Souris wrote:

In your code, you have two Main objects, with ditto buttons. One Main is set in the main method of Main itself, the second Main is created in the setActionListener() method of te class ChangeButton. It is that second button that has its color changed, but the first button, as shown in the frame, is left unchanged. Therefore you see nothing happening with that button.


Okay, thanks. This is my first program with multiple classes, so I was not aware this was a problem. But if I remove the mainObject from the main - method how should I call buttonManager without making it static? Or do I have to?
5 years ago
I tried to change the background color of numerous JButtons in two different classes. In one, it is working in the other it isn't . I'm sorry if this question is not really hard, but I just can't figure it out. Here the simplified code:
Main - class

And the ChangeButton - class

I know this version f the code doesn't always make sense, but I just wanted an example that is short and produces the same problem.
5 years ago