Matthew Bendford wrote:couple of advises:
don't extend from JFrame unless you alter its base behaviour - your code isn't a JFrame, it uses one
when dealing with swing make sure to override paintComponent() instead of paint()
I didn't look at your listeners, but be aware of how to deal with swings thrwading policy
And give it protected access, not public. There is a format for the first line of that method which you should use so as to get the display blanked before you draw anything.Go through the Java™ Tutorials (I think the 2nd and 3rd sections thereMatthew Bendford wrote:. . . override paintComponent() instead of paint() . . .
Campbell Ritchie wrote:Moving to our GUIs forum
Norm Radder wrote:The code does not compile because of missing Rectangle2D class definition.
How can the code be compiled and executed for testing?
Pat Watson wrote:
Norm Radder wrote:The code does not compile because of missing Rectangle2D class definition.
How can the code be compiled and executed for testing?
The Rectangle2D is defined and I created an object before using the reference. Is that what you mean?
These are my codes
Norm Radder wrote:Where is the color set? I the bottom of a rectangle is displaying as red.
Also what was the value of the rectangle's width and height?
Note: Rectangle2D is the name of a java SE class. It is better if you do NOT give your classes the same names as java SE classes.
What is the need for the Rectangle2D class in the current program?
I added this to ShapesPanels for testing:
Norm Radder wrote:Please post your current code that can be compiled and executed for testing.
Norm Radder wrote:The paintComponent method is in the ShapesPanels class so the drawing coordinates are for that panel. If you want the drawing to be defined by the coordinates for the centerDrawPanel object, then the code needs to override the paintComponent method for that instance of JPanel.
nothing was happening with ActionListener
I can see another potential problem: there already is a class called Rectangle2D. If you use that awt.geom class, you can have all sorts of confusion.Norm Radder wrote:. . . missing Rectangle2D class definition. . . .
Sorry. Not pleased with that inheritance. I don't know about the Shape class, but let's forget that and create a Shape2D class without specifying a supertype, so its direct supertype is now Object. Let's start with the class looking the same as what you showed.. . These are my codes . . .
I suggest reading about lambdas a bit if you find that statement confusing: https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.htmljava tutorial wrote:all code that creates or interacts with Swing components must run on the event dispatch thread
Yes, that's a good idea. It exactly matches our purpose in this case.Campbell Ritchie wrote:Should we use Actions instead of action listeners?
ice is for people that are not already cool. Chill with this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
|