DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3

Thread: java problem

  1. #1
    Join Date
    Oct 2004
    Posts
    11

    java problem

    Code:
    Hi!
    I have a little problem whit main method.
    How do I put  Point  object as parameter in main method:
    my.buildRect(?, ?);
    -----------------
    import  java.awt.Point;
    class myOverLoad{
      int x1=0;
      int y1=0;
      int x2=0;
      int y2=0;	
    
      myOverLoad buildRect(int x1, int y1, int x2, int y2){
      	this.x1=x1;
      	this.y1=y1;
      	this.x2=x2;
      	this.y2=y2;
      	return this;
      }
       myOverLoad buildRect(Point topleft, Point  bottomRight){
          x1=topleft.x;
          y1=topleft.y;
          x2=bottomRight.x;
          y2=bottomRight.y;
         return this;
      }
      
      
       myOverLoad buildRect(Point topleft, int w, int h){
          x1=topleft.x;
          y1=topleft.y;
          x2=(x1+w);
          y2=(y1+h);
         return this;
      }
    	
    }
    
    
    class Overload1{
          public static void main (String[]args){
          myOverLoad  my =  new myOverLoad();
    		 
                my.buildRect(1, 2, 3, 4);
    	     my.buildRect(?, ?);//WHAT DO I WRITE HERE?????
    	 	//******     ********  ********************
                   my.buildRect(?,10,11);
    }
    }
    ------------------
    I have another question also, If I do not import  Point.
    How can I solve the problem.
    If I write the point class like this;
    class point{
       int x; int y;
    }
     int getx(){
     	return x;
     }
    int gety(){
     	return y;
     }
    }

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560

    Like this

    Code:
    import  java.awt.Point;
    class myOverLoad{
      int x1=0;
      int y1=0;
      int x2=0;
      int y2=0;	
    
      public myOverLoad buildRect(int x1, int y1, int x2, int y2){
      	this.x1=x1;
      	this.y1=y1;
      	this.x2=x2;
      	this.y2=y2;
      	return this;
      }
      public myOverLoad buildRect(Point topleft, Point  bottomRight){
          x1=topleft.x;
          y1=topleft.y;
          x2=bottomRight.x;
          y2=bottomRight.y;
         return this;
      }
      
      
       public myOverLoad buildRect(Point topleft, int w, int h){
          x1=topleft.x;
          y1=topleft.y;
          x2=(x1+w);
          y2=(y1+h);
         return this;
      }	
    }
    class Overload1{
        public static void main (String[]args){
          myOverLoad  my =  new myOverLoad();
    		 
          my.buildRect(1, 2, 3, 4);
          my.buildRect(new Point(1,2), new Point(3,4)); 
          my.buildRect(new Point(1,2),10,11);
      }
    }
    As for coding your own Point class I cannot see how that could be of any
    help at all.

  3. #3
    Join Date
    Oct 2004
    Posts
    11
    Hi!
    Thank you very much.
    Morgan

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links