We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

Simple JavaCode

BrianGEFF719
BrianGEFF719 asked
on
Medium Priority
236 Views
Last Modified: 2010-03-31
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
Comment
Watch Question

Author

Commented:
This needs to be as an applet.

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

http://www.faqs.org/docs/javap/source/RubberBand.java
Java Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
Have a look at DrawTest.java in the sample applets that come with the jdk

<jdk>/demo/applets/DrawTest.java

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Mayank SPrincipal Technologist
CERTIFIED EXPERT

Commented:
Manikandan ThiagarajanSenior consultant

Commented:
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 SPrincipal Technologist
CERTIFIED EXPERT

Commented:

Author

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 Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
doesn't it have an import option?
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
Mayank SPrincipal Technologist
CERTIFIED EXPERT

Commented:
In Netbeans, goto File -> New Project -> General -> Java Project with existing sources

Author

Commented:
q. will be finalized later this week. thanks for patience.
Mayank SPrincipal Technologist
CERTIFIED EXPERT

Commented:
Ok.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.