*
The moose likes Swing / AWT / SWT and the fly likes What's wrong with my DrawLine Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "What Watch "What New topic
Author

What's wrong with my DrawLine

Litas Lee
Greenhorn

Joined: Apr 18, 2012
Posts: 10

It doesn't work. I wander where is the mistake. I just want to draw a line.



The wind in June reconciles my sadness and the rain in July makes my dream. In Auguest, I turn to a green fruit with your gorgeous shine. In September, the mature fruit you see is the flower you see in May.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9993
    
    7

Welcome to the Ranch.

From what you have shown, no one is calling the unknown method so that code is not getting executed.
For the correct way to perform custom painting check out http://docs.oracle.com/javase/tutorial/uiswing/painting/


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13884
    
  10

What does "it doesn't work" mean exactly?

The code you posted is not a complete program. Is your method called unknown called anywhere?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Litas Lee
Greenhorn

Joined: Apr 18, 2012
Posts: 10

Jesper de Jong wrote:What does


Here is complete program


I just see a window titled "draw a line", and nothing is on the component.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9993
    
    7

Still, nobody is calling the unknown method.
Did you check out the link I had provided?
Litas Lee
Greenhorn

Joined: Apr 18, 2012
Posts: 10

Maneesh Godbole wrote:Still, nobody is calling the unknown method.
Did you check out the link I had provided?


Thanks for your replay.
So I must amend my unknown method as

And this method must named as paintComponent right?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13884
    
  10

Litas Lee wrote:And this method must named as paintComponent right?

What happens when you try it?
Litas Lee
Greenhorn

Joined: Apr 18, 2012
Posts: 10

Jesper de Jong wrote:
Litas Lee wrote:And this method must named as paintComponent right?

What happens when you try it?


It drew a line as I wanted.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36579
    
  16
Welcome to the Ranch

Since this appears to be a GUI-related question, I shall move it to our GUIs forum. The paintComponent() method ought to have protected access, not public. You don’t usually call it yourself; it is called by the JVM whenever you need to “paint” that component. And beware: it’s paintComponent not paintComponents, which you might come across some time.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What's wrong with my DrawLine
 
Similar Threads
SDK1.4, new IO ops, and creating JPGs...oh my!
Problem in reloading graphics object.
Can anybody help??
AffineTransform "transform" method
How do read a double datatype 2D array into your applet code from a text file