Wrox Programmer Forums
|
BOOK: Beginning Java 2
This is the forum to discuss the Wrox book Beginning Java 2, SDK 1.4 Edition by Ivor Horton; ISBN: 9780764543654
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Java 2 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 5th, 2004, 10:17 AM
Authorized User
 
Join Date: Sep 2003
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Default The Line class

lingprash wrote:

India
Posted - 08/04/2004 : 6:54:18 PM

Dear Friends,
I cannot follow the Line class from Sir's Book.
IVOR HORTON : BEGINNING JAVA 2.
Can somebody explain me the nitty-gritty details
of the TryGeometry class too.
Honestly i tried going through the code but i am lost.
My sincere thanks to all you who will chip in with your advice.
Have A Nice Day !!!
__________________________________________________ ________

A Line is defined by two Points: the starting point and the end point. A Point is defined by two coordinates (x,y).
The x is the width measured from left to right.
The y is the height measured from the top to the bottom.

Every coordinate pair x,y should be measured in its own rendering context. This can be an area like a button or a frame or a panel, of which the top left is the (0,0) coordinate. A line could be drawn on a panel and you would supply the coordinates for the start and end points of this line measuring from the top left of the panel.

You can supply these coordinates as float or double type, creating a Line2D.Float or Line2D.Double object.

But what was your question, dear student of Sir Ivor's???

Francis from Holland




 
Old August 5th, 2004, 10:35 AM
Registered User
 
Join Date: Aug 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My question is:

Line(final Point start, final Point end)
  {
    this.start = new Point(start);
    this.end = new Point(end);
  }
what happens here???
************************************************** ****
Line(double xStart, double yStart, double xEnd, double yEnd)
  {
    start = new Point(xStart, yStart); // Create the start point
    end = new Point(xEnd, yEnd); // Create the end point
  }

what happens here...???

i presume here we get 8 coordinates...
That's what I think...

Have A Nice Day!!!



 
Old August 6th, 2004, 03:47 AM
Authorized User
 
Join Date: Sep 2003
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by lingprash
 My question is:

Line(final Point start, final Point end)
{
    this.start = new Point(start);
    this.end = new Point(end);
}
what happens here???
The arguments to the Line constructor are two Point objects.
These are called final so it is made impossible to change the value of the argument Point objects.
We use the two arguments to construct two new Point objects.
Which we store in the start point and end point to construct our new Line.
We use this to refer to the data variables of our Line, instead of the parameter values with the same name, so the compiler will know the difference.

Interesting is:
Here the compiler will not allow you to leave out the this qualifier, because the parameters are declared final.
Try it out!

An Object type variable is passed by reference. The data members of an Object can be changed when you have a reference to it. Qualifying it as final prevents changing the original object.

************************************************** ****
Quote:
quote:Originally posted by lingprash
Line(double xStart, double yStart, double xEnd, double yEnd)
{
    start = new Point(xStart, yStart); // Create the start point
    end = new Point(xEnd, yEnd); // Create the end point
}

what happens here...???

I presume here we get 8 coordinates...
No, 4 coordinates, creating two new Point objects: the start & end data members that define our Line.

Another constructor for a Line here, asking for 4 double type arguments.

Interesting is:
The parameters need not be declared final here. Because basic type variables (like double, char, etc.) are always duplicated when passed to a constructor. So the original double variables won't be modified, passing them as arguments to the Line constructor.





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to draw indicator line in owc line chart AlexOo General .NET 0 July 9th, 2007 10:32 PM
Reading a string from line by line vaidyapragati ASP.NET 2.0 Professional 1 May 3rd, 2007 08:43 AM
Property access from Class within Partial Class zoltac007 C# 2005 0 December 1st, 2006 01:01 AM
How to read file line by line in EVC++ iriskab Visual C++ 0 September 27th, 2006 01:39 PM
Reading line by line from a .txt file x_ray VB.NET 2002/2003 Basics 5 February 10th, 2006 01:55 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.