[Java]repaint() won't reload the screen

Status
Not open for further replies.

Adil

DevBest CEO
May 28, 2011
1,276
714
So, any way, here's my code:
PHP:
package core;
/**
 * @author Adil
 *
 */

import java.awt.*;
import javax.swing.JFrame;
import javax.swing.ImageIcon;
@SuppressWarnings("serial")
public class Core extends JFrame{
public static void main(String[] args) {

DisplayMode dm = new DisplayMode(800,600,16,DisplayMode.REFRESH_RATE_UNKNOWN);
Core i = new Core();
i.run(dm);

}
//variables for image loading below
public Screen s;
public Image bg;
public boolean loaded = false;

//run method below
public void run(DisplayMode dm){
setBackground(Color.BLACK);
setForeground(Color.WHITE);
setFont(new Font("Ubuntu", Font.PLAIN, 24));
s = new Screen();
loaded = false;
 
try{
s.setScreenSize(dm, this);
loadbg();
try{
                    Thread.sleep(5000);
}catch (Exception ex){}
}finally {
s.RestoreScreen();
}
}
  
public void loadbg() {
bg = new ImageIcon("file:\\\\home\\adil\\Desktop\\pack_2\\bgame.jpg").getImage();
loaded = true;
repaint();
}
   
public void paint(Graphics g){
if(g instanceof Graphics2D){
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
}
if(loaded){g.drawImage(bg,0,0,null);
}
}
}
What I want to do, is repaint the canvas with my image when the boolean "loaded" becomes true. This is not working. Any ideas why?
 
Status
Not open for further replies.

Users who are viewing this thread

Top