codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  need help  amain at 08:46 on Monday, February 27, 2006
 

Hallo,
I'm new here...
I want to built the application which is after the application run, user can make two point with mouse and after that the system will calculate the distance between two point...
So can java do that?
If yes, can someone help me in this issues?
Everyone can help me.

<Added>

And i want the source code that can move the line using mouse

  Re: need help  crwood at 19:45 on Monday, February 27, 2006
 


import java.awt.*;
import java.awt.event.*;
import java.text.NumberFormat;
import javax.swing.*;

public class MousePoints extends JPanel
{
Point start;
Point end;
JLabel label;
NumberFormat nf;
int lastPoint;
final int START_POINT = 0;
final int END_POINT = 1;

public MousePoints()
{
start = new Point(-2,-2);
end = new Point(-2,-2);
nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(1);
lastPoint = END_POINT;
}

protected void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.drawLine(start.x, start.y, end.x, end.y);
g2.setPaint(Color.red);
g2.fillRect(start.x-2, start.y-2, 4, 4);
g2.fillRect(end.x-2, end.y-2, 4, 4);
}

public void setPoint(Point p)
{
if(lastPoint == START_POINT)
{
end = p;
lastPoint = END_POINT;
}
else
{
if(end.x == -2) // for the first time
end = p;
start = p;
lastPoint = START_POINT;
}
setDistance();
repaint();
}

private void setDistance()
{
double distance = start.distance(end);
label.setText(nf.format(distance));
}

private JLabel getLabel()
{
label = new JLabel();
label.setHorizontalAlignment(JLabel.CENTER);
Dimension d = label.getPreferredSize();
d.height = 35;
label.setPreferredSize(d);
return label;
}

public static void main(String[] args)
{
MousePoints mp = new MousePoints();
PointPlacer placer = new PointPlacer(mp);
mp.addMouseListener(placer);
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(mp);
f.getContentPane().add(mp.getLabel(), "South");
f.setSize(400,400);
f.setLocation(200,200);
f.setVisible(true);
}
}

class PointPlacer extends MouseAdapter
{
MousePoints mousePoints;

public PointPlacer(MousePoints mp)
{
mousePoints = mp;
}

public void mousePressed(MouseEvent e)
{
mousePoints.setPoint(e.getPoint());
}
}


  Re: need help  amain at 10:01 on Wednesday, March 01, 2006
 

Thank you crwood....
I i have any problem, can i ask you again?


  Re: need help  crwood at 15:32 on Wednesday, March 01, 2006
 

Yes.

  Re: need help  amain at 05:43 on Friday, March 03, 2006
 

Ok..
I hava stupid question i think...
Can i put java coding in php coding?
And java and javascript.. Is that similar thing?








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: need help in applet communication
•  Re: MS Access connection in JSP
•  Highlight a DataGrid Row and Stay there -
•  Numeric field
•  Re: visible/invisible divs
•  radio buttons questionnaire
•  Re: Splitter in DHTML, no frames
•  Re: how to set value to texbox
•  Re: IE page Redirect


Recent Articles
What is a pointer in C?
Multiple submit buttons with form validation
Understanding Hibernate ORM for Java/J2EE
HTTP screen-scraping and caching
a javascript calculator
A simple way to JTable
Java Native Interface (JNI)
Parsing Dynamic Layouts
MagicGrid
Caching With ASP.Net


© Copyright codetoad.com 2001-2006