java代码写出动态画面 java画动态图

用JAVA Swing编写应用程序的界面时如何实现界面的动态更新 如:当点击一个按钮之后当前界面会相应的更新 。UpdateUI()
如:你需要刷新一个面板,
就 panel.UpdateUI();
该方法对所有组件容器均适用
求java做动画代码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 ()
【java代码写出动态画面 java画动态图】{
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 == meisShowing ())
{
if (PRESSED)
{
try
{
if (DIR == 39)
{
RIGHT_GO = RIGHT_GO50;
LEFT_GO = 0;
pointX = pointX1;
if (pointX420)
{
ANGLE = 90;
pointX--;
pointy--;
W = 60;
H = 50;
}
if (RIGHT_GO50)
{
RIGHT_GO = 0;
}
}
else if (DIR == 37)
{
pointX = pointX - 1;
RIGHT_GO = RIGHT_GO50;
LEFT_GO = 60;
if (pointX0)
{
ANGLE = -90;
pointX;
pointy--;
W = 60;
H = 50;
}
if (RIGHT_GO50)
{
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_GO50;
LEFT_GO = 0;
pointX = pointX1;
if (RIGHT_GO50)
{
RIGHT_GO = 0;
}
if (pointX500)
{
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);
}
});
}
}
如何在java控制台输出动态效果字符跳动好像不java代码写出动态画面的行额...java代码写出动态画面我只知道什么颜色?。∽痔灏∈裁吹幕蛘呒佣右衾质裁吹模《詊ava代码写出动态画面了你可以这样嘛!判断文本的长度!如果长度在某个段内就调用Substring()截取字符串来设定大小颜色什么的!再创建几个Icon ir= new ImageIcon();插入些制定找好的图片 你看怎么样~?。考右衾秩缦拢?可以这样! 也是取值到某段就放MUSIC通过Java提供的AudioClip类就可以播放了java代码写出动态画面:
mid = java.applet.Applet.newAudioClip(this.getClass().getResource(midUrl[0]));mid.loop();
//循环mid.play();
//播放mid.stop();
//停止检举midUrl[0]是文件的路径
java 鼠标放在按钮上,按钮上面显示动态特效,比如一个图片从左边滑到右边,如何实现input type="button" onmouseover="this.className='left'" onmousedown="this.className='right'"/
随便再定义两个class即可,一个class把图片的位置设置在左边,一个设置在右边,位置结合position实现即可 。
JAVA里面能做出来质点根据函数动态移动的效果吗?可以java代码写出动态画面的 。
解决方案如下:
/.setDefaultCloseOperation(JFrame.println(".addKeyListener(mp)java代码写出动态画面,希望对java代码写出动态画面你有帮助 。不然可以帮你构建一下代码;/
import java.event.repaint();
}else if(e 。你先参考java代码写出动态画面我以前学习时做的一个简单移动质点的程序(可直接运行) 。
/import javax 。
Java UI本来就是一个坐标系.*.VK_DOWN)
{
y =5;
/.VK_RIGHT)
{
x =5.add(mp).VK_LEFT)
{
x-=5;实现监听
this;
}
@Override
public void keyTyped(KeyEvent e) {
/.EXIT_ON_CLOSE);调用repaint函数 来重绘界面
this;
public void paint(Graphics g)
{
super.getKeyCode()==KeyEvent:加深对事件处理机制的理解
* 键盘方向键控制小球的运动
*/.out;/.*.getKeyChar());被按下"
package JavaBase13_ActionListerner;
import java.awt;
if(e;/
}
@Override
public void keyPressed(KeyEvent e) {
/ TODO Auto-generated method stub
/
}
}
class MyPanel extends JPanel implements KeyListener
{
int x = 10; TODO Auto-generated method stub
}
@Override
public void keyReleased(KeyEvent e) {
/, 300).*; TODO Auto-generated method stub
DemoB w51 = new DemoB().paint(g), y.awt 。就不知道你要的什么效果.fillOval(x.VK_UP)
{
y-=5; e;
}
/.getKeyCode()==KeyEvent;System.setSize(300;
}
public DemoB()
{
mp = new MyPanel();
this;
this;
int y = 10;
public class DemoB extends JFrame{
MyPanel mp = null楼主你好;/
}else if(e, 10.getKeyCode()==KeyEvent;/
}else if(e, 10)java代码写出动态画面,将参数的值和你需要移动的质点坐标建立关系.getKeyCode()==KeyEvent!你用纯JAVA做UI界面要实现动态效果就必须不断刷新画面.swing;
public static void main(String[] args) {
//
this;
this.setVisible(true);
g 。你的函数的参数也要不断的改变 。应该就可以;*
* 功能
关于java代码写出动态画面和java画动态图的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息 , 记得收藏关注本站 。

    推荐阅读