• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 224
  • Last Modified:

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
0
BrianGEFF719
Asked:
BrianGEFF719
  • 4
  • 3
  • 3
  • +2
1 Solution
 
BrianGEFF719Author Commented:
This needs to be as an applet.

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

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

<jdk>/demo/applets/DrawTest.java
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
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/

0
 
Mayank SAssociate Director - Product EngineeringCommented:
0
 
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
0
 
objectsCommented:
doesn't it have an import option?
0
 
Mayank SAssociate Director - Product EngineeringCommented:
In Netbeans, goto File -> New Project -> General -> Java Project with existing sources
0
 
BrianGEFF719Author Commented:
q. will be finalized later this week. thanks for patience.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Ok.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

  • 4
  • 3
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now