File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 10535
    
    9

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: 14433
    
  23

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 8 API documentation
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: 10535
    
    9

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: 14433
    
  23

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: 40052
    
  28
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