-1
我的問題是在幀中移動圓時產生的閃爍。 當我用鍵移動它時,圓圈消失。閃爍着方法畫顏料java
我需要雙緩衝區,但我不知道如何使用它。幫助我的朋友,我需要你對這個項目的知識!
解決方案?
import javax.swing.JFrame;
public class PruebaGraphics extends JFrame{
int x=130, y=130;
public static void main(String[] args) {
new PruebaGraphics();
}
public PruebaGraphics() {
this.setTitle("Dibujando sobre lienzo en java");
this.setSize(300,300);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
KeyListener pulsa = new KeyListener() {
@Override
public void keyTyped(KeyEvent ke) {
throw new UnsupportedOperationException("Not supported yet.");
@Override
public void keyPressed(KeyEvent ke) {
if(ke.getKeyCode()==39 && x+60<size().width) //derecha
{
x = x+10;
}
if(ke.getKeyCode()==40 && y+60<size().height) //abajo
{
y= y+10;
}
if(ke.getKeyCode()==38 && y-30>0) //Arriba
{
y = y-10;
}
if(ke.getKeyCode()==37 && x-10 > 0) //izquierda
{
x= x-10;
}
repaint();
}
@Override
public void keyReleased(KeyEvent ke) {
}
};
addKeyListener(pulsa);
}
@Override
public void paint(Graphics g) {
super.paint(g);
g.fillOval(x, y, 50, 50);
}
}
thx !!!!!!!!!!!!它的工作現在! – user3547063