You often need to print out objects to see what is in them.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
You often need to print out objects to see what is in them.
This question probably belongs more in object-oriented programming, but I've grown attached to this thread now.
The way I'm organizing my tower classes is that I have a superclass, called Tower, which contains all the fields that every Tower needs to have. Then, I extend that class to make the actual tower classes. So for example, I have...
public class FlareTower extends Tower
...so that the FlareTower class gains all of Tower's fields and methods.
Where my question comes is here: if I tell a method to take a Tower as an argument, for example...
public void addTower(Tower t)
...or something like that, and then I use the method in a code like this...
addTower(new FlareTower());
...would Java accept that? So, even though I actually input a FlareTower as the argument and the method expects a Tower, wouldn't Java accept it because FlareTower is a subclass based on the class Tower?
Use highlight tags to help others help you!
[highlight=Java]Your prettily formatted code goes here[/highlight]
Using these tags makes your code formatted, and helps everyone answer your questions more easily!
Wanna hear something funny?
Me too.
Yes that describes inheritance.
Okay. Thank you! That is good to know before I accidentally write 20 more methods than I actually need to.
Use highlight tags to help others help you!
[highlight=Java]Your prettily formatted code goes here[/highlight]
Using these tags makes your code formatted, and helps everyone answer your questions more easily!
Wanna hear something funny?
Me too.
Alright, now I've got a new little idea. Soon, I will have my OpenGameGUI completed. One of the sections of the OpenGameGUI will be the "Levels" tab. What I want to happen is this: when the user hovers over a level's icon (for example, level 1 will have a square button that says "1" on it), I want a JPanel to appear next to the mouse displaying information on the level (so, if it's locked, say so; if the user has beat it, display his/her best score, etc.).
I know I can use a MouseListener to display the panel tooltips and a MouseMotionListener to move the panel tooltips with the user's mouse, but how can I make the panels that will act as tooltips appear on top of the other Components of the GUI? I've heard of GlassPanes and Z-alignment, but I'd like some advice about which way is the best to go, and may some good documentation to look at. Thanks!
Use highlight tags to help others help you!
[highlight=Java]Your prettily formatted code goes here[/highlight]
Using these tags makes your code formatted, and helps everyone answer your questions more easily!
Wanna hear something funny?
Me too.
Hmm... A random curiosity struck me. Is there any way to create a gradient fill for components, instead of just using...
<Component>.setBackground(Color c);
...? Or perhaps a special type of color that is actually a gradient? Any help would be appreciated!
Use highlight tags to help others help you!
[highlight=Java]Your prettily formatted code goes here[/highlight]
Using these tags makes your code formatted, and helps everyone answer your questions more easily!
Wanna hear something funny?
Me too.
I've never seen anything that simple.
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
snowguy13 (December 20th, 2011)
Okay. I'll do that in the future, after this is solved (pointless to start a new thread halfway through a solution).You might consider posting separate questions in separate threads.
g2d.setPaint() is telling the g2d (Graphics2D Class, right? or is g2d an instance?) to use the specified gradient to paint Components, and g2d.fillRect() fills the specified area of a... JFrame? Component? How can I apply this to a JLabel?
Thanks for your help!
Use highlight tags to help others help you!
[highlight=Java]Your prettily formatted code goes here[/highlight]
Using these tags makes your code formatted, and helps everyone answer your questions more easily!
Wanna hear something funny?
Me too.
Yeah, g2d is an instance of Graphics2D. You can get one by overriding paintComponent and casting the Graphics Object, which is actually a Graphics2D Object. And it fills whatever you want, you just have to override paintComponent.
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
I'd say do the second choice, but then from within that super class you make multiple classes in which you detail what each of the objects are, if your a beginner, it might take a while to get to write that code