Swing is a single-threaded infrastructure. These are all interactions and modifications to the user interface that are expected to be performed on the contents of the event dispatch thread, including redraw requests.
, , , EDT , . , , ( ), .
run Thread.sleep. , EDT , , , ...
paint AND Thread.sleep. WILL EDT, paint EDT.
, , , paint , , paint, , EDT, - .
, " ", Swing .
paint , .
- ...
public void paint(Graphics g){
super.paint(g);
Graphics2D g2=(Graphics2D)g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.drawImage(bg,0,0,null);
g2.drawImage(bg,0,480,null);
g2.drawImage(bg,360,0,null);
g2.drawImage(bg,360,480,null);
g2.drawImage(bg,720,0,null);
g2.drawImage(bg,720,480,null);
g2.drawImage(chara,imgX,imgY,null);
g2.dispose();
}
...
Thread.sleep - javax.swing.Timer, ...
s=new Screen();
try{
loadpics();
s.setFullScreen(dm,this);
Timer timer = new Timer(10000, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
s.restoreScreen();
}
});
timer.setRepeats(false);
timer.start();
}catch(Exception e){
e.printStackTrace();
}
Concurrency Swing .
paint. , , , .
- , , JPanel paintComponent, , super.paintComponent, - .