• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What's wrong with my DrawLine

 
Litas Lee
Greenhorn
Posts: 10
Debian Eclipse IDE Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't work. I wander where is the mistake. I just want to draw a line.


 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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/
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15219
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does "it doesn't work" mean exactly?

The code you posted is not a complete program. Is your method called unknown called anywhere?
 
Litas Lee
Greenhorn
Posts: 10
Debian Eclipse IDE Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still, nobody is calling the unknown method.
Did you check out the link I had provided?
 
Litas Lee
Greenhorn
Posts: 10
Debian Eclipse IDE Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15219
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Litas Lee wrote:And this method must named as paintComponent right?

What happens when you try it?
 
Litas Lee
Greenhorn
Posts: 10
Debian Eclipse IDE Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic