The Internet has opened a new medium for collaboration. Students and colleagues no longer have to be in the same physical location to share their ideas in multiple mediums. Among the multimedia tools that collaborators can use online is the "Whiteboard." Just as whiteboards in offices are available for throwing out ideas and write them down, Java applets can create the same tool online.
- Skill level:
Other People Are Reading
Open a new file in your Java integrated development environment or your favoured text editor. Remember to create the file name with the .Java extension.
Import the libraries you will need to use the Swing graphical tool kit for creating the interface for your whiteboard applet. These will include "java.awt." and "java.awt.event." to get all the necessary functions.
Create your public class, within which you will write the rest of your code. Remember to match the name of the public class to the name of your file, excluding the ".java" extension.
Create a new frame for your user interface. Remember the syntax follows the pattern "Frame [your frame object name] = new Frame('[window title]')" including your name for the frame object and the title of the window.
Create any buttons you want for the interface. It is a whiteboard, so all you strictly need is a white rectangle, but you can add interface buttons and labels as you see fit. Remember to add these objects with "[your frame object name].add([your component);" until you have your interface built.
Add a mouse motion listener. This object will track the mouse around the whiteboard. Use the syntax "addMouseMotionListener( this );" to do this.
Create the events for when the mouse is clicked. Follow the form of:
x = e.getX();
You will get the coordinates where the mouse was clicked. Invoke your preferred drawing method, and pass the "x" and "y" coordinates so your program can draw at that location as the mouse moves. Finish with the "repaint()" function to add the new lines to your applet face.
Compile your code into a class file. Turn the code into an applet by using the "<APPLET = [your whiteboard program].class> </APPLET>" HTML tag.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for