Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Java Applet - display a flashing dot moving around page

Posted on 2004-09-11
10
Medium Priority
?
610 Views
Last Modified: 2013-11-23
I'm very much a novice of java, but part of may app, I need a java applet that is a blinking/flashing dot(smal circle) that moves around the page.  The position of the dot/circle will be determined by (x,y) coordinates passed to it, probabaly from a database(Access).

I realize this is a lot to ask, but just wondering how hard this would be to build, and if anyone has the code for this already.

Thanks
0
Comment
Question by:Malek103197
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
10 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 172 total points
ID: 12037582
Yes, that's possible and straightforward. Your best bet is to adapt a 'bouncing ball' applet:

http://javaboutique.internet.com/tutorials/Java_by_Example/section6_9.html
0
 
LVL 3

Assisted Solution

by:mte01
mte01 earned 164 total points
ID: 12037646
For a bit simpler program, you can use this:

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;

public class FMApplet extends JApplet
{


  public FMApplet()
  {
  }

  public void init()
  {
    try
    {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }

  private void jbInit() throws Exception
  {
    Mover m = new Mover(this,200);
    this.setSize(new Dimension(400,300));
  }

}




import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import java.util.Timer;
import java.util.TimerTask;


public class Mover
{
    Timer timer;
    JApplet myapp;

    public Mover(JApplet a,int milliseconds)
    {
      myapp = a;
        timer = new Timer();
        timer.schedule(new MoverTask(myapp), milliseconds);
    }

}




import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import java.util.TimerTask;

class MoverTask extends TimerTask
{
    Thread runner;
    JApplet myapp;
    final int h;
    final int w;
    double inc1;
    double inc2;
    double x;
    double y;

    public MoverTask(JApplet a)
    {
      myapp = a;
      h = 30;
      w = 30;
      inc1 = 1.5;
      inc2 = 2;
      x = 150;
      y = 150;
    }

    public void start()
    {
        if (runner == null)
        {
                runner = new Thread (this);
                runner.start();
        }
    }


    public void run()
    {
      while(true)
      {
      try
      {
        runner.sleep(15);
      }
        catch (Exception e) { }

      myapp.getGraphics().drawOval((int)x,(int)y,w,h);
      x += inc1;
        y += inc2;

        if(x<0 || x>myapp.getWidth()-w)
        {
            inc1=-inc1;
            x+=inc1;
        }

       if(y<0 || y>myapp.getHeight()-h)
        {
           inc2=-inc2;
           y+=inc2;
        }
        myapp.repaint();
      }
    }
}

0
 
LVL 92

Expert Comment

by:objects
ID: 12040247
you're probably going to need to sign your applet, what exactly is the purpose of the applet?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Malek103197
ID: 12049818
Thanks,

I wish to have a dot moving around over top of an image. The image is a map, and the dot represents coordiante swhere a vehilce has driven. I've seen someone else do this solution and it looks pretty good. the dot blinks/flashes on/of and moves around the page, where the position of the dot (x,y) are determined by passing it (x,y).
0
 
LVL 92

Assisted Solution

by:objects
objects earned 164 total points
ID: 12049888
Use a couple of JLabel's, one for the map image, and the other for the dot.

JLabel map = new JLabel(new ImageIcon(mapimage));
JLabel dot = new JLabel(new ImageIcon(dotimage));
map.setLayout(null);
map.add(dot);

then use setLocation() method of JLabel to move the dot as required.

0
 

Author Comment

by:Malek103197
ID: 12062151
Thanks for your suggestions. I will be a while before I try this out since I need help with setting up my java etc...but I will get back.
0
 
LVL 3

Expert Comment

by:mte01
ID: 12278434
I feel that I deserve a bit of the credit (few points not much :))
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question