자바 스윙에서 플립 효과를 만들려고하는데 플립 방식이 실제 플립처럼 보이지 않습니다. 제 방법으로는 x var 및 xspeed로 너비를 변경하여 이미지를 만듭니다. 더 작 으면 x가 내 이미지의 절반 이상인지 확인하십시오. 누군가가 사전에 덕분에 그것을 개선하는 데 도움이되기를 바랍니다.자바 스윙 애니메이션
애니메이션 클래스
public class Animation extends JPanel implements MouseListener {
private static final long serialVersionUID = 3264508834913061718L;
public Timer timer;
public int x = 0;
public int xspeed = 2;
public boolean turning = true;
public String pic = "/images/image.jpg";
public URL url = this.getClass().getResource(pic);
public ImageIcon im = new ImageIcon(url);
public String rev = "/images/image2.jpg";
public URL url2 = this.getClass().getResource(rev);
public ImageIcon reverse = new ImageIcon(url2);
public Animation(){
this.setPreferredSize(new Dimension(128,128));
this.setBackground(Color.BLACK);
this.setFocusable(true);
this.addMouseListener(this);
}
public void paintComponent(Graphics g){
super.paintComponent(g);
g.drawImage(im.getImage(), 0 , 0, im.getIconWidth() - x, im.getIconHeight(), null);
}
public void flipAnimation(){
ActionListener actionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
//
if (turning) {
x = x + xspeed;
}
repaint();
// x in the middle paint new image & set turning to false to stop animation
if(x >= im.getIconWidth()/2){
turning = false;
x = 0;
im = reverse;
}
}
};
if (turning) {
if (timer != null)timer.stop();
timer = new Timer(30, actionListener);
timer.start();
}
}
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
e.getSource();
flipAnimation();
}
그럼 어떻게 보이는지는 불만족 스럽습니까? 프레임이 누락 되었습니까? 3D로 보길 원한다면 Swing으로 그걸 얻지 못할 것입니다. – Frecklefoot
이미지가 플립보다 왼쪽으로 움직이는 것처럼 보입니다. 왼쪽에서 오른쪽 자르기와 같은 것이 더 좋을 것 @Frecklefoot – Aestraelyse
'x' 드로잉 위치를'x'로 조정해야합니다. 그러면 미끄러 져 보이지 않습니다. – Frecklefoot