/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mediaplayer;
/**
*
* @author zbp
*/
import java.awt.Dimension;
import java.awt.Toolkit;
import javafx.animation.Interpolator;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.input.KeyCombination;
import javafx.stage.Stage;
import javafx.beans.binding.Bindings;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.Node;
import javafx.scene.effect.PerspectiveTransform;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.util.Duration;
public class PicPlayer extends Application {
@Override
public void start(Stage stage) {
Group root = new Group();
Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();
Scene scene = new Scene(root, screensize.getWidth(), screensize.getHeight());
ImageView image1 = new ImageView(new Image( ("file:///d:///mv///22.jpg")));
ImageView image2 = new ImageView(new Image( ("file:///d:///mv///111.jpg")));
FlipView flip = new FlipView(image1, image2);
scene.setRoot(flip);
// show stage
stage.setScene(scene);
stage.fullScreenExitKeyProperty();
stage.setFullScreen(true);
stage.setFullScreenExitHint("");//去掉“按esc退出全屏”
stage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);//去掉esc退出全屏
// stage.initModality(Modality.APPLICATION_MODAL);
stage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}
class FlipView extends StackPane {
//正面视图
public Node frontNode;
//反面视图
public Node backNode;
//是否翻转
boolean flipped = false;
//翻转角度
DoubleProperty time = new SimpleDoubleProperty(Math.PI / 2);
//正面翻转特效
PerspectiveTransform frontEffect = new PerspectiveTransform();
//反面翻转特效
PerspectiveTransform backEffect = new PerspectiveTransform();
KeyFrame frame1 = new KeyFrame(Duration.ZERO, new KeyValue(time,
Math.PI / 2, Interpolator.LINEAR));
KeyFrame frame2 = new KeyFrame(Duration.seconds(10),
new EventHandler() {
@Override
public void handle(Event event) {
flipped = !flipped;
}
}, new KeyValue(time, -Math.PI / 2, Interpolator.LINEAR));
Timeline anim = new Timeline();
public FlipView(Node n1, Node n2) {
frontNode = n1;
backNode = n2;
create();
anim.play();
}
private void create() {
time.addListener(new ChangeListener() {
@Override
public void changed(ObservableValue observable, Object oldValue, Object newValue) {
setPT(frontEffect, time.get());
setPT(backEffect, time.get());
}
});
anim.getKeyFrames().addAll(frame1, frame2);
backNode.visibleProperty().bind(
Bindings.when(time.lessThan(0)).then(true).otherwise(false));
frontNode.visibleProperty().bind(
Bindings.when(time.lessThan(0)).then(false).otherwise(true));
setPT(frontEffect, time.get());
setPT(backEffect, time.get());
frontNode.setEffect(frontEffect);
backNode.setEffect(backEffect);
getChildren().addAll(backNode, frontNode);
}
private void setPT(PerspectiveTransform pt, double t) {
double width = 200;
double height = 200;
double radius = width / 2;
double back = height / 10;
pt.setUlx(radius - Math.sin(t) * radius);
pt.setUly(0 - Math.cos(t) * back);
pt.setUrx(radius + Math.sin(t) * radius);
pt.setUry(0 + Math.cos(t) * back);
pt.setLrx(radius + Math.sin(t) * radius);
pt.setLry(height - Math.cos(t) * back);
pt.setLlx(radius - Math.sin(t) * radius);
pt.setLly(height + Math.cos(t) * back);
}
}
|
for (int i = 0; i < 15; i++) {
if (i % 2 == 0) {
this.setLocation(this.getX(), this.getY() + (i % 4 < 2 ? -4 : 4));
} else {
this.setLocation(this.getX() + (i % 4 < 2 ? -4 : 4), this.getY());
}
try {
Thread.sleep(15);
} catch (InterruptedException ex) {
Logger.getLogger(Hufan.class.getName()).log(Level.SEVERE, null, ex);
}
} this.setLocation(x,y);
参考了网上一段javascript代码:
<img id="win" style='position:relative' src="http://www.iteye.com/images/logo.gif">
<br /><br />
<button onclick="zd()">鎸姩</button>
<script>
function zd(u){
var a=['top','left'],b=0;
u=setInterval(function(){
document.getElementById('win').style[a[b%2]]=(b++)%4<2?0:4;
if(b>15){
clearInterval(u);
b=0;
}
},32)
}
</script>
|