Questions about drawing on Canvas



Greetings,

I am attempting for the first time to do some drawing on a canvas.
What I would like to do is draw a standard set of three orthogonal
axes and then superimpose a line (vector) on the canvas as well, to
aid in visualizing some rotations. The questions I have are as
follows:

1. If I want the vectors to have any thickness, it sounds like I am
going to have to call drawRect() instead of drawLine() - true or
false?
2. In my reading, I have seen code examples where they seem to extend
JPanel (I don't know why such a graphical object would subclass from a
panel, so I'm a bit puzzled by that) and override its paintComponent()
method. Why do you subclass from JPanel to draw rectangles, etc.?
3. Must you do everything to each thing you want to draw that you
would do to other container components (e.g. my canvas) such as
frame.add(canvas) and canvas.setVisible(true), etc.?
4. When you do a setColor(color), it seems like it's just telling the
Graphics object "you're about to do something and I want you to do it
with this color). Is that correct? Why can you get away with not
specifying the fg and bg colors each time (for example, if you want to
draw a red rectangle with a black border, I have seen in that example
where they make two calls to setColor())?
5. Is there a specific order to packing and adding things before
showing them? I'm a little confused on what the absolute last thing
is that you need to do when you want to show your combined UI. (In
other words, I have a frame which contains the canvas, the axes, and
the vector, and so far I can only get the canvas to be drawn.)

I am hoping there are some simple answers here but unfortunately none
of the Java tutorials I have seen on Sun or in my manuals I printed
seem to provide any concrete answers. If you know of any good
websites that really explain the graphics paradigm well, I'm open to
hearing about them.

Thanks in advance,
Mike
.



Relevant Pages

  • Re: Questions about drawing on Canvas
    ... I am attempting for the first time to do some drawing on a canvas. ... Why do you subclass from JPanel to draw rectangles, ... // TODO Find out what effect removing these LOC will have. ...
    (comp.lang.java.programmer)
  • Re: Questions about drawing on Canvas
    ... axes and then superimpose a line on the canvas as well, ... Why do you subclass from JPanel to draw rectangles, ... // TODO Find out what effect removing these LOC will have. ...
    (comp.lang.java.programmer)
  • Re: Newbie looking for info on basic graphics with Delphi.
    ... panel objuct on the main form. ... some of them draw on their parent's canvas. ... I think all of Windows' ...
    (comp.lang.pascal.delphi.misc)
  • Re: Newbie looking for info on basic graphics with Delphi.
    ... Do I need to use a canvas to draw? ... Posted via NewsDemon.com - Premium Uncensored Newsgroup Service ... Unlimited Access, Anonymous Accounts, Uncensored Broadband Access ...
    (comp.lang.pascal.delphi.misc)
  • Re: Canvas tp display audio waveform
    ... > I've had limited success displaying the audio waveform of a 16 bit ... > simple and I don't know how to draw points and connect them with lines. ... > In a window with a pushbutton, a listbox and a canvas on it I use this ... Do you have some reason to believe that a WAV file is ...
    (comp.lang.basic.realbasic)