Simple JavaCode

Can someone provide me with code that takes a simple "canvas" as a java applet and allows the user to click two places on that canvas and draws a line between those two click points?


Brian
LVL 19
BrianGEFF719Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BrianGEFF719Author Commented:
This needs to be as an applet.

Brian
DeanHorakCommented:
This should be pretty close to what you're looking for

http://www.faqs.org/docs/javap/source/RubberBand.java
Mick BarryJava DeveloperCommented:
Have a look at DrawTest.java in the sample applets that come with the jdk

<jdk>/demo/applets/DrawTest.java

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Manikandan ThiagarajanSenior consultantCommented:
check this program modify according to your need


import java.applet.*;
import java.awt.*;
import java.awt.Event.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
public class MouseMotion  extends Applet implements MouseListener,MouseMotionListener

{

Point p;

public void init()
{
addMouseListener(this);
addMouseMotionListener(this);
}
      public void mouseClicked(MouseEvent arg0) {
            // TODO Auto-generated method stub
            
      }

      public void mousePressed(MouseEvent arg0) {
            p = arg0.getPoint();
            repaint();
            // TODO Auto-generated method stub
            
      }

      public void mouseReleased(MouseEvent arg0) {
            p = null;
            repaint();
            // TODO Auto-generated method stub
            
      }

      public void mouseEntered(MouseEvent arg0) {
            // TODO Auto-generated method stub
            
      }

      public void mouseExited(MouseEvent arg0) {
            // TODO Auto-generated method stub
            
      }

      public void mouseDragged(MouseEvent arg0) {
            // TODO Auto-generated method stub
            
      }

      public void mouseMoved(MouseEvent arg0) {
            // TODO Auto-generated method stub
            
      }
      public void paint(Graphics g)
      {
            if(p != null)
                  
            {
                  
                  Dimension d = getSize();
                  int xc = d.width/2;
                  int yc = d.height/2;
                  g.drawLine(xc,yc,p.x,p.y);
            }
      }
      

}


here is the tutorial


http://www.dgp.toronto.edu/~mjmcguff/learn/java/08-painting/

Mayank SAssociate Director - Product EngineeringCommented:
BrianGEFF719Author Commented:
How do I use netbeans to compile this stuff? I tried to make a general applet, but I'm having a hard time. How can I create a new project an import some of that sample .java code.

Brian
Mick BarryJava DeveloperCommented:
doesn't it have an import option?
Mick BarryJava DeveloperCommented:
Mayank SAssociate Director - Product EngineeringCommented:
In Netbeans, goto File -> New Project -> General -> Java Project with existing sources
BrianGEFF719Author Commented:
q. will be finalized later this week. thanks for patience.
Mayank SAssociate Director - Product EngineeringCommented:
Ok.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.