Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Custom painting is done by overriding the paintComponent() method of the panel. Then you use the Graphics object to do you painting.</p> <p>You should NOT have an empty paint() method.</p> <p>The drawline() method shouuld not use the getGraphics() method. Instead that code should be moved to the paintComponent() method and then use the Graphics object passed to the method.</p> <p>Also, you should NOT be overriding the paint() method of the applet. Since your code is painting the image at its actual size you should just use a JLabel to display the image by creating an ImageIcon. Then you add the label to the layered pane to use as your background image.</p> <p>Edit:</p> <p>Why do you still have the empty paint() method? Get rid of it there is no need to override the paint() method.</p> <p>When I run the code I get a security exception since applets are not able to write to a file so I can't test that part of your code. But in case you are interested I use <a href="http://tips4java.wordpress.com/2008/10/13/screen-image/" rel="nofollow">Screen Image</a> to create images of a component.</p> <p>However, you main problem is that the painting code is wrong. Yes you will see lines drawn, but they are not permanent. You should never use the getGraphics() method of a component when you want to do permanent paintinting. Try drawing some lines, then minimize the applete and then restore the applet and you will see what I mean. </p> <p>The solution for this is to do your drawing on a BufferedImage. See the <code>DrawOnImage</code> example from <a href="http://tips4java.wordpress.com/2009/05/08/custom-painting-approaches/" rel="nofollow">Custom Painting Approaches</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload