⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testanimator.java

📁 一些简单的java程序。老师很认真
💻 JAVA
字号:
package com.test;
import javax.swing.*;
import java.awt.Graphics;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Color;
import java.awt.Image;
import java.awt.Toolkit;
public class TestAnimator extends JPanel{
	private boolean stop = false;
	Point lastP = new Point(100,100);
	int ballW = 50,ballH =50;
	int slope = 1;
	int x , y ;
	public TestAnimator(){
		super();
		x = lastP.x;
		y = lastP.y;
		moveBall();
	}
	public  void paintComponent(Graphics g){
		super.paintComponent(g);
		this.setPreferredSize(new Dimension(800, 600));
		Toolkit tk=Toolkit.getDefaultToolkit(); 
		Image img=tk.getImage("c:/车.jpg");
		g.drawOval(x,y,ballW,ballH);
	}
	private void moveBall(){
		Thread t = new Thread(){
			public void run(){
				while (stop == false){
					try{
						Thread.sleep(100);
						x += 10;
						y=x*slope;
						repaint();
						System.out.println("----------x = " + x + " y = " + y);
						if (x + ballW > 800 || y + ballH > 600)
							stop = true;
						}catch (Exception e){
							e.printStackTrace();
							}
						}
				}
			};
			t.start();
			}
	public static void main(String[] arg){
		JFrame f = new JFrame();
		TestAnimator tb = new TestAnimator();
		f.getContentPane().add(tb);
		f.setSize(800, 600);
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		f.setVisible(true);
		}
	}

//http://www.7880.com/Info/Article-861dcd20.html
//http://hi.baidu.com/lizhao_yiqing/blog/item/4161511378c803075aaf530c.html
//http://topic.csdn.net/t/20060109/11/4505546.html

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -