Solved

Drawing a line outside the paint method

Posted on 2004-09-09
9
272 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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:
Suggested Courses

734 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