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.

Page 3 of 3 FirstFirst 123
Results 51 to 61 of 61

Thread: Tower Defense on Java

  1. #51
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Tower Defense on Java

    You often need to print out objects to see what is in them.

  2. #52
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Tower Defense on Java

    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.

  3. #53
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Tower Defense on Java

    Yes that describes inheritance.

  4. #54
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Tower Defense on Java

    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.

  5. #55
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Tower Defense on Java

    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.

  6. #56
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Tower Defense on Java

    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.

  7. #57
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Tower Defense on Java

    I've never seen anything that simple.

  8. #58
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Tower Defense on Java

    Quote Originally Posted by snowguy13 View Post
    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!
    You'll want something more like:

    LinearGradientPaint gradient = new LinearGradientPaint(start, end, fractions, colors);	
    g2d.setPaint(gradient);		
    g2d.fillRect(0, 0, getWidth(), getHeight());

    You might consider posting separate questions in separate threads.
    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!

  9. The Following User Says Thank You to KevinWorkman For This Useful Post:

    snowguy13 (December 20th, 2011)

  10. #59
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Tower Defense on Java

    You might consider posting separate questions in separate threads.
    Okay. I'll do that in the future, after this is solved (pointless to start a new thread halfway through a solution).

    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.

  11. #60
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Tower Defense on Java

    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!

  12. #61
    Junior Member
    Join Date
    Dec 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Tower Defense on Java

    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

Page 3 of 3 FirstFirst 123

Similar Threads

  1. Extended Hanooi Tower
    By mahsa in forum Algorithms & Recursion
    Replies: 1
    Last Post: December 31st, 2010, 05:55 PM