Help coderanch get a
new server
by contributing to the fundraiser

Dick Hammer

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

Recent posts by Dick Hammer

OK so some more searching led me to something about a "wrapper" and the fact that String is in fact already a wrapper class. So why won't this work? I guess it's got nothing to do with primitives? My bad.


The solution was I needed to include the correct libraries such as

import java.util.ArrayList;
import java.util.List;
import java.util.Collections;
import java.util.Arrays;

leaving this up for other noobs like me, but it's been solved. Include the correct libraries and use a correct wrapper class.
12 years ago
This was working fine when "labels" and "ListofCars_1" were arrays. But I made them a list and now it won't work.


Expression should be an Array but resolves to List <String>. I tried typing something like

But that did not work either. Any help would be appreciated.
12 years ago

^ won't work but this one below will?

Okay. What would be the equivalent for a string array? In this example? "Integer" is just a word? I mean shouldn't it be declared first someone else, like a type of some kind? So we could use

As long as "Taco" is typed somewhere I'm guessing?

12 years ago
Doh I think we were both editing and posting at same time.

So Rob, I can in fact declare it as "List" and/or "ArrayList", but if I want to declare it as "List" I have to import java.util.List? And declaring it as "List" is better right?

Internet searches did not mention that library. Looked it up in my Deitel book as far as declaring it as ArrayList though.

List <Integer> intlist = new ArrayList<Integer>();

should be

ArrayList<Integer> intlist = new ArrayList<Integer>();

But I will try that library Rob since it's better. Thanks Rob.

12 years ago
"List cannot be resolved to a type." is the error message I get. I copied and pasted it from the web examples. I tried a few different ones. Why am I getting that error. The web examples are very simple and don't include libraries but I looked it up and I made sure to import the libraries as so:

Neither of the two list declarations work. What am I missing? I have bunch of other code ...main etc, but everything was working fine until I tried adding that list thing. The list declarations are outside of main, below the "import" declarations....there with my other variables. Any help would be appreciated.

12 years ago
LOL Campbell. Thanks Fred. I guess I made a pretty nifty infinite loop.
12 years ago
I have a program with a few functions and it works fine, but then I add a for loop to fill an array and I have tried adding this to *two* separate programs and it causes it to hang

It's just a for loop that I copied and pasted from the web on how to fill an array using a for loop. What am I doing wrong?
12 years ago
Can someone give me an example of how to use collections.shuffle on an ArrayList so that I can generate 16 non-repeating random I mean "random" numbers. I've read up on generating non-repeating random numbers but it just complicated things (Like someone pointing out that non-repeating random numbers are not technically random because random numbers do repeat. *face to palm* For ****'s sake ok? *simulates blowing his brains out* Yah, ok I get that it's not random, but you know what I am getting at, yeah? Random numbers from a declining population...however you want to think about it. And besides, it IS random...the sequence will not be random, but each iteration the selection of a number (from a narrowing range) is random so forgive my sloppy get the point...I'm trying to write a little proggie that will display 16 images on the screen in a 4x4 array but each iteration the order of the cards or images is random. I would really appreciate any help. What's the best way to go about this? I have searched and like I said I found info including "shuffle" but it gets vague and could not find good examples. I want to know how to drive a car and I found explanations of internal combustion, ya know what I mean? Cheers.
12 years ago
No need to move it. You answered the question for me. Thank you!
12 years ago
I am pretty new to Eclipse windows builder and Java and I created these tabs with Labels and buttons, but I am not able to move them around? Anyone know why not? If I put a label in a jframe, and I select absolute coordinates, I am able to move them as I wish, but not when I put them in in a tabbed pane? Also wheneever I add another label or button, it creates another pane!

12 years ago
Ok thanks, check out the new edited code above.
12 years ago
Ok I edited this post in response to

Ralph Cook wrote:This is pretty much unintelligible.

It took me too long to make out that you have not posted all the code. Your description of what is supposed to happen and what does happen is also a bit obtuse; I could make some guesses about what you mean, but it likely wouldn't help since I can't see the code.

I suggest boiling down what you want to do to a small example -- put the variables in the scope they have to be in the real app, to ensure you can get to them from where you want to, but a couple of labels and buttons and a listener or two should be all you need. And then show us all of it -- where you modify these variables, where you attach the listeners, all of it. Often, in the process of making a small executable example of what you're trying to do, you may even discover the answer yourself.

Sorry about the confusion, I had kept some of the code collapsed for readability, but no need to have two big blocks of code, so here's the new shorter program. I don't understand why the method do_btnJbutton_mousePressed doesn't setText correctly. The variable TheFilePath should get set by the call to RandomNessGenerator(). What am I doing wrong in the code?

12 years ago
I had done it successfully using Netbeans in this example:

But now, I switched to Eclipse (using the WindowBuilder Pro plugin). It generates a method stub, which I filled with

JLabel lblJlabela = null;
lblJlabela.setIcon(new ImageIcon("J:\\Eclipse Folder\\Eclipse1GUI\\Photos\\Viper3.jpg"));

I had to add the first line of that because it was telling me that lblJlabela was "unresolved" auto-suggested that I do that. But here's the whole program.

It runs and displays a jFrame with the two initial photos, but when I press my mouse over "LabelA", nothing happens. It gives these message in console:

at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at Source)

How can I get it to work so that I change images in that jLabel?
12 years ago
thanks I think it worked
12 years ago

Michael Dunn wrote:100% agree with Darryl, but if you really want to modify the generated code:

1) add this line to the section // Variables declaration - do not modify
JLabel[] labels;

2) add the indicated line

unless the 'Variables declaration' section is regenerated, you will now be able to access the labels via

It gives me errors. Something about not finding symbol? Oh and if I figure out how to edit that closed section of code of "private void InitComponents" would I have to change jLabel1 = new javax.swing.JLabel(); to labels[0] = new javax.swing.JLabel();? And also, there is no "Variable Declarations" section.

12 years ago