Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For this lab assignment, you will create an applet which will be interactive (us

ID: 3732568 • Letter: F

Question

For this lab assignment, you will create an applet which will be interactive (uses listeners by implementing MouseListener and MouseMotionListener interfaces or by extending MouseAdapter class). l. 150%I write an applet called Blackboard, which displays and behaves as shown below: when it runs initially: Applet Viewer: Blackboard.class Applet Erase Board Applet started. When the user draws on the black board (panel) with the mouse: Applet Viewer: Blackboard.class Applet Erase Board Applet started.

Explanation / Answer

//BlackBoard Class by implementing MouseMotionListener

import java.awt.*;

import java.awt.event.*;

import javax.swing.JButton;

import java.applet.*;

public class BlackBoard extends Applet implements MouseMotionListener {

public void init() {

addMouseMotionListener(this);

setBackground(Color.black);

repaint();

JButton button=new JButton("Erase Board");

button.addActionListener(new ActionListener(){  

public void actionPerformed(ActionEvent e){  

repaint();

}  

});

add(button);

}

public void mouseDragged(MouseEvent me) {

Graphics g = getGraphics();

g.setColor(Color.white);

g.fillOval(me.getX(), me.getY(), 5, 5);

}

public void mouseMoved(MouseEvent me) {

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote