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!

Eric Madore

+ Follow
since Mar 16, 2020
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 Eric Madore

I have a solution. So I stripped down my code by commenting out some of the extraneous features for the purpose of my learning.
So I experimented with a couple of ideas, both of which worked.  I started by drawing a simple square using drawRect().  I created Setter/Getters
for the x and y coordinates.  I passed these as instance variables to the MouseListener.  I essentially reconstructed the rectangle and used the contains() method.
The next idea was to use a Setter/Getter for a rectangle object.  Instead of passing coordinates to the MouseListener, I pass a duplicate of the square. Much cleaner code
that way.  

My excitement over passing the rectangle is that I can calculate a rectangle around an arrow shape (which will indicate a continuing passage) and pass that
as a hit box for the mouse click. Would be a mess reconfiguring the arrow in the mouseListener.

The thing that I was not able to figure out (and I believe was the source of my problem) was that I could not cast the objects in my Arraylist to Shape, despite the
fact that they were drawn with GeneralPath().  I am sure this gets back to inheritance, lack of understanding of which is responsible for 80 - 90% of my newbie problems in Java.

Once I finish out the code, I will post it to hopefully help other fledgling Java-ologists, and to ask for recommendations to improve encapsulation as well as Object-Oriented design principles.
1 year ago
@ Piet Souris  So initially I had considered using JButtons with "custom" graphics. Figured it would be easier to program on click as I had done that before.
Then I decided to stick with the current plan to try to better understand Java overall.  That being said, is there a "best practice"? Or is the idea
to use what you can figure out? (That was only partially in jest!).  I may still go this route if I cannot figure out the Graphics solution.  

@ Rob Camick  Please excuse my density, but do I use a setter and getter for a Shape parameter that is saved as part of the Exit instance in the ArrayList?
                     I am not asking for the code, I just want to make sure that I grasp the process. Because I thought I did at first.  
1 year ago
@Piet Souris -  Not at all! Appreciate the patience of everyone posting.  It is interesting how the answer can sometimes be obvious, but still so difficult to see.
Again, a different way of thinking compared to the older languages I used.
1 year ago
I understand, just was trying to explain what I was trying to accomplish.  But now I (think!) I understand.  Thanks again for all of the responses!
Will post code once it is working.
1 year ago
Thank you for the responses.

The purpose of the program is to randomly generate a dungeon.  My ultimate goal is for the players to click on a exit and the program randomly generate the next dungeon segment.
I am trying to set it up so that when the player clicks the mouse, the program will iterate through the exit list, identify inside which specific exit the click occurred, and
generate the next dungeon segment appended to that exit.

The reason I have been using General Path instead of a simple draw rectangle, is that I am differentiating a door from a continuing corridor by drawing an arrow to represent the continuing corridor.

Would it be easier to use BitMap graphics to represent these items?
1 year ago
Seems some code is in order

This is where the difficulty lies, I have tried various methods to getBounds on the Exit, but it keeps returning the origin and size of my JFrame/JPanel

1 year ago
I am using an ArrayList to store references to Graphical Objects drawn with a GeneralPath method. I am trying to cycle through the list
after a MouseListener detects a mouse click.  I am then using getPoint on the mouseclick, and contains point on the graphical object to
detect if the click occurs within the bounds of a given object.  Would it be better to store a GetBounds reference with the object in the ArrayList, or
would it be better to calculate that as I iterate through the ArrayList? If my code would help I can post it. Hoping there is a general approach
that one could recommend.
1 year ago
I am a newbie that started reading books on Java about 2 months ago.

My last legitimate line of code was typed in 1992, and I honestly cannot remember if it was QuickBasic or Mathematica.
I am old enough I took a college course on FORTRAN, and my parents owned a TI-994A and a C64. Those were the days!

I am attempting to write programs that I would like for table top gaming and in my line of work. I am finding the transition from the
older procedural way of thinking to an object-oriented way of thinking difficult.  However, I see the benefit, and I am enjoying the process.

Many thanks in advance to all the Moderators and others who are kind enough to give their time and knowledge to educate others!!!
1 year ago
Thank you all!! Problem Solved, and each of you had me think of a different aspect. So thanks to all of you!

The solution was to place the call to draw the first chamber in the JFrame class.  And as mentioned I did not need to extend JFrame.
Also, I revised the method for placing the StartChamber in the Arraylist. I needed to cast it to DungeonFeature as the arraylist was expecting an object of that class.
Revised code as below:

1 year ago
Thank you for the responses! I am sorry, I was concerned the way I posted these with the commented code would be confusing.

When I run the code with the commented part uncommented, the mouseListener works fine.  The program draws the graphic appropriately.

But when I run the program WITHOUT the mouseListener I cannot get the program to draw the StartChamber directly.  The window appears,
but the background color is not set  appropriately, and the starting chamber is not drawn. Not sure if I explained it better?

Thanks again for the help!

This is the JFrame class that adds the panel

Here is the StartChamber class that constructs the first room

1 year ago
Hello, having problems as noted above.  Trying to make a game that randomly generates a dungeon. The commented part of the code below works.  I am trying to change the code to
draw a starting chamber automatically instead of relying on a mouse click to start the process. But when I alter the code to what is shown below, the window appears, but the
background color does not change and the chamber does not appear. The DungeonFeature and Exit arraylists hold objects of classes that extend DungeonPanel.

1 year ago