I am working with the following code for an assignment:
import java.awt.*;
import java.applet.*;
publicclass Mystery5 extends Applet {
Image Buffer;
Graphics gBuffer;
publicvoid init() {
Buffer=createImage(getSize().width, getSize().height);
gBuffer=Buffer.getGraphics();
}
publicboolean MouseDown(Event evt,int x,int y) {
drawRB(x,y);
repaint();
returntrue;
}
publicvoid drawRB(int x, int y) {
int red=(int)(Math.random()*255);
int green=(int)(Math.random()*255);
int blue=(int)(Math.random()*255);
Color randomColor=new Color(red, green, blue);
gBuffer.setColor(randomColor);
int diameter=(int)(Math.random()*90)+10;
gBuffer.fillOval(x-diameter/2,y-diameter/2,diameter,diameter);
}
publicvoid update(Graphics g) {
paint(g);
}
publicvoid paint(Graphics g) {
gBuffer.setColor(Color.black);
gBuffer.drawString("Click the applet to go!", 50,20);
g.drawImage (Buffer,0,0, this);
}
}
The assignment simply says to implement the following code and determine what it does.
The code had some deprication errors before I began working with it and I worked all of those out. The program now compiles but nothing happens when ran with the following html file
public void mouseClicked(MouseEvent e){ MouseDown( e.getX(),e.getY()); } public void mouseEntered(MouseEvent e){}; public void mouseExited(MouseEvent e){}; public void mousePressed(MouseEvent e){}; public void mouseReleased(MouseEvent e){};
public void drawRB(int x, int y) { int red=(int)(Math.random()*255); int green=(int)(Math.random()*255); int blue=(int)(Math.random()*255); Color randomColor=new Color(red, green, blue); gBuffer.setColor(randomColor); int diameter=(int)(Math.random()*90)+10; gBuffer.fillOval(x-diameter/2,y-diameter/2,diameter,diameter); }
public void update(Graphics g) { paint(g); }
public void paint(Graphics g) { gBuffer.setColor(Color.black); gBuffer.drawString("Click the applet to go!", 50,20); g.drawImage (Buffer,0,0, this); } }
Right now, it doesn't do much. Does the colors which has been set present itself in the web browser? It looks like the code builds the presentation layer (The user friendly GUI view). The MouseDown indicates that addition code will be added to carry out some function at a later point. But again, someone else may have more insight.