Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

java painting applet

Posted on 2000-03-17
3
Medium Priority
?
1,069 Views
Last Modified: 2013-11-23
Hello,
         can anyone help I am looking for a java applet that can be used by children in a educational site.

Is there any free applets that can be used to draw paint etc but very siimply with 1 color and brush size being able to change brushes and colors is not required. ie tha ability for kids to be able to draw in a thin pencil off white color on a black background is ideal.

best wishes from New zealand
0
Comment
Question by:wampy
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
loumf earned 600 total points
ID: 2630458
Here's source for something simple.
Draw with the mouse, erase by refreshing the page.  If you need the class file tell me your email and I'll send that and sample html

// DrawApplet
//

import java.awt.*;
import java.applet.*;
import java.util.*;


public class DrawApplet extends Applet
{
      public void init()
      {
      }

      public boolean mouseDown(Event e, int x, int y)
      {
            FDown = true;
            FX = x;
            FY = y;
            return true;
      }
      
      public boolean mouseUp(Event e, int x, int y)
      {
            FLines.addElement(new Rectangle(x,y, FX, FY));
            FDown = false;
            return true;
      }
      
      public boolean mouseDrag(Event e, int x, int y)
      {
            if (FDown) {
                  FLines.addElement(new Rectangle(x,y, FX, FY));
                  FX = x;
                  FY = y;
                  repaint(10);
            }
            return true;
      }      
      
      public void update(Graphics g)
    {
            Graphics gr;
               
            if (FOffScreenBuffer==null ||
                  (! (FOffScreenBuffer.getWidth(this) == this.size().width
                  && FOffScreenBuffer.getHeight(this) == this.size().height))) {
                  
                    FOffScreenBuffer = this.createImage(size().width, size().height);
            }

            // We need to use our buffer Image as a Graphics object:
            
            gr = FOffScreenBuffer.getGraphics();
            gr.clearRect(0,0,size().width, size().height);
            
            paint(gr);
            
            g.drawImage(FOffScreenBuffer, 0, 0, this);                  
    }

      
      public void paint(Graphics g)
      {
            g.setColor(Color.black);
            g.fillRect(0,0,getSize().width, getSize().height);
            g.setColor(Color.white);
            for (int i = 0; i < FLines.size(); ++i) {
                  Rectangle r = (Rectangle)FLines.elementAt(i);
                  g.drawLine(r.x, r.y, r.width, r.height);
            }
      }
      
      private boolean FDown = false;
      private int FX = 0;
      private int FY = 0;
      private Vector FLines = new Vector();
      private Image FOffScreenBuffer;
}
0
 

Author Comment

by:wampy
ID: 2630669
yes if you could please send applet and sample htm im off trying to figure a compiler my email is arrowtow@es.co.nz.

are you interested in custom applet jobs?

all the best Gerald.
0
 

Author Comment

by:wampy
ID: 2630733
ok thanks ive worked it out found a programme on my linux box  guavac that compiled it aok.

for 50 more points can you show me how to make a clear screen button.

many thanks gerald
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

972 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