• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

★ I have a java applet program (yanhua.java) need help!!!

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
★ I have a java applet program (yanhua.java) that use mouse click a area show a fireworks, the applet program that a java fan mail me. Now i find some bug in the program, can you help me? thank in advance!
The backdrop of the question: The yanhua.java applet program works well. But one day, i install j2re 1.4.1 plugin for my microsfot Internet Explorer, i run the yanhua.java applet program again, it show difficult(i move my mouse in the area, slowness), the fireworks is not fluent. Then i try my best to find the cause , i get some information, the following: yanhua.java run in j2re 1.4.1 plugin,it will deplete 100% cpu; else yanhua.java does not run in j2re 1.4.1 plugin, it will deplete 90%--95% cpu too; but my computer c3 1G cpu and 256MB memory, without running other program at that time. So i can have the assurance to say that the yanhua.java have some bug or error. can you help me to find all bug in yanhua.java? thank you very much!!!
i want to solve the question: finding all bug in yanhua.java

NOTE:
1、fireworks show specially good effect(a yanhua.java applet) you can look at:
http://www.3ren.net/down/java/yanhua.html
2、all program you can get from http://www.3ren.net/down/java/yanhua.rar
/*************************yanhua.java*************

import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.*;
import java.awt.image.MemoryImageSource;
import java.util.Random;
public class yanhua extends Applet
implements Runnable
{
private int m_nAppX;
private int m_nAppY;
private int m_centerX;
private int m_centerY;
private int m_mouseX;
private int m_mouseY;
private int m_sleepTime;
private boolean isError;
private boolean m_isPaintFinished;
boolean isRunning;
boolean isInitialized;
Thread runner;
int pix0[];
MemoryImageSource offImage;
Image dbImg;
int pixls;
int pixls2;
Random rand;
int bits;
double bit_px[];
double bit_py[];
double bit_vx[];
double bit_vy[];
int bit_sx[];
int bit_sy[];
int bit_l[];
int bit_f[];
int bit_p[];
int bit_c[];
int bit_max;
int bit_sound;
int ru;
int rv;
AudioClip sound1;
AudioClip sound2;
public yanhua()
{
m_mouseX = 0;
m_mouseY = 0;
m_sleepTime = 5;
isError = false;
isInitialized = false;
rand = new Random();
bits = 10000;
bit_px = new double[bits];
bit_py = new double[bits];
bit_vx = new double[bits];
bit_vy = new double[bits];
bit_sx = new int[bits];
bit_sy = new int[bits];
bit_l = new int[bits];
bit_f = new int[bits];
bit_p = new int[bits];
bit_c = new int[bits];
ru = 50;
rv = 50;
}
public void init()
{
String s = getParameter("para_bits");
if(s != null)
bits = Integer.parseInt(s);
s = getParameter("para_max");
if(s != null)
bit_max = Integer.parseInt(s);
s = getParameter("para_blendx");
if(s != null)
ru = Integer.parseInt(s);
s = getParameter("para_blendy");
if(s != null)
rv = Integer.parseInt(s);
s = getParameter("para_sound");
if(s != null)
bit_sound = Integer.parseInt(s);
m_nAppX = this.getSize().width;
m_nAppY = this.getSize().height;
m_centerX = m_nAppX / 2;
m_centerY = m_nAppY / 2;
m_mouseX = m_centerX;
m_mouseY = m_centerY;
resize(m_nAppX, m_nAppY);
pixls = m_nAppX * m_nAppY;
pixls2 = pixls - m_nAppX * 2;
pix0 = new int[pixls];
offImage = new MemoryImageSource(m_nAppX, m_nAppY, pix0, 0, m_nAppX);
offImage.setAnimated(true);
dbImg = createImage(offImage);
for(int i = 0; i < pixls; i++)
pix0[i] = 0xff000000;
sound1 = getAudioClip(getDocumentBase(), "firework.au");
sound2 = getAudioClip(getDocumentBase(), "syu.au");
for(int j = 0; j < bits; j++)
bit_f[j] = 0;
isInitialized = true;
start();
}
public void run()
{
while(!isInitialized)
try
{
Thread.sleep(200L);
}
catch(InterruptedException interruptedexception) { }
do
{
for(int j = 0; j < pixls2; j++)
{
int k = pix0[j];
int l = pix0[j + 1];
int i1 = pix0[j + m_nAppX];
int j1 = pix0[j + m_nAppX + 1];
int i = (k & 0xff0000) >> 16;
int k1 = ((((l & 0xff0000) >> 16) - i) * ru >> 8) + i;
i = (k & 0xff00) >> 8;
int l1 = ((((l & 0xff00) >> 8) - i) * ru >> 8) + i;
i = k & 0xff;
int i2 = (((l & 0xff) - i) * ru >> 8) + i;
i = (i1 & 0xff0000) >> 16;
int j2 = ((((j1 & 0xff0000) >> 16) - i) * ru >> 8) + i;
i = (i1 & 0xff00) >> 8;
int k2 = ((((j1 & 0xff00) >> 8) - i) * ru >> 8) + i;
i = i1 & 0xff;
int l2 = (((j1 & 0xff) - i) * ru >> 8) + i;
int i3 = ((j2 - k1) * rv >> 8) + k1;
int j3 = ((k2 - l1) * rv >> 8) + l1;
int k3 = ((l2 - i2) * rv >> 8) + i2;
pix0[j] = i3 << 16 | j3 << 8 | k3 | 0xff000000;
}
rend();
offImage.newPixels(0, 0, m_nAppX, m_nAppY);
try
{
Thread.sleep(m_sleepTime);
}
catch(InterruptedException interruptedexception1) { }
} while(true);
}
public void update(Graphics g)
{
paint(g);
}
public void paint(Graphics g)
{
g.drawImage(dbImg, 0, 0, this);
}
public void start()
{
if(isError)
return;
isRunning = true;
if(runner == null)
{
runner = new Thread(this);
runner.start();
}
}
public void stop()
{
if(runner != null)
{
runner.stop();
runner = null;
}
}
public boolean mouseMove(Event event, int i, int j)
{
m_mouseX = i;
m_mouseY = j;
return true;
}
public boolean mouseDown(Event event, int i, int j)
{
m_mouseX = i;
m_mouseY = j;
int k = (int)(rand.nextDouble() * 256D);
int l = (int)(rand.nextDouble() * 256D);
int i1 = (int)(rand.nextDouble() * 256D);
int j1 = k << 16 | l << 8 | i1 | 0xff000000;
int k1 = 0;
for(int l1 = 0; l1 < bits; l1++)
{
if(bit_f[l1] != 0)
continue;
bit_px[l1] = m_mouseX;
bit_py[l1] = m_mouseY;
double d = rand.nextDouble() * 6.2800000000000002D;
double d1 = rand.nextDouble();
bit_vx[l1] = Math.sin(d) * d1;
bit_vy[l1] = Math.cos(d) * d1;
bit_l[l1] = (int)(rand.nextDouble() * 100D) + 100;
bit_p[l1] = (int)(rand.nextDouble() * 3D);
bit_c[l1] = j1;
bit_sx[l1] = m_mouseX;
bit_sy[l1] = m_nAppY - 5;
bit_f[l1] = 2;
if(++k1 == bit_max)
break;
}
if(bit_sound > 1)
sound2.play();
return true;
}
public boolean mouseExit(Event event, int i, int j)
{
m_mouseX = i;
m_mouseY = j;
return true;
}
void rend()
{
boolean flag = false;
boolean flag1 = false;
boolean flag2 = false;
for(int k = 0; k < bits; k++)
switch(bit_f[k])
{
default:
break;
case 1: // '\001'
bit_vy[k] += rand.nextDouble() / 50D;
bit_px[k] += bit_vx[k];
bit_py[k] += bit_vy[k];
bit_l[k]--;
if(bit_l[k] == 0 || bit_px[k] < 0.0D || bit_py[k] < 0.0D || bit_px[k] > (double)m_nAppX || bit_py[k] > (double)(m_nAppY - 3))
{
bit_c[k] = 0xff000000;
bit_f[k] = 0;
} else
if(bit_p[k] == 0)
{
if((int)(rand.nextDouble() * 2D) == 0)
bit_set((int)bit_px[k], (int)bit_py[k], -1);
} else
{
bit_set((int)bit_px[k], (int)bit_py[k], bit_c[k]);
}
break;
case 2: // '\002'
bit_sy[k] -= 5;
if((double)bit_sy[k] <= bit_py[k])
{
bit_f[k] = 1;
flag2 = true;
}
if((int)(rand.nextDouble() * 20D) == 0)
{
int i = (int)(rand.nextDouble() * 2D);
int j = (int)(rand.nextDouble() * 5D);
bit_set(bit_sx[k] + i, bit_sy[k] + j, -1);
}
break;
}
if(flag2 && bit_sound > 0)
sound1.play();
}
void bit_set(int i, int j, int k)
{
int l = i + j * m_nAppX;
pix0[l] = k;
}

}
/*********************************end*************
 
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sunlinux
Welcome to the JavaRanch! Please adjust your display name to meet
the JavaRanch Naming Policy. You can change it here.
Thanks!
and welcome to the JavaRanch!
 
sunlinux
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
to Paul Stevens :

I want to edit ,but I can not change my display name , it is error in
http://www.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=edit_my_profile
[ October 08, 2002: Message edited by: sunlinux ]
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know that microsoft (notice the noncapitalized letters as they are not worthy) has discontinued the use of sun java applets in IE 5.5 sp2 and greater.
I was able to load the sun version into IE5.5 but had to enter my firewall information everytime I want to use it.
This will make things difficult because one machine may not be running the service pack 2 while the other one is.
Good luck
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic