Java source Code! Can show the water wave effect!

Source: Internet
Author: User
Tags thread
Show | Source code Wave effect Program:
Import java.awt.*;
Import Java.applet.Applet;

public class Splash extends Applet implements runnable{
int xmax=112;
Float[] M_height=new Float[xmax];
Float[] M_g=new Float[xmax];
float b=1.01f;
float fweight=3;
Private Thread M_nami2d=null;
public boolean MouseDown (Event event,int i,int j) {
M_HEIGHT[I/4-1]+=J/2;
M_height[i/4]+=j;
M_HEIGHT[I/4+1]+=J/2;
return false;
}
public void Paint (Graphics g) {
G.setcolor (Color.Blue);
float F1=3f*fweight;
float f2=f1-2.0f;
M_HEIGHT[0]=M_HEIGHT[1];
M_HEIGHT[XMAX-1]=M_HEIGHT[XMAX-2];
float f=m_height[0];
for (int i=1;i<xmax-1;i++) {
Float f3= ((f+f2*m_height[i]+m_height[i+1])/f1+m_g[i])/b;
F=m_height[i];
M_g[i]=f3-f;
M_HEIGHT[I]=F3;
G.clearrect ((i-1) *4, (int) f3-30,4,60);
G.fillrect ((i-1) *4, (int) f3+30,4,60);
}
}
public void Run () {
Todo
try{
Repaint ();
Thread.Sleep (50L);
}
catch (Interruptedexception _ex) {
Stop ();
}
while (true);
}
public void Start () {
if (m_nami2d==null) {
M_nami2d=new Thread (this);
M_nami2d.start ();
}
}
public void Stop () {
if (m_nami2d!=null) {
M_nami2d.stop ();
M_nami2d=null;
}
}
public void Update (Graphics g) {
Paint (g);
}
}





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.