「特效源码java」代码特效编写

博主:adminadmin 2022-11-25 09:11:08 38

本篇文章给大家谈谈特效源码java,以及代码特效编写对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

使用Java做一个走马灯,源代码?

import java.awt.Color;

import java.awt.Dimension;

import java.awt.Font;

import java.awt.HeadlessException;

import java.awt.Point;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.ComponentAdapter;

import java.awt.event.ComponentEvent;

 

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JViewport;

import javax.swing.Timer;

 

public class Test84 extends JFrame {

  private Timer timer;

  private JLabel view;

  private JViewport window;

  

  public static void main(String[] args)

  {

    JFrame frm = new Test84("跑马灯");

    frm.setDefaultCloseOperation(EXIT_ON_CLOSE);

    frm.pack();

    frm.setVisible(true);

  }

 

  public Test84(String title) throws HeadlessException

  {

    super(title);

    

    initComponents();

    

    addComponentListener(new ComponentAdapter() {

      public void componentResized(ComponentEvent e)

      {

        anchor = new Point();

        anchor.x = -window.getExtentSize().width;

        timer.start();

      }

    });

    

    timer = new Timer(100, new ActionListener() {

      public void actionPerformed(ActionEvent e)

      {

        animate();

      }

    });

    timer.setInitialDelay(0);

  }

 

  private void initComponents()

  {

   String s = JOptionPane.showInputDialog(null, "请输入要实现效果的文字:");

    view = new JLabel(s);

    view.setFont(Font.decode("Dialog-BOLD-36"));

    view.setForeground(Color.BLUE);

    

    window = new JViewport();

    window.setView(view);

    getContentPane().add(window);

  }

  

  Point anchor;

  private void animate()

  {

    Dimension extSize = window.getExtentSize();

    Dimension viewSize = view.getPreferredSize();

    anchor.x += 5;//设置移动的速度

    window.setViewPosition(anchor);

    if (anchor.x  viewSize.width)

      anchor.x = -extSize.width;

  }

}

实现星星闪动的java代码

package panel;

import java.awt.Color;

import java.awt.Font;

import java.awt.Graphics;

import javax.swing.JPanel;

import main.MainTank;

public class TipPanel extends JPanel implements Runnable{

/**

*

*/

private static final long serialVersionUID = 1L;

//偶数打印,画面板

int time=0;

public void paintComponent(Graphics g){

super.paint(g);

g.fillRect(0, 0, MainTank.getWidthOfGame(), MainTank.getHeightOfGame());//绘制提示窗口

if (time%2==0){//偶数打印,画面板,造成闪烁效果

g.setColor(Color.ORANGE);

Font font=new Font("华文楷体",Font.BOLD,30);

g.setFont(font);//选用字体

g.drawString("Ready", 140, 130);

}

}

@Override

public void run() {

while (true){

try{

Thread.sleep(250);

}catch (Exception e){

e.getMessage();

}

time++;//绘图开关

this.repaint();

}

}

}//TipPanel

类似的,修改下就行

求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 ()

{

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);

}

});

}

}

急求一个网页特效代码

用这个吧 可以全屏拖动的 支持FLASH引用

script id=clientEventHandlersJS language=JScript

!--

function ad_check() {

self.onError=null;

self.onError=null;

setTimeout("ad_check()",100);

}

function Min_onclick() {

//alert(ad1.style.visibility )

ad1.style.visibility='hidden';

}

function Max_onclick() {

//alert(ad1.style.visibility )

ad1.style.visibility='visible';

}

//--

/scriptscript language=JScript

//floater.innerHTML =''

//window.alert (floater.innerHTML.length4000);

self.onError=null;

currentX = currentY = 0;

whichIt = null;

lastScrollX = 0; lastScrollY = 0;

NS = (document.layers) ? 1 : 0;

IE = (document.all) ? 1: 0;

!-- STALKER CODE --

function heartBeat() {

if(IE) { diffY = document.body.scrollTop; diffX = document.body.scrollLeft; }

if(NS) { diffY = self.pageYOffset; diffX = self.pageXOffset; }

if(diffY != lastScrollY) {

percent = .1 * (diffY - lastScrollY);

if(percent 0) percent = Math.ceil(percent);

else percent = Math.floor(percent);

if(IE) document.all.floater.style.pixelTop += percent;

if(NS) document.floater.top += percent;

lastScrollY = lastScrollY + percent;

}

if(diffX != lastScrollX) {

percent = .1 * (diffX - lastScrollX);

if(percent 0) percent = Math.ceil(percent);

else percent = Math.floor(percent);

if(IE) document.all.floater.style.pixelLeft += percent;

if(NS) document.floater.left += percent;

lastScrollX = lastScrollX + percent;

}

}

//--

function checkFocus(x,y) {

stalkerx = document.floater.pageX;

stalkery = document.floater.pageY;

stalkerwidth = document.floater.clip.width;

stalkerheight = document.floater.clip.height;

if( (x stalkerx x (stalkerx+stalkerwidth)) (y stalkery y

(stalkery+stalkerheight))) return true;

else return false;

}

function grabIt(e) {

if(IE) {

whichIt = event.srcElement;

while (whichIt.id.indexOf("floater") == -1) {

whichIt = whichIt.parentElement;

if (whichIt == null) { return true; }

}

whichIt.style.pixelLeft = whichIt.offsetLeft;

whichIt.style.pixelTop = whichIt.offsetTop;

currentX = (event.clientX + document.body.scrollLeft);

currentY = (event.clientY + document.body.scrollTop);

} else {

window.captureEvents(Event.MOUSEMOVE);

if(checkFocus (e.pageX,e.pageY)) {

whichIt = document.floater;

stalkerTouchedX = e.pageX-document.floater.pageX;

StalkerTouchedY = e.pageY-document.floater.pageY;

}

}

return true;

}

function moveIt(e) {

if (whichIt == null) { return false; }

if(IE) {

newX = (event.clientX + document.body.scrollLeft);

newY = (event.clientY + document.body.scrollTop);

distanceX = (newX - currentX); distanceY = (newY - currentY);

currentX = newX; currentY = newY;

whichIt.style.pixelLeft += distanceX;

whichIt.style.pixelTop += distanceY;

if(whichIt.style.pixelTop document.body.scrollTop) whichIt.style.pixelTop =

document.body.scrollTop; if(whichIt.style.pixelLeft document.body.scrollLeft)

whichIt.style.pixelLeft = document.body.scrollLeft; if(whichIt.style.pixelLeft

document.body.offsetWidth - document.body.scrollLeft - whichIt.style.pixelWidth - 20)

whichIt.style.pixelLeft = document.body.offsetWidth - whichIt.style.pixelWidth - 20;

if(whichIt.style.pixelTop document.body.offsetHeight + document.body.scrollTop -

whichIt.style.pixelHeight - 5) whichIt.style.pixelTop = document.body.offsetHeight +

document.body.scrollTop - whichIt.style.pixelHeight - 5;

event.returnValue = false;

} else {

whichIt.moveTo(e.pageX-StalkerTouchedX,e.pageY-StalkerTouchedY);

if(whichIt.left 0+self.pageXOffset) whichIt.left = 0+self.pageXOffset;

if(whichIt.top 0+self.pageYOffset) whichIt.top = 0+self.pageYOffset;

if( (whichIt.left + whichIt.clip.width) = (window.innerWidth+self.pageXOffset-17)) whichIt.left

= ((window.innerWidth+self.pageXOffset)-whichIt.clip.width)-17;

if( (whichIt.top + whichIt.clip.height) = (window.innerHeight+self.pageYOffset-17)) whichIt.top

= ((window.innerHeight+self.pageYOffset)-whichIt.clip.height)-17;

return false;}

return false;

}

function dropIt() {

whichIt = null;

if(NS) window.releaseEvents (Event.MOUSEMOVE);

return true;

}

!-- DRAG DROP CODE --

if(NS) {

window.captureEvents(Event.MOUSEUP|Event.MOUSEDOWN);

window.onmousedown = grabIt;

window.onmousemove = moveIt;

window.onmouseup = dropIt;

}

if(IE) {

document.onmousedown = grabIt;

document.onmousemove = moveIt;

document.onmouseup = dropIt;

}

if(NS || IE) action = window.setInterval("heartBeat()",1);

setTimeout("ad_check()",10)

/script

/div

DIV align=center id=floater style="HEIGHT: 100px; WIDTH: 343px; position:absolute; left:76px; top:126px"

TABLE bgColor=#eeeeee border=1 borderColor=#999999

cellPadding=0 cellSpacing=0

style="BORDER-COLLAPSE: collapse" width=167

TBODY

TR

TD height=20 width=167

TABLE border=0 cellPadding=0 cellSpacing=0

width="100%"

TBODY

TR

TD align=right

height=15 vAlign=bottom width="100%"

TABLE border=0 height=2 width="100%"

TR

TD height=1 align=rightFONT color=#000000 face=宋体

style="FONT-SIZE: 9pt" /FONT font

class=banner

id=Min language=javascript

onclick="return Min_onclick()"font color="#990000" style="font-size: 9pt; cursor: hand"收起/font/fontfont

class=banner

id=Min language=javascript

onclick="return Max_onclick()"FONT

color=#666666//FONTfont color="#990000" style="font-size: 9pt; cursor: hand"展开/font/font/TD

/TR/TABLE/TD/TR/TBODY/TABLE/TD/TR/TBODY/TABLE

TABLE bgColor=#eeeeee border=1 borderColor=#999999

cellPadding=2 cellSpacing=0 id=ad1

style="BORDER-COLLAPSE: collapse" width=165

TBODY

TR

TD bgColor=#eeeeee disabled height=20 width=165 P align=center

object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="" width="165" height="120"

param name="movie" value=""

param name="quality" value="high"

embed src="" quality="high" pluginspage="" type="application/x-shockwave-flash" width="165" height="120"/embed/object

/P

/TD/TR

TR

TD bgColor=#eeeeee height=20 width=310div align="left"

FONT

color=#990000 size=2font color="#666666"/font/FONT

FONT

color=#FFFFFF size=2 /FONTFONT

color=#800000 size=2蓝染惣右介/FONT/div/TD

/TR

/TBODY/TABLE

/DIV

关于特效源码java和代码特效编写的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

The End

发布于:2022-11-25,除非注明,否则均为首码项目网原创文章,转载请注明出处。