This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages forum!

rick pine

Ranch Hand
+ Follow
since Jul 13, 2016
rick likes ...
Netbeans IDE Java
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
6
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by rick pine

I did notice the enum type was incorrect and have fixed it. Also i figured it out, i just needed to create the method with paramteres of type enum. I was very wrong with what i thought i needed to do. Regarding the Mathrandom i will try to use a random instance instead. Thank you for replying, this the solution i came up with

4 years ago
Hello, i have a simple rock paper scissors game. That displays a gui with three jbuttons, place inside a jpanel two of which contain an image that is loaded by calling an enum that contains the images. I hope that made sense. Now whenever there is a match the result will be displayed in the middle jbuton that contains a jlabel, i can work out the logic inside of the gui class by saying something like, if icon on left jbutton equals rock and icon on right button equals paper, change the jlabel text to who ever wins, that is nice and easy. But being a school assignment im requiered to build a winner losser method inside of my enum class. The problem is that i dont understand how i can bring the components from the jframe into the enum. My idea is that i will need a method that returns a string because of jLabel.setText("some string").  the code its rather large, so i will post what i believe to be necessary to communicate my issue.




4 years ago
I have come up with this code to changes images by calling my methods change on an action listener if certain conditions are met. It works as intended however i dont like that i hardcoded the number of images im using, if i were to add a new image this my code would become garbage as it wont change dynamically. Im looking for a suggestion to improve what i did.



4 years ago
never mind guys i wasnt reading the instructions properly, dumb me. I have marked the question as resolved.
4 years ago
Im doing something wrong here, i think my problem its at the step " Initialize the field clickImage with a new ImageIcon that is based on Image3". My understanding is that the constructor does the initialization,  so after i create
the constructor, i cant go outside of it and say  field = new object... , i tried to initialize inside of the constructor but i got errors. The instructions do not say anything about initializing the fields on the ctor, it only says to change the tittle. So i also tried not initializing the fields on the ctor, and initializing at the same time as the fields are declared but it doesn't like this approach either. Can i get a hint about how to resolve this.


1- Create two final fields: imgButton of type JButton clickImage of type Icon
2- In the constructor do the following:
3- Set the title to Lab Button
4- Create two local variables of type Icon: image1 and image2.
5- Initialize them with a new ImageIcon base on Image1 and Image2 - like this:
  Icon image1 = new ImageIcon(getClass().getResource("Image1.png"));
6- Initialize the field clickImage with a new ImageIcon that is based on Image3
7- Initialize the field imgButton with a new JButton that accepts image1 as the only argument
8- Call the method setRolloverIcon on imgButton and pass image2 as roll-over icon
9- Add the imgButton to this (ImageButton, which is a JFrame)




4 years ago
I thank you all for your responses and helping me think this through.
I would like some advice if you guys dont mind. For this particular problem i was never told that i could pull out an element from a list without having to iterate though it, that is why i kept doing for loops every time i wanted to pull out a word to stitch it to my sb.
And this has happened often in class, im going to use another loop as example: I was thought how to use a nested for loop to create patterns, like a square , or a rectangle. But then the homework was to create said rectangle but with the perimeter only. So there i was seating at the tutor center having to ask them to explain to me how i could accomplish this daunting task. I feel like while in class im presented with a tool box and handed a carpenter hammer, but i know there is other tools in there that could be useful to get the job done. Then Im asked to put a nail on the wall, but i dont have a nail, so i must look in that tool box and find the nail but not just any nail, a specific one that fits the situation.
I dont know if that makes sense, i guess the question is, how can i turn that carpenter hammer into a jackhammer?, i feel like im confined to the material learned in class, i have browsed the web looking for examples related to what im learning but every time i browse the terms "java", "programming", "examples" im bombarded with content that doesnt even apply to my interest. I really want to become a god programmer but every time i hit a wall i feel deterred and feel like changing my major from Cs to History , talk about contrast.
4 years ago
This is exactly what i was thinking about doing, except i was thinking of posting on reddit and search within my local area. I tried a tutor from wyzant website but it was too expensive and not helpful at all.
I'll keep an eye on this post.
4 years ago
i noticed there is a comma after philosophy, is that the error you are referring to?
4 years ago
This came to me while watching tv. Its funny how after thinking so long with no answer I get an idea out of nowhere. So you guys kept saying "why use a loop if you only need one element", the thing is, i dint know i could just grab an element from an arraylist without looping it. That was never brought up during class, so all of a sudden i thoutgh:  if i can chain append and grab an individual list element without a loop then its done. So this is what i got.



output:
representatives from the english,  math,  philisophy, and computer science were present
4 years ago

Junilu Lacar wrote:No. Again, what's the point of using a for loop if you're only interested in one element? Pulling out the last element is done only ONE time. *Calculate* the index of the last element, (it's relative to the size of the list), then GET it out of the list and add it to your StringBuilder. Then add the last part of the string to the StringBuilder and you're done. Only thing left to do is display what's in the StringBuilder.




So i need to do something n times to the elements on the list, that something its add a comma in between, except for the last element. this is why i used the departments.size()-1 on the first loop. and added a comma, also on this loop im adding the content produced to my sb. On the second loop im only interested on the last element, hence the i = 0 ; i < 1; i++ , with this the loop goes through one time only and pulls out one element on position 3, i grab this element and add it to my sb. now my sb its almost completed, i just need to add one last part " were present", so i append again. then at the end i output the sb tha was built on the "work space".



4 years ago
im going to follow the "stop coding advice", i know it seems like an easy task for you guys but im struggling and need to cool off.
4 years ago
i think im almost there, im only missing the last element. I can do a second for loop and get the last element and modify the output, but i don't think that's the best way.
but this would be a nested for loop correct?

4 years ago
Here is what i worked out, looks pitiful but its getting it done.


System.out.println(sb);


representatives from the english, math, philisophy,

4 years ago
1. put "Representatives from the " in the work space
2. stitch on the first department name

To accomplish this, dont i need to iterate through the array list and pull the specified position? if i do this it means i need to loop thorough the list, and when i do, i get all the elements out not just the first one, or how else could i stitch an element from the array list to sb? I can also do sb.append(departments.toString()); but this again gives me the whole list.
4 years ago
I had a test in my class and was unable to come up with a solution, needless to say my grade will be low. But with that fact aside I still want to know how I could have resolved this...
I needed to create a department arraylist and use a string builder to produce the sentence " representatives from the english department, math department, philosophy department and computer science department were present."  This is the code i have, the output its simply the array list departments. I have no clue how to tackle this. Can i get some suggestions.


4 years ago