Solved

java painting applet

Posted on 2000-03-17
3
1,028 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 150 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now