?
Solved

Simple JavaCode

Posted on 2006-03-30
12
Medium Priority
?
221 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
0
Comment
Question by:BrianGEFF719
  • 4
  • 3
  • 3
  • +2
12 Comments
 
LVL 19

Author Comment

by:BrianGEFF719
ID: 16339231
This needs to be as an applet.

Brian
0
 
LVL 11

Expert Comment

by:DeanHorak
ID: 16339267
This should be pretty close to what you're looking for

http://www.faqs.org/docs/javap/source/RubberBand.java
0
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 16339479
Have a look at DrawTest.java in the sample applets that come with the jdk

<jdk>/demo/applets/DrawTest.java
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:Manikandan Thiagarajan
ID: 16339665
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/

0
 
LVL 19

Author Comment

by:BrianGEFF719
ID: 16340045
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
0
 
LVL 92

Expert Comment

by:objects
ID: 16340151
doesn't it have an import option?
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16340374
In Netbeans, goto File -> New Project -> General -> Java Project with existing sources
0
 
LVL 19

Author Comment

by:BrianGEFF719
ID: 16363810
q. will be finalized later this week. thanks for patience.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16367720
Ok.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month15 days, 18 hours left to enroll

850 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