Trying to write a program in BlueJ that randomly puts a square inside an applet
ID: 3645944 • Letter: T
Question
Trying to write a program in BlueJ that randomly puts a square inside an applet and lets it bounce around inside a certain border. Although this program is not finished, i am trying to run it just to get an idea of where i am. Program compiles fine but fails to start in the applet.Any help?import java.awt.*;
import java.applet.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
public class Midterm_2 extends JApplet implements Runnable
{
// INSTANCE VARIABLES
int x, y, size, moveR, moveD, width;
Random random;
Image brick;
String audiofilename = "click.wav";
AudioClip click;
Thread bouncer;
public void init()
{
bouncer = new Thread(this);
int x = 10;
int y= 10;
int size =40;
int width = 80;
int moveR = random.nextInt(8) + 3;
int moveD = random.nextInt(8) + 3;
brick = getImage(getCodeBase(), "brick.png");
click = getAudioClip(getCodeBase() ,audiofilename) ;
random = new Random();
}
public void start()
{
bouncer.start();
}
public void run()
{
try
{
while(true)
{
repaint();
Thread.sleep(5000000) ;
}
}
catch(Exception e){}
}
public void paint(Graphics g)
{
g.fillRect(x, y, size, size);
g.drawImage(brick, 375, 400, this);
}
public void drawBorder(Image img)
{
}
}
Explanation / Answer
from this what i can see is that the implementation is correct but the drawBorder method is not implemented...so try completing it and then revisit your program...this should help you!!
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.