Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Hi i'm trying to do a diamond. i don't know whats wrong with my program. so can anyone help  RSS feed

 
Nathalie Monvoisin
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi i'm currently trying to do a diamond using Polygon.
i have done this so far.
can anyone tell me whats wrong. it is not drawing a diamond.
 
Campbell Ritchie
Sheriff
Posts: 55329
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use the paint method. Override paintComponent (with protected access).
 
Nathalie Monvoisin
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like this ?

 
Rob Camick
Ranch Hand
Posts: 2787
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is your SSCCE? You asked for an example SSCCE in your first question and your were given one.

Why does you code not look like the painting code found in the Swing tutorial on "Custom Painting". In your first two questions you were given a link to the tutorial.

Why are you not following the advice given in the past? If you want help in the future, make sure you follow advice given in the past. We don't have time to keep repeating ourselves.
 
Nathalie Monvoisin
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
should the code look like this?
 
Rob Camick
Ranch Hand
Posts: 2787
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly.

Now why are you using negative values? Negative values will be painted outside the view of the panel.

Start with something simple, like a square. It should be easy to define the four points of a square.

Once you get that working change the 3rd set of points to stretch one vertex. Then try changing other points. The hard part is not the GUI code. The hard part is specifying your points correctly.

In other words start with something simple and then make changes one at a time to see what happens so you understand what is happening.

Also, this SSCCE can now be used as a basis for all future questions. The main() and createAndShowGUI() parts will be the same. All that will change in the future is the panel. In most cases you will add components to the panel to demonstrate a problem.

A SSCCE is a great tool for simplifying your problem.
 
Nathalie Monvoisin
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Rob Camrick. i will try to start with a square first
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!