Solved

Drawing a line outside the paint method

Posted on 2004-09-09
9
273 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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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 the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

707 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