• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

inherited from the Component class

 
David McHugh
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

what is the syntax to call a repaint object that is inherited from the Component class via Container and JComponent classes???
 
Campbell Ritchie
Sheriff
Pie
Posts: 49793
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
repaint(); ??

And the paintComponent method should read like this:Probably best to move this thread to the Swing forum where they usually discuss this sort of thing.
 
David McHugh
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi cambell, didn't seem to work, gave me a cannot find symbol error..
i have posted my original code below, it is the bit at the bottom plotdarryl.repaint giving the problem, it would usually work but i realised in the question it says "repaint Not part of PicturePlotter; inherited from the component class via Container and JComponent classes, so at that point i need to jiggle the code slightly??? cheers

 
Rob Spoor
Sheriff
Pie
Posts: 20609
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And what is this PicturePlotter object?
 
David McHugh
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi rob,

picture plotter is where all the classes are stored i.e. plot, setColorTable and repaint but plotdarryl.repaint(); does not work because it says "repaint Not part of PicturePlotter; inherited from the component class via Container and JComponent classes"

cheers
 
Campbell Ritchie
Sheriff
Pie
Posts: 49793
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And as Rob was asking, what is PicturePlotter's inheritance hierarchy?
 
David McHugh
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi campbell,

is this what you mean?

class PicturePlotter extends JComponent
public PicturePlotter(int width,int height)
public void plot(int x, int y, int color)
// Plot a single pixel at (x,y) in the given color.
public void plot(int x, int y, int count, int color)
// Plot count pixels at (x,y) in the given color.
public void setColorTable(int[][] table)
// Set a user defined int-based color table.
// Turn the table into Color objects.
public void repaint()
// Call to tidy up display of image
// Not part of PicturePlotter; inherited from the
// Component class via Container and JComponent classes
 
Campbell Ritchie
Sheriff
Pie
Posts: 49793
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, thank you, that is what I wanted.

I can't see why you are having problems.

Has somebody else given you the PicturePlotter class? If it extends JComponent it will have several overridden repaint() methods inherited from java.awt.Component and javax.swing.JComponent; the no-args version is from Component. So I can't see why it doesn't work.

Please check your imports that you are actually importing javax.swing.JComponent and you haven't somehow found another class called JComponent. [You probably don't need to import Component.]

What actually happens? I can think of three ways it can go wrong
  • Compiler errors. In which case you might be reverting somehow to an old version of the .class files.
  • Exception when starting up.
  • Exception after it has run for some time.
  • Sorry I'm not more helpful.
     
    David McHugh
    Greenhorn
    Posts: 23
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    cheers for your time campbell, it is a strange one really, i will get the answer on tuesday and let you now what was wrong, it is only a simple exercise so it must be something small i am missing, but that is inexperience for you!!!
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic