Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / November 2005

Tip: Looking for answers? Try searching our database.

Graphics2D problem

Thread view: 
Thanasis (sch) - 24 Nov 2005 15:32 GMT
Hi to all,

i describe a drawArrow method below, which takes 5 parameters : a graphics
object g and the coordinates of 2 points.
What i want to achieve is to draw a dotted line
whenever i pass a Graphics2D object to drawArrow method and a solid line
whenever
i pass a Graphics object.The problem is that even if i pass a
graphics object to drawArrow method i get a dotted line.
Why does this happen?

thanasis

===============================================
public void drawArrow(Graphics  g, int x1, int y1, int x2, int y2){

if (  g  instanceof  Graphics2D   ){

    Graphics2D g2=(Graphics2D)g;
     g2.setStroke (new BasicStroke(1f,BasicStroke.CAP_ROUND,
     BasicStroke.JOIN_ROUND,1f,new float[] {5f, 7f }, 0f));
  }
  g.drawLine(x1,y1,x2,y2);
}//end of method
=================================================
Andrey Kuznetsov - 24 Nov 2005 16:03 GMT
> i describe a drawArrow method below, which takes 5 parameters : a graphics
> object g and the coordinates of 2 points.
[quoted text clipped - 4 lines]
> graphics object to drawArrow method i get a dotted line.
> Why does this happen?

although variable g is declared as as Graphics (for backwards
compatibility), it points to Graphics2D object
Probably you have to run your app on java 1.1 to get solid line painted,
however it wouldn't compile on java 1.1 and compiled on java2 it wouldn't
run on 1.1...
You could solve this problem Reflection.

HTH
Signature

Andrey Kuznetsov
http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.