,然后将其和编译后生成的class文件放在同一文件夹下,然后运行就可以了-~~
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import chrriis.common.UIUtils;
import chrriis.dj.nativeswing.swtimpl.NativeInterface;
import chrriis.dj.nativeswing.swtimpl.components.JFlashPlayer;
/**
* @author Christopher Deckers
*/
public class SimpleFlashExample extends JPanel {
public SimpleFlashExample() {
super(new BorderLayout());
JFlashPlayer flashPlayer = new JFlashPlayer();
flashPlayer.load(getClass(), "resource/Movement-pointer_or_click.swf");
add(flashPlayer, BorderLayout.CENTER);
}
/* Standard main method to try that test as a standalone application. */
public static void main(String[] args) {
UIUtils.setPreferredLookAndFeel();
NativeInterface.open();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JFrame frame = new JFrame("DJ Native Swing Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new SimpleFlashExample(), BorderLayout.CENTER);
frame.setLocationByPlatform(true);
frame.setVisible(true);
});
NativeInterface.runEventPump();
import?java.awt.Canvas;
import?java.awt.Color;
import?java.awt.Dimension;
import?java.awt.EventQueue;
import?java.awt.Frame;
import?java.awt.Graphics;
import?java.awt.Image;
import?java.awt.RenderingHints;
import?java.awt.event.KeyEvent;
import?java.awt.event.KeyListener;
import?java.awt.event.WindowAdapter;
import?java.awt.event.WindowEvent;
import?java.awt.image.BufferedImage;
import?java.io.File;
import?java.io.IOException;
import?javax.imageio.ImageIO;
public?class?TestImage?extends?Frame
{
private?static?final?long?serialVersionUID?=?1L;
private?static?boolean?PRESSED?=?false;
private?static?int?pointX?=?0;
private?static?int?RIGHT_GO?=?0;
private?static?int?LEFT_GO?=?0;
private?static?int?DIR?=?0;
private?static?int?ANGLE?=?0;
private?_Canvas?canvas?=?null;
public?TestImage?()
add?(canvas?=?new?_Canvas?());
setIgnoreRepaint?(true);
requestFocus?();
public?class?_Canvas?extends?Canvas?implements?Runnable
private?BufferedImage?bi?=?null;
private?Image?bufferedImage?=?null;
private?Thread?thread?=?null;
private?long?sleepTime?=?10;
public?_Canvas?()
try
bi?=?ImageIO.read?(new?File?("go.png"));
catch?(IOException?e)
{}
setBackground?(Color.BLACK);
addKeyListener?(new?KeyListener?()
@Override
public?void?keyTyped?(?KeyEvent?e?)
public?void?keyReleased?(?KeyEvent?e?)
RIGHT_GO?=?0;
PRESSED?=?false;
public?void?keyPressed?(?KeyEvent?e?)
DIR?=?e.getKeyCode?();
PRESSED?=?true;
public?void?paint?(?Graphics?g?)
this);
public?void?update?(?Graphics?g?)
if?(null?==?bufferedImage)
bufferedImage?=?createImage?(getWidth?(),?getHeight?());
Graphics?bufferedG?=?bufferedImage.getGraphics?();
bufferedG.clearRect?(0,?0,?getWidth?(),?getHeight?());
paint?(bufferedG);
bufferedG.dispose?();
g.drawImage?(bufferedImage,?0,?0,?this);
g.dispose?();
public?void?start?()
thread?=?new?Thread?(this);
thread.setName?("TestImage");
thread.setPriority?(Thread.MIN_PRIORITY);
thread.start?();
public?synchronized?void?stop?()
thread?=?null;
notify?();
public?void?run?()
Thread?me?=?Thread.currentThread?();
while?(thread?==?me?!isShowing?()?||?getSize?().width?==?0)
catch?(InterruptedException?e)
return;
while?(thread?==?me?isShowing?())
if?(PRESSED)
LEFT_GO?=?0;
pointX?=?pointX?+?1;
pointX--;
pointy--;
pointX?=?pointX?-?1;
if?(pointX?0)
pointX++;
ANGLE?=?0;
RIGHT_GO?=?100;
Thread.sleep?(sleepTime);
repaint?();
break;
else
pointX?=?0;
*?旋转图像为指定角度
*?
public?static?BufferedImage?rotateImage?(?final?BufferedImage?image,?final?int?angdeg,?final?boolean?d?)
int?w?=?image.getWidth?();
int?h?=?image.getHeight?();
int?type?=?image.getColorModel?().getTransparency?();
BufferedImage?img;
RenderingHints.KEY_INTERPOLATION,?RenderingHints.VALUE_INTERPOLATION_BILINEAR);
return?img;
public?static?void?main?(?String[]?args?)
EventQueue.invokeLater?(new?Runnable?()
final?TestImage?ti?=?new?TestImage?();
ti.setLocationRelativeTo?(null);
ti.addWindowListener?(new?WindowAdapter?()
public?void?windowClosing?(?WindowEvent?e?)
System.exit?(0);
public?void?windowDeiconified?(?WindowEvent?e?)
ti.canvas.start?();
public?void?windowIconified?(?WindowEvent?e?)
ti.canvas.stop?();
ti.setResizable?(false);
ti.setVisible?(true);
效果图
参考代码
import?java.awt.*;
import?java.awt.event.*;
import?javax.swing.*;
public?class?MoveTextFrame?extends?JFrame?{
JLabel?jl;//文字标签
public?MoveTextFrame()?{
jl?=?new?JLabel("文字动画");
jl.setForeground(Color.RED);
add(jl);
setLocationRelativeTo(null);//窗口居中
setResizable(false);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
public?void?actionPerformed(ActionEvent?e)?{
int?x?=?jl.getX()+speed;//计算移动后的位置
jl.setLocation(x,?jl.getY());//更新位置
//repaint();
t.start();
public?static?void?main(String[]?args)?{
new?MoveTextFrame();
一: 用多线程播放一组图片, 实现动画片的效果; 类似于逐帧动画,每个图片是动画的一帧
二: 在awt/swing界面里, 可以使用paint方法,去绘制图形,然后用swing提供的Timer或者多线程技术,去刷新绘制的图形
三:在JavaFX里, 本身就支持动画,并且封装了很多动画效果可以直接使用,比如逐帧动画.缩放动画,渐变动画,旋转动画,位置动画等.
下面是一个javaFX绘制的动态表格
javaFX动态表格
线程不是同时进行的,定义多个线程,当一个线程运行完时,另外一个线程接着做,给人的感觉是同时的
以上就是土嘎嘎小编为大家整理的JAVA动漫代码相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!