• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Bear Bibeault
  • Liutauras Vilda
  • Devaka Cooray
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

DrawString

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey! I have a trouble with Java programming - I need to create Java image using drawString and coordinates. It can be anything - owl, frog, house, but it should have 12 points. Could someone help me?
 
Ranch Hand
Posts: 116
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you give more details?

You can't really draw something like a house or a frog with drawString - drawString draws text on the screen.
You can draw something like that by having an image in your project and directly drawing the image, or by drawing multiple lines that look like an image.
To do this, you would call the drawLine() multiple times, making sure the coordinates of those lines are connected.

In general, to draw, you are going to want to grab the Graphics or Graphics2D object in the paint or paintComponent method, and then call the method you want.
See Graphics2D docs: https://docs.oracle.com/javase/7/docs/api/java/awt/Graphics2D.html
And Graphics: https://docs.oracle.com/javase/7/docs/api/java/awt/Graphics.html
 
Bartender
Posts: 3747
154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Asmodeus,

welcome to the Ranch and enjoy the stay!

Your question is a tad too short for me to understand. What do you mean by '12 points'? And drawString and coordinates remind me of a graphical environment. So, can you be a bit more specific?
 
machines help you to do more, but experience less. Experience this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!