2024-06-23 07:21:01 | 我爱编程网
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.Graphics2D;
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 pointy = 200;
private static int RIGHT_GO = 0;
private static int LEFT_GO = 0;
private static int DIR = 0;
private static int ANGLE = 0;
private static int W = 50;
private static int H = 60;
private _Canvas canvas = null;
public TestImage ()
{
add (canvas = new _Canvas ());
setIgnoreRepaint (true);
requestFocus ();
}
public class _Canvas extends Canvas implements Runnable
{
private static final long serialVersionUID = 1L;
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);
requestFocus ();
addKeyListener (new KeyListener ()
{
@Override
public void keyTyped ( KeyEvent e )
{}
@Override
public void keyReleased ( KeyEvent e )
{
RIGHT_GO = 0;
PRESSED = false;
}
@Override
public void keyPressed ( KeyEvent e )
{
// 38 40 37 39上下左右
DIR = e.getKeyCode ();
PRESSED = true;
}
});
}
@Override
public void paint ( Graphics g )
{
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint (RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2d.drawImage (rotateImage (bi.getSubimage (RIGHT_GO, LEFT_GO, W, H), ANGLE, true), pointX, pointy, W, H,
this);
g2d.dispose ();
}
@Override
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 ();
}
@Override
public void run ()
{
Thread me = Thread.currentThread ();
while (thread == me && !isShowing () || getSize ().width == 0)
{
try
{
Thread.sleep (555);
}
catch (InterruptedException e)
{
return;
}
}
while (thread == me && isShowing ())
{
if (PRESSED)
{
try
{
if (DIR == 39)
{
RIGHT_GO = RIGHT_GO + 50;
LEFT_GO = 0;
pointX = pointX + 1;
if (pointX > 420)
{
ANGLE = 90;
pointX--;
pointy--;
W = 60;
H = 50;
}
if (RIGHT_GO > 50)
{
RIGHT_GO = 0;
}
}
else if (DIR == 37)
{
pointX = pointX - 1;
RIGHT_GO = RIGHT_GO + 50;
LEFT_GO = 60;
if (pointX < 0)
{
ANGLE = -90;
pointX++;
pointy--;
W = 60;
H = 50;
}
if (RIGHT_GO > 50)
{
RIGHT_GO = 0;
}
}
else if (DIR == 38)
{
W = 50;
H = 60;
pointy = 150;
ANGLE = 0;
RIGHT_GO = 100;
}
else if (DIR == 40)
{
W = 50;
H = 60;
ANGLE = 0;
pointy = 200;
RIGHT_GO = 0;
}
Thread.sleep (sleepTime);
repaint ();
}
catch (InterruptedException e)
{
break;
}
}
else
{
RIGHT_GO = RIGHT_GO + 50;
LEFT_GO = 0;
pointX = pointX + 1;
if (RIGHT_GO > 50)
{
RIGHT_GO = 0;
}
if (pointX > 500)
{
pointX = 0;
}
try
{
Thread.sleep (sleepTime);
repaint ();
}
catch (InterruptedException e)
{
break;
}
}
}
thread = null;
}
}
/**
* 旋转图像为指定角度
*
* @param degree
* @return
*/
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;
Graphics2D graphics2d;
( graphics2d = ( img = new BufferedImage (w, h, type) ).createGraphics () ).setRenderingHint (
RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics2d.rotate (d ? -Math.toRadians (angdeg) : Math.toRadians (angdeg), w / 2, h / 2);
graphics2d.drawImage (image, 0, 0, null);我爱编程网
graphics2d.dispose ();
return img;
}
public static void main ( String[] args )
{
EventQueue.invokeLater (new Runnable ()
{
@Override
public void run ()
{
final TestImage ti = new TestImage ();
ti.setSize (new Dimension (500, 300));
ti.setLocationRelativeTo (null);
ti.addWindowListener (new WindowAdapter ()
{
@Override
public void windowClosing ( WindowEvent e )
{
System.exit (0);
}
@Override
public void windowDeiconified ( WindowEvent e )
{
ti.canvas.start ();
}
@Override
public void windowIconified ( WindowEvent e )
{
ti.canvas.stop ();
}
});
ti.setResizable (false);
ti.canvas.start ();
ti.setVisible (true);
}
});
}
}
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.setSize(800, 600);
frame.setLocationByPlatform(true);
frame.setVisible(true);
}
});
NativeInterface.runEventPump();
}
}
我爱编程网(https://www.52biancheng.com)小编还为大家带来2.Java有哪几种常见的实现动画的方法?的相关内容。
一: 用多线程播放一组图片, 实现动画片的效果; 类似于逐帧动画,每个图片是动画的一帧
二: 在awt/swing界面里, 可以使用paint方法,去绘制图形,然后用swing提供的Timer或者多线程技术,去刷新绘制的图形
三:在JavaFX里, 本身就支持动画,并且封装了很多动画效果可以直接使用,比如逐帧动画.缩放动画,渐变动画,旋转动画,位置动画等.
强烈推荐使用javaFX来实现动画, 因为javaFX是现代化的图形界面工具,具有简单,强大,组件丰富,跨平台,支持Html5, 支持表格, 支持动画等多种优势
下面是一个javaFX绘制的动态表格
javaFX动态表格
java运行的五个步骤?Java程序从源文件创建到程序运行要经过两大步骤:1、源文件由编译器编译成字节码(ByteCode)2、字节码由java虚拟机解释运行。因为java程序既要编译同时也要经过JVM的解释运行,所以说Java被称为半解释语言("semi-interpreted"language)。下面通过以下这个java程序,来说明java程序从编译到最后运行的整个流程。
如何自动加载类很多开发者写面向对象的应用程序时对每个类的定义建立一个PHP源文件。一个很大的烦恼是不得不在每个脚本开头写一个长长的包含文件列表(每个类一个文件)。在PHP5中,不再需要这样了。可以定义一个__autoload()函数,它会在试图使用尚未被定义的类时自动调用。通过调用此函数,脚本引擎在PHP出错失败前有了最后一个机会加载所需的类。Tipspl_autoload_re
一个很简单的PHP面向对象问题如果不是写在类里你这个就是一个函数如果写在类里你这个就是一个类里的一个方法function_get()括号里如果没有参数就不要填直接调用这个函数可以了括号中间的是参数,意思就是你写这个函数的时候需要外部调入的数据才能完成function__set($name,$value)不一定是类里的属性不是很熟悉对类是外部传入的参数比如$a=1;$b=8
php通过base64如何实现动态URL加密base64不能实现加密,只是采用了不同方式来对数据进行编码,方便通过防火墙传输,php中base64encode函数base64_encode("");decode函数base64_decode($str);php下,有加密函数stringcrypt(stringstr[,stringsalt]),自己看看文档把。求大佬,解决一个p
eclipse创建java程序教程eclipse软件操作方法01首先确保电脑上已经配置好java的环境,安装了eclipse软件,如果确定已经完成了,则双击鼠左键打开eclipse软件否则可参考如下链接,分别为安装java环境和配置java环境和下载安装eclipse的详细步骤,可参。1首先java程序的运行你需要下载和安装JDK,这是java运行的必备环境2在桌面上找到eclipes,
JAVA实现音频播放这个程序只要写对了音乐文件的URL地址,例如:newURL("file:/C:/tmp/1/WindowsDing.wav");就可以播放音乐,除了可以播放.wav格式的音乐,还可以播放.au格式的音乐。另外,如果你不希望音乐循环播放,你可以去掉audio1.loop();这一语句。importjava.applet.AudioClip;importjav
如何让tomcat启动时,就运行java一、创建Servlet在一个Web项目中创建一个Servlet,在web.xml文件中配置。将需要初始化的内容放在Servlet的init()方法实现。二、设置Servlet为自启动在web.xml文件中添加:<servlet> <servlet-name>servlet的名字</s
Java控制台实现程序importjava.util.HashMap;importjava.util.Map;importjava.util.Scanner;publicclassStr{publicstaticStringuserName;publicstaticStringpass;/***@paramargs*/publicStringtoSt
2025-02-01 20:24:39
2024-01-05 14:11:24
2025-02-12 03:21:37
2025-02-10 15:19:48
2025-01-28 17:58:32
2024-11-22 05:08:01