/ Forside / Teknologi / Udvikling / Java / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
Java
#NavnPoint
molokyle 3688
Klaudi 855
strarup 740
Forvirret 660
gøgeungen 500
Teil 373
Stouenberg 360
vnc 360
pmbruun 341
10  mccracken 320
to draw line in swing?
Fra : somez72


Dato : 03-07-01 22:58

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.

if I draw line in canvas, is it possible to print out?


Best regards,
Sun haeng.



 
 
Lars Dam (03-07-2001)
Kommentar
Fra : Lars Dam


Dato : 03-07-01 08:31

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"

Søg
Reklame
Statistik
Spørgsmål : 177552
Tips : 31968
Nyheder : 719565
Indlæg : 6408847
Brugere : 218887

Månedens bedste
Årets bedste
Sidste års bedste