Solved

java painting applet

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
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 …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

743 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

12 Experts available now in Live!

Get 1:1 Help Now