Solved

Drawing a line outside the paint method

Posted on 2004-09-09
9
267 Views
Last Modified: 2012-05-05
Hey Experts!

Well, I guess the question explains itself....In the paint method you can easily draw a line with the Gaphics object g and the method draw line; however, outisde it, if I want to draw a line I can't  do that because Graphics is an abstract class, and thus I cannot instantiate objects of its type to draw lines. Is there a simple way to draw a line inside a function?
0
Comment
Question by:mte01
  • 3
  • 3
  • 3
9 Comments
 
LVL 24

Expert Comment

by:sciuriware
ID: 12018587
You must not create a Graphics object yourself! paint gives you a reference
to a Graphics object. The object is surely "bigger" that the abstract class,
but the abstract class is just a kind of guarantee that some methods
will be implemented. Why not call another method with such an object as an argument?

;JOOP!
0
 
LVL 3

Author Comment

by:mte01
ID: 12018644
>> Why not call another method with such an object as an argument?

I tried, but I couldn't (you have to instantiate something at some point)...how could you do that??
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12018720
I wonder what weird programming you are doing.
What would you instantiate more than you got?

;JOOP!
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 420 total points
ID: 12018771
>>Is there a simple way to draw a line inside a function?

You can draw a line from anywhere as long as you've got a reference to a Graphics context
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 3

Author Comment

by:mte01
ID: 12018782
I didn't understand your last comment.....anyway let's go back to our main point:

>> Why not call another method with such an object as an argument?

How could you do that? and how could that help in drawing a line inside a user function (which is just all what I want to do)
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 420 total points
ID: 12018808
void foo() {
    component.getGraphics().drawLine(.....);
}
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12018845
I give up. CEHJ can certainly handle this.

Good night.

;JOOP!
0
 
LVL 3

Author Comment

by:mte01
ID: 12018866
Excellant CEHJ that's all what I wanted!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12018935
8-)
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now