Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Graphics Objects(URGENT)

 
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I want to create Gaphics objects (not in an applet).How to create Graphics objects without paint method?
Plz let me know by an example,
Thanks
angela
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the easy answer is that you extend the abstract Graphics and provide implementations for the abstract methods.
I expect that this is not what you meant.
You can create another graphics from an existing graphics using the create method.

From the API:
create
public Graphics create(int x,
int y,
int width,
int height)
Creates a new Graphics object based on this Graphics object, but with a new translation and clip area. The new
Graphics object has its origin translated to the specified point (x, y). Its clip area is determined by the intersection of the
original clip area with the specified rectangle. The arguments are all interpreted in the coordinate system of the original
Graphics object. The new graphics context is identical to the original, except in two respects:
The new graphics context is translated by (x, y). That is to say, the point (0, 0) in the new graphics context is the
same as (x, y) in the original graphics context.
The new graphics context has an additional clipping rectangle, in addition to whatever (translated) clipping rectangle it
inherited from the original graphics context. The origin of the new clipping rectangle is at (0, 0), and its size is
specified by the width and height arguments.
Parameters:
x - the x coordinate.
y - the y coordinate.
width - the width of the clipping rectangle.
height - the height of the clipping rectangle.
Returns:
a new graphics context.
See Also:
translate(int, int), clipRect(int, int, int, int)

However I have the funny feeling that you are REALLY asking how to get images into you GUI's
 
Angela Jessi
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Cindy,
Sorry I have asked wrong question? I meant to ask that Without creating or initiating Graphics objects , can I just access FontMetrics or getFont method in class(not in applet)?
I solved this question myself.
Thanks again,
Angela
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi angela,
Without creating or initiating Graphics objects , how can I just access FontMetrics or getFont method in class(mine is a servlet and nota class/applet)? It seems you hae figured that out. Please let me know too.
Than you,
tarun
 
Angela Jessi
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I used FontMetrics fontMetrics = applet.getFontMetrics(f);
Where f is object variable of Font class
Thanks
angela

Originally posted by tarun Mehra:
Hi angela,
Without creating or initiating Graphics objects , how can I just access FontMetrics or getFont method in class(mine is a servlet and nota class/applet)? It seems you hae figured that out. Please let me know too.
Than you,
tarun


 
tarun Mehra
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey angela,
Thanx a bunch. I just never realised that there was a getFontMetrics method for the component class. And all this time I thought that it could be applied only to Graphics objects. This really solved my problem.
Thank you, I appreciate it.
tarun.
 
He was giving me directions and I was powerless to resist. I cannot resist this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic