Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / May 2004

Tip: Looking for answers? Try searching our database.

JAVA - Probl?me avec une applet Java

Thread view: 
jimmy - 30 May 2004 23:48 GMT
Bonjour,
Ci-dessous vous trouverez le code Java qui pose probl?me ? la compilation.
pourriez-vous m'aider ? d?bogger. Merci..

Il s'agit de dessiner un segment de droite ? partir de la class Droite..
Comment proc?der pour ranger les class Point, Direction dans un packagepuis
la classe Droite dans un autre package.(j'ai essay? des packages imbriqu?s ,
mais j'ai toujours des probl?mes ? la
compilation)-----------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
import java.lang.Math;
import java.awt.Graphics;
import java.applet.Applet;

public class optique1 extends Applet implements
ActionListener,KeyListener,MouseListener,MouseMotionListener
{
  Droite axe = new Droite(80,420,0,1,0,0,800);
  public void init(){
    axe.traceSegment(this);
   }
}

public class Point
{
 double x;
 double y;
 double z;
Point(){this.x=0;this.y=0;this.z=0;}
Point(double x, double y,double z){this.x=x;this.y=y;this.z=z;}
public double getx(){return this.x;}
public double gety(){return this.y;}
public double getz(){return this.z;}
public void set(double x, double y,double z){this.x=x;this.y=y;this.z=z;}
public void setx(double x){this.x=x;}
public void sety(double y){this.y=y;}
public void setz(double z){this.z=z;}
}

public class Direction //cosinus directeurs
{
 double x;
 double y;
 double z;
Direction(){this.x=1;this.y=0;this.z=0;} // x direction principale, axe
optique
Direction(double x, double y,double z){this.x=x;this.y=y;this.z=z;}
public double getx(){return this.x;}
public double gety(){return this.y;}
public double getz(){return this.z;}
public void set(double x, double y,double z){this.x=x;this.y=y;this.z=z;}
public void setx(double x){this.x=x;}
public void sety(double y){this.y=y;}
public void setz(double z){this.z=z;}
}

public class Droite extends Graphics
{
 double x1;double y1;double z1;
 double x2;double y2;double z2;
 Droite(){this.x1=0;this.y1=0;this.z1=0;
               this.x2=0;this.y2=0;this.z2=0;} //point (0,0,0)
 Droite(Point p,Direction d,double
dist){this.x1=p.getx();this.y1=p.gety();this.z1=p.getz();
                dx=d.getx();dy=d.gety();dz=d.getz();
                this.x2=x1+dist*dx;this.y2=y1+dist*dy;this.z2=z1+dist*dz;}
 Droite(double x1,double y1,double z1,double l,double m,double n,double
dist){this.x1=p.getx();this.y1=p.gety();this.z1=p.getz();
                this.x2=x1+dist*l;this.y2=y1+dist*m;this.z2=z1+dist*n;}
 Droite(Point p1,Point
p2){this.x1=p1.getx();this.y1=p1.gety();this.z1=p1.getz();
                this.x2=p2.getx();this.y2=p2.gety();this.z2=p2.getz();}
 public void traceSegment(Graphics g)
{
  g.drawLine(this.x1,this.y1,this.x2,this.y2);//trac? en 2D
 }
}
Roedy Green - 31 May 2004 00:54 GMT
>Bonjour,
>Ci-dessous vous trouverez le code Java qui pose problème à la compilation.
[quoted text clipped - 4 lines]
>la classe Droite dans un autre package.(j'ai essayé des packages imbriqués ,
>mais j'ai toujours des problèmes à la compilation.

Here is your Applet. It had a great many problems. Now it draws a
horizontal red line.  I changed all the public classes to default so
that I could put everything in one file.

import java.applet.Applet;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class Optique extends Applet

// all methods for doing this are missing.
// implements ActionListener,
// KeyListener, MouseListener, MouseMotionListener
  {
  Droite axe = new Droite( 80,420,0,1,0,0,800 );

  public void init()
     {
     // moved code to paint, no graphics object available here.
     // axe.traceSegment(this);

     }

  public void paint( Graphics g )
     {
     System.out.println ( axe );

     // must pick a colour, or you will just paint white on white
     g.setColor( Color.RED );

     axe.traceSegment(g);
     }

  /**
   * Allow this applet to run as as application as well for testing
   *
   * @param args not used
   */
  public static void main( String args[] )
     {
     final Optique applet = new Optique(  );
     final Frame frame = new Frame( "Optique" );
     frame.setSize( 1000, 1000 );
     applet.init();
     frame.add( applet );
     frame.validate();
     frame.setVisible( true );
     applet.start();
     frame.addWindowListener(
                            new WindowAdapter ()
                               {
                               /**
                                * handler on window close
                                *
                                * @param e      event details
                                */
                               public void windowClosing (
WindowEvent e )
                                  {
                                  applet.stop();
                                  applet.destroy();
                                  System.exit( 0 );
                                  } // end WindowClosing
                               } // end anonymous class
                            );
     } // end main

  }

/**
* Point renamed to PointXYZ avoid confusion with java.awt.Point
* Defines a point in 3D cartesian space
*/
class PointXYZ
  {
  double x;
  double y;
  double z;

  PointXYZ()
     {
     this.x=0;
     this.y=0;
     this.z=0;
     }

  PointXYZ(double x, double y,double z)
     {
     this.x=x;
     this.y=y;
     this.z=z;
     }

  public double getx()
     {
     return this.x;
     }

  public double gety()
     {
     return this.y;
     }

  public double getz()
     {
     return this.z;
     }

  public void set(double x, double y,double z)
     {
     this.x=x;
     this.y=y;
     this.z=z;
     }

  public void setx(double x)
     {
     this.x=x;
     }

  public void sety(double y)
     {
     this.y=y;
     }

  public void setz(double z)
     {
     this.z=z;
     }
  }

/**
* defines a direction with x,y,z
* Instead of duplicating code, we inherit it from PointXYZ
*/
class Direction extends PointXYZ //cosinus directeurs
  {
  Direction()
     {
     super( 1, 0, 0 );
     } // x direction principale, axe optique

  Direction( double x, double y,double z )
     {
     super( x, y, z );
     }

  }

/**
* defines a 3D line segment
*/
class Droite
// I don't think you mean extends Graphics.
// This class has nothing to do with the java.awt.Graphics class.
// extends Graphics
  {
  double x1, y1, z1, x2, y2, z2;

  Droite()
     {
     this.x1=0;this.y1=0;this.z1=0;
     this.x2=0;this.y2=0;this.z2=0;
     } //point (0,0,0)

  Droite(PointXYZ p,Direction d,double dist)
     {
     this.x1=p.getx();
     this.y1=p.gety();
     this.z1=p.getz();
     double dx=d.getx();
     double dy=d.gety();
     double dz=d.getz();
     this.x2=x1+dist*dx;
     this.y2=y1+dist*dy;
     this.z2=z1+dist*dz;
     }

  Droite(double x1, double y1, double z1,
         double l, double m, double n, double dist)
     {
     // is no p.
     //this.x1=p.getx();
     //this.y1=p.gety();
     //this.z1=p.getz();
     // I presume you mean
     this.x1=x1;
     this.y1=y1;
     this.z1=z1;

     this.x2=x1+dist*l;
     this.y2=y1+dist*m;
     this.z2=z1+dist*n;
     }

  Droite( PointXYZ p1, PointXYZ p2 )
     {
     this.x1=p1.getx();
     this.y1=p1.gety();
     this.z1=p1.getz();
     this.x2=p2.getx();
     this.y2=p2.gety();
     this.z2=p2.getz();
     }

  public void traceSegment(Graphics g)
     {
     // drawLine takes int values
     g.drawLine((int)this.x1,
                (int)this.y1,
                (int)this.x2,
                (int)this.y2);//tracé en 2D
     }

  /**
   * debugging tool
   *
   * @return string representation of the line
   */
  public String toString()
     {
     return
     "x1:" + x1 + " y1:" + y1 +  z1:" + z1
     + " x2:" + x2 + " y2:" + y2 + " z2:" + z2;
     }

  }

Signature

Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

jimmy - 31 May 2004 13:04 GMT
Thanks you very much,
The problem is completly resolved .

Now, I would like to put each java-class on one file and create the
packages. Would you show me an method and practice example using my first
problem to realese it .

Thanks you by advance...
----------------------------------------------------
"Roedy Green" <look-on@mindprod.com.invalid> a ?crit

I changed all the public classes to default so
> that I could put everything in one file.
Roedy Green - 31 May 2004 13:19 GMT
>/**
> * Point renamed to PointXYZ avoid confusion with java.awt.Point
[quoted text clipped - 11 lines]
>      this.y=0;
>      this.z=0;

If you put each class in its own file it would like this:

package com.mindprod.optique;

public class PointXYZ
{
...
}

See http://mindprod.com/jgloss/package.html
http://mindprod.com/jgloss/import.html
http://mindprod.com/jgloss/javacexe.html
http://mindprod.com/jgloss/javaexe.html

Signature

Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

jimmy - 31 May 2004 16:13 GMT
Please, would you give mean example using my first Optique class and compose
it in a package optique_project..
thanks you...
---------------------------------------------------------
> See http://mindprod.com/jgloss/package.html
> http://mindprod.com/jgloss/import.html
> http://mindprod.com/jgloss/javacexe.html
> http://mindprod.com/jgloss/javaexe.html
Roedy Green - 31 May 2004 21:53 GMT
>Please, would you give mean example using my first Optique class and compose
>it in a package optique_project..
>thanks you...

No.  You are asking me to spoon feed you. I showed you for one class,
so surely you can do it for any class now.  At least make an effort.

At least TRY several thing and show us what happened.

Signature

Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.