java问题如何解决图片闪烁问题,求大神解答详细点,不知道双缓冲怎么用的,谢了 5
packageceshi;importjava.awt.*;importjavax.swing.*;publicclasscheshi25extendsJFrame{My...
package ceshi;
import java.awt.*;
import javax.swing.*;
public class cheshi25 extends JFrame{
Mypanel q;
public cheshi25(){
q=new Mypanel();
Thread sn=new Thread(q);
sn.start();
this.add(q);
this.setVisible(true);
this.setSize(400,400);
this.setLocationRelativeTo(null);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new cheshi25();
}
}
class Mypanel extends JPanel implements Runnable{
Image image1;
Image image2;
Image image3;
Image image4;
Image image5;
Image image6;
int k=0;
public Mypanel(){
image1=Toolkit.getDefaultToolkit().getImage("wutitupian//完旗一.png");
image2=Toolkit.getDefaultToolkit().getImage("wutitupian//完旗二.png");
image3=Toolkit.getDefaultToolkit().getImage("wutitupian//完旗三.png");
image4=Toolkit.getDefaultToolkit().getImage("wutitupian//完旗四.png");
image5=Toolkit.getDefaultToolkit().getImage("wutitupian//完旗五.png");
image6=Toolkit.getDefaultToolkit().getImage("wutitupian//完旗6.png");
}
public void paint(Graphics g){
super.paint(g);
g.setColor(Color.blue);
g.fillRect(0,0,400,400);
if(k==1){
g.drawImage(image1,100,50,this);
}else if(k==2){
g.drawImage(image2,101,50,this);
}else if(k==3){
g.drawImage(image3,112,50,this);
}else if(k==4){
g.drawImage(image4,97,50,this);
}else if(k==5){
g.drawImage(image5,76,48,this);
}else if(k==6){
g.drawImage(image6,107,48,this);
}
this.repaint();
}
@Override
public void run() {
// TODO 自动生成的方法存根
while(true){
try {
Thread.sleep(100);
} catch (Exception e) {
// TODO: handle exception
}
k++;
if(this.k==7){
this.k=0;
}
this.repaint();
}
}
} 展开
import java.awt.*;
import javax.swing.*;
public class cheshi25 extends JFrame{
Mypanel q;
public cheshi25(){
q=new Mypanel();
Thread sn=new Thread(q);
sn.start();
this.add(q);
this.setVisible(true);
this.setSize(400,400);
this.setLocationRelativeTo(null);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new cheshi25();
}
}
class Mypanel extends JPanel implements Runnable{
Image image1;
Image image2;
Image image3;
Image image4;
Image image5;
Image image6;
int k=0;
public Mypanel(){
image1=Toolkit.getDefaultToolkit().getImage("wutitupian//完旗一.png");
image2=Toolkit.getDefaultToolkit().getImage("wutitupian//完旗二.png");
image3=Toolkit.getDefaultToolkit().getImage("wutitupian//完旗三.png");
image4=Toolkit.getDefaultToolkit().getImage("wutitupian//完旗四.png");
image5=Toolkit.getDefaultToolkit().getImage("wutitupian//完旗五.png");
image6=Toolkit.getDefaultToolkit().getImage("wutitupian//完旗6.png");
}
public void paint(Graphics g){
super.paint(g);
g.setColor(Color.blue);
g.fillRect(0,0,400,400);
if(k==1){
g.drawImage(image1,100,50,this);
}else if(k==2){
g.drawImage(image2,101,50,this);
}else if(k==3){
g.drawImage(image3,112,50,this);
}else if(k==4){
g.drawImage(image4,97,50,this);
}else if(k==5){
g.drawImage(image5,76,48,this);
}else if(k==6){
g.drawImage(image6,107,48,this);
}
this.repaint();
}
@Override
public void run() {
// TODO 自动生成的方法存根
while(true){
try {
Thread.sleep(100);
} catch (Exception e) {
// TODO: handle exception
}
k++;
if(this.k==7){
this.k=0;
}
this.repaint();
}
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询