Note that there are some explanatory texts on larger screens.

plurals
  1. POJava not calling component's overloaded paintComponent method
    primarykey
    data
    text
    <p>First this is part of a homework assignment to create a mosaic image generator. I want the program to repaint in realtime as it finds a image and place it ontop of another (source image).</p> <p>This is code to create the panel in my main function.</p> <p>The last piece mypanel.create() is the mosaic logic. </p> <pre><code>myPanel = new mosiacPanel(sourceFile, sizePercent, pixesize,threads, imageList); //test.setText(Integer.toString(myPanel.getWidth())); JFrame frame2 = new JFrame("COS 226 MOSIAC OF AWESOMENESS BY SLUIPMOORD &amp;&amp; ELEANORASAURUSS"); myPanel.setVisible( true ); myPanel.repaint(); frame2.add(myPanel); if(myPanel.getWidth() &gt; menubar.getWidth()){ frame2.setSize(myPanel.getWidth() , myPanel.getHeight() + menubar.getHeight() ); frame2.repaint(); } else { frame2.setSize(menubar.getWidth() , myPanel.getHeight() + menubar.getHeight() ); } frame2.setVisible( true ); // myPanel.setLocation(170, 4); myPanel.create(); </code></pre> <p>Mosaic panel class code snippet</p> <pre><code>public void create() { ph.createMosiac(imgUrls, this); } @Override protected void paintComponent( Graphics g ) { super.paintComponent(g); g.drawImage( imgToPaint, 0, 0, null ); // System.out.println("paint"); } public void paintTile( BufferedImage img ) { imgToPaint = img; this.repaint(); // this.paintComponent(this.getGraphics()); } </code></pre> <p>I call the paintTile function within create Mosaic Function.</p> <pre><code>public void createMosiac(List&lt;String&gt; fileNames, mosiacPanel parent) { ArrayList&lt;TileImage&gt; srcTiles = new ArrayList&lt;TileImage&gt;(); for( int i = 0; i &lt; fileNames.size(); i++ ) { srcTiles.add( new TileImage( fileNames.get(i), tileSize ) ); } for( int y = 0; y &lt;= (this.getHeight() - tileSize); y += tileSize ) { for( int x = 0; x &lt;= (this.getWidth() - tileSize); x += tileSize ) { int location = 0; double dist, high = 2147483647; for( int i = 0; i &lt; srcTiles.size(); i++ ) { dist = this.getTileImage(x, y).differance( srcTiles.get(i) ); if( (dist &lt; high) ) { high = dist; location = i; } } this.setTileImage( x, y, srcTiles.get(location) ); parent.paintTile(this); } } } </code></pre> <p>That is my program logic. When I uncomment this in the second snippet // this.paintComponent(this.getGraphics()); The program work but it repaints with a horrible flash and i am not one for medical bills when some of my other students within the demo venue are prone to epileptic attacks.</p> <p>If I trace trace the paintComponent function it get called twice at the end of the program and not on every repaint.</p> <p>Thank you in advance.</p> <p>I added a source code you guys can just copy and run. Select a image you want to test with the default is not available currently because you guys don't have it </p> <p>and then a directory containing a bunch of jpg to tile it with It is pretty slow at the moment i still need to fix that <a href="https://docs.google.com/file/d/0B1QbUvYjuQe1LUVDR1NQZlJzQms/edit" rel="noreferrer">Google docs link to the java file</a></p>
    singulars
    1. This table or related slice is empty.
    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.
 

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