On Tue, 3 Jul 2001 14:58:12 -0700, "somez72" <somez72@chollian.net>
wrote:
>Hi,all
>if I want to draw line or rectangle in swing, how can I do?
>what I mean is what class library can I use?
>
>I don't want use canvas class in awt.
Use JPanel in swing instead. JPanel replaces Canvas when going from
awt to swing.
To draw a line on the JPanel, derive from it, and override JComponent,
and implement paintComponent():
class MyJPanel extends JPanel{
public void paintComponent( Graphics g ){
g.drawLine(0,0,100,100);
}
}
>if I draw line in canvas, is it possible to print out?
Yes. Check the class printJob. You should obtain a printJob instance,
and from that you get a Graphics object you can pass to your
paint(Graphics) method in your Canvas (or paintComponent(Graphics) in
a JPanel).
You might need to adjust your code to the specs of your printer
(DPI/page size etc. That info is available in the printJob instance).
>
>Best regards,
> Sun haeng.
>
kr. ld
--
"Time is the fire in which we burn"
|