Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think your design is way off and that is why things are not working. I'm not quite sure how your non-abstract JPanels work, but consider making your parent JPanel something more along these lines:</p> <pre><code>import java.awt.*; import java.awt.event.*; import java.awt.image.BufferedImage; import javax.swing.*; public class MyPanel extends JPanel { private GraphicsEnvironment ge; private GraphicsDevice gs; private GraphicsConfiguration gc; private BufferedImage offScreen; public MyPanel(boolean visible) { super(); this.setLayout(new BorderLayout(640, 416)); // strange constants for this layout. this.setOpaque(false); this.setVisible(visible); ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); gs = ge.getDefaultScreenDevice(); gc = gs.getDefaultConfiguration(); addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { setUp(); } }); } @Override // don't make this public. Keep it protected like the super's // just draw in this method. Don't call other methods that create buffers // or draw to buffers. protected void paintComponent(Graphics g) { super.paintComponent(g); if (offScreen != null) { g.drawImage(offScreen, 0, 0, null); } } private void setUp() { offScreen = gc.createCompatibleImage(getSize().width, getSize().height, Transparency.TRANSLUCENT); } // draw to the buffer outside of the paintComponent // and then call repaint() when done public void upDateOffScreen() { // ?? offScreen.flush(); // I've never used this before, // so am not sure if you need this here Graphics2D osGraphics = offScreen.createGraphics(); // TODO: do drawing with osGraphics object here osGraphics.dispose(); repaint(); } } </code></pre> <p>Also and again,</p> <ul> <li>Do all long processing methods off of the EDT (Event Dispatch Thread).</li> <li>Never call Thread.sleep(...) on the EDT.</li> <li>Consider using Swing Timers instead of using Thread.sleep for the animations.</li> <li>It's OK to call repaint on your JPanel off of the EDT, but for the most part that's about it. </li> <li>All other Swing methods should be called on the EDT.</li> <li>Read, re-read, and study the 2D and Swing graphics tutorials.</li> </ul>
    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