Hi,
 
 As per the previous discussion I have tried simple applet progarmme in the tools directoroy & I m able to compile & run it successfully( So It can find the class file ). But When ever I m going to modify that programme with Listen Programme logic Its givning me errors that It cannot detect Package net.tinyos.tools; But as per my knowledge both the files ( Applet file & original Listen programme are in the same folder named "tools" ) so How it can be possible that with the original programme Listen.java compiler finds the package & with my programme called "circle.java" Its could not find the same package. Because in both the cases the classpath will remain same & files are in same folder.
 
 
I m showing the code I have written for my applet which may give u some hints. what's goona wrong.
 
// W! hat follows here is a special javadoc comment, which is
// used for automatic generation of documentation in HTML.
/**
* Simple applet of moving circle.
*
* @author Les Kitchen <[EMAIL PROTECTED]>
*
*
*/
// This is probably a lot more heavily commented than necessary,
// for didactic purposes...
// Imported stuff for windowing, events, and applets...
 
 
package net.tinyos.tools;
import java.io.*;
import net.tinyos.packet.*;
import net.tinyos.util.*;
import net.tinyos.message.*;
 
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
// Comment-embedded sample HTML code for invoking this applet
// So that the source code can be fed to appletviewer
// In the applet HTML tag, code is the .class file where the
// Java bytecode can be found, as a URL (in this case a relative URL),
// and width and height give the width and height of the applet.
// The param tags pass parameters to the applet (only one here).
/*
<applet code="Circle" width=300 height=200>
<param name=sleeptime value=100>
</applet>
*/
 
// This is a specialization of the Java Applet class, and it has
// to implement the KeyListener, MouseListener and Runnable interfaces
// so it can respectively handle key events, handle mouse events, and be
// run as a thread.
public class Circle extends Applet
implements KeyListener, MouseListener, Runnable {
// Encodings of directions -- "final" so they're in effect constants
// Even numbers so diagonal directions could be added later
// Multiples of 45 degrees anticlockwise from East
final int E = 0; // East
final int N = 2; // North
final int W = 4; // West
final int S = 6; // South
// Various bits of information for our applet's state
int direction = E; // movement direction
int cx = 10, cy = 10; // circle center
int diameter = 20; // circle diameter
Thread t = null; // Thread for moving the circle
boolean running = false; // Whether thread is running
// How long to sleep between circle movements, milliseconds.
int sleeptime = 100;
 
 
//jatin code
static double kk=0;
int mote1_id=0,mote1_light=0;
static double range=2147483.648;
 
// The next four methods, init(), start(), stop(), ! and paint(),
// are part of Applet. We override them here to do what we want.
// There's also a destroy() method, but we don't need to worry about
// it.
// Called from outside when the applet is first created
public void init() {
System.out.println("This is in init ");
// Grab (as a string) the parameter named "sleeptime"
// from the HTML applet's param tag
String sleepstring = getParameter("sleeptime");
// The sleeptime parameter may not have been provided
// (note null object not empty string), or may have been
// badly formatted, triggering a caught exception. In
// either case, stick with default.
try {
if( sleepstring != null ) {
sleeptime = Integer.parseInt(sleepstring); // Like atoi() in C
}
} catch(NumberFormatException e) {
!
// Do nothing if badly formatted number triggers exception
}
// Nominate this applet itself as the listener for key and mouse
// events.
addKeyListener(this);
addMouseListener(this);
requestFocus(); // Request input focus -- needed to get input at all
// Background color for the applet's window
setBackground(Color.WHITE);
}
// Called from outside whenever applet starts running -- whenever it
// becomes visible
public void start () {
System.out.println("This is in start ");
// All we do is create a new thread to run the run() method
// of this applet, and set it going.
t = new Thread(this);
running = true;
t.start();
}
// Called from outside whenever applet stops running -- whenever it
// becomes invisible. So we don'! t have to waste CPU cycles updating
// the graphics display unnecessarily.
public void stop () {
System.out.println("This is in stop ");
// All we do is mark that the thread should stop running,
// to be noticed by the run() method next time it wakes up.
running = false;
// Not strictly necessary, but if we no longer keep a reference
// to the thread, then it can get garbage collected sooner.
t = null;
}
// Called from outside whenever the applet should have its
// window display redrawn.
public void paint(Graphics g) {
System.out.println("This is in paint ");
// Gets passed the Graphics object on which to draw.
// All we do is pass it on to our own method.
g.setColor(new Color(234));
drawCircle(g, cx, cy, diameter );
}
 
// This is the one method required to implement the Runnable interface.
// It's called by a thread to do our work. This is the heart of
// the applet's action.
public void run () {
//////////////////////////////////////////////////////////////////////////////
/*
System.out.println("This is in run ");
// We loop (almost) forever, repainting, sleeping a bit, and
// calling our own method move() to change the position of
// the circle. The thread terminates when running gets set
// to false (presumably by stop()), so we have to keep polling that.
for(;;) {
try {
// This is the preferred way for an applet to ask for
// its window to be redrawn. Calling paint() directly
// would holdup execution while the (possibly lengthy)
// paint() method completed. C! alling repaint() just
// tells the system to schedule a call to paint()
// sometime real soon now.
repaint();
if(!running) break;
Thread.sleep(sleeptime);
move();
} catch (InterruptedException e) {
// The thread might get interrupted. We have to
// catch that exception just to do nothing about it.
}
}
*/
//////////////////////////////////////////////////////////////////////////////
 
System.out.println("This is in run ");
// We loop (almost) forever, repainting, sleeping a bit, and
// calling our own method move() to change the position of
// the circle. The thread terminates when running gets set
// to false (presumably by stop()), so we have to keep polling that.
PacketSource reader = BuildSource.makePacketSource();
if (reader! == null) {
System.err.println("Invalid packet source (check your MOTECOM environment variable)");
System.exit(2);
}
try {
reader.open(PrintStreamMessenger.err);
for(;;) {
try {
// This is the preferred way for an applet to ask for
// its window to be redrawn. Calling paint() directly
// would holdup execution while the (possibly lengthy)
// paint() method completed. Calling repaint() just
// tells the system to schedule a call to paint()
// sometime real soon now.
repaint();
if(!running) break;
Thread.sleep(sleeptime);
// move();
////////////////////
byte[] packet = reader.readPacket();
//jatin code for displaying the light value :
String st=new String();
String st1=new String();
String bs = Integer.toHexString(packet[13] & 0xff).toUpperCase();
if (packet[13] >=0 && packet[13] < 16)
st=st.concat("0");
st=st.concat(bs);
String bs1 = Integer.toHexString(packet[14] & 0xff).toUpperCase();
st1= bs1.concat(st);
// System.out.println("This is main string " + st1 );
System.out.println("This is final FROM THIS & DISABLED " + Integer.valueOf(st1,16));
mote1_id=(Integer.valueOf(st1,16)).intValue();
System.out.println();
//END //jatin code for displaying the light value :
//jatin code for displaying the SOURCE MOTE :
st=new String("");
st1=new String("");
bs=new String("");
bs1=new String("");
bs = Integer.toHexString(packet[9] & 0xff).toUpperCase();
if (packet[9] >=0 && packet[9] < 16)
st=st.concat("0");
st=st.concat(bs);
bs1 = Integer.toHexString(packet[10] & 0xff).toUpperCase();
st1= bs1.concat(st);
// System.out.println("This is main string " + st1 );
System.out.println("This is final FROM THIS & DISABLED : ADC CHANNEL " + Integer.valueOf(st1,16));
mote1_light=(Integer.valueOf(st1,16)).intValue();
mote1_light=(int)((range * mote1_light)+ 1073741.821);
System.out.println();
//END // jatin code for displaying the SOURCE MOTE :
// Dump.printPacket(System.out, packet);
System.out.println();
System.out.flush();
//////////////////////
} catch (InterruptedException e) {
// The thread might get interrupte! d. We have to
// catch that exception just to do nothing about it.
}
} // end of for loop :
} // end of try
catch(Exception ee) {
}
///////////////////////////////////////////////////////////////////
}
 
 
// The next three methods have to be here so our applet implements
// the KeyListener interface.
// Called from outside whenever a key is depressed.
public void keyPressed(KeyEvent ke) {
// Basically, get the key code from the event object passed in
// and do various things, like change size of the circle for
// PAGE_UP PAGE_DOWN, or change direction of motion for arrow
// keys. Note this just changes the internal parameters of
// the applet; the movement of the circle, and the drawing
!
// happens elsewhere.
int key = ke.getKeyCode();
switch(key) {
case KeyEvent.VK_PAGE_DOWN:
if( diameter > 1 ) --diameter;
break;
case KeyEvent.VK_PAGE_UP:
diameter++;
break;
case KeyEvent.VK_LEFT:
direction = W;
break;
case KeyEvent.VK_RIGHT:
direction = E;
break;
case KeyEvent.VK_UP:
direction = N;
break;
case KeyEvent.VK_DOWN:
direction = S;
break;
}
// Show what's happening in the status line.
// Note: + is Java's string concatenation operator, and a
// number in string context is automagically converted into
// its string representation.
showStatus("Diameter: " + diameter + ", Direction: " + direction);
}
// These two methods have to be de! fined (with null bodies) so we
// fully implement the KeyListener interface.
// We probably could just as easily have done our stuff instead in the
// keyTyped() method. Done the way we have here, the change happens
// as soon as the key is pressed, and doesn't wait for it to be
// released.
// Actually keyTyped() probably wouldn't do the job, since it
// just handles typed-in characters -- wouldn't handle arrow
// keys and such.
public void keyReleased(KeyEvent ke) {
}
public void keyTyped(KeyEvent ke) {
}
 
// The next five methods are necessary to fully implement
// the MouseListener interface, but only mouseClicked has
// a non-null body, since that's all we care about.
public void mouseClicked(MouseEvent me) {
// Set the circle center to be where the mouse clicked.
cx = me.getX(); cy = me.getY();
showStatus("Diameter: " + diameter + ", Direction: " + direction +
", Jumped to (" + cx + "," + cy + ")" );
}
public void mouseEntered(MouseEvent me) {
}
public void mouseExited(MouseEvent me) {
}
public void mousePressed(MouseEvent me) {
}
public void mouseReleased(MouseEvent me) {
}
 
// This is our own method to draw a circle of given
// radius and center (in a given Graphics object).
// It just makes a call on the underlying drawOval()
// method, with the obvious geometric adjustments.
void drawCircle( Graphics g, int ccx, int ccy, int ccd ) {
System.out.println("This is in drawCircle ");
int r = diameter/2;
g.drawOval( ccx-r, ccy-r, ccd, ccd );
}
// This is our own method for updating the position of the circle
// each time step. Basically, it just moves one pixel in the
// appropriate direction, and "bounces" back off the edge of the
// window when it touches (or gets closer than touching, just in
// case it slipped by because of some subtlety that escapes me --
// ah yes, you might mouse-click very close to the edge).
void move() {
System.out.println("This is in move ");
int r = diameter/2;
Dimension d = getSize();
switch( direction ) {
case E:
if( cx+r >= d.width-1 ) {
cx = d.width-r;
direction = W;
} else {
cx++;
}
break;
case W:
if( cx-r <= 0 ) {
cx = r;
direction = E;
} else {
--cx;
}
break;
case S:
if( cy+r >= d.height-1 ) {
cy = d.height-r;
direction = N;
} else {
cy++;
}
break;
case N:
if( cy-r <= 0 ) {
cy = r;
direction = S;
} else {
--cy;
}
break;
}
}
}//end of Circle applet
 
          In above code I have merged some of the codes of Listen.java & Dump.java files which are available in tools & message folders..
 
 
Thanks
 
         

Michael Schippling <[EMAIL PROTECTED]> wrote:
you _should_ be able to set a classpath in your environment
before starting appletviewer...I think. The easiest might be
to try: export CLASSPATH=. and then run the viewer from
tools/java where it will then search down net/tinyos/...
Or include the full path to your tools/java in the CP and
you can run from anywhere.

On the other hand you may just need to specify the full
package name to the viewer: net.tinyos.tools.Listen

Also I believe you want the class file, not the .java file
so leave off ".java". I think I used appletviewer once so
take this all with a grain of salt...

MS

nandy jones wrote:
> Hi,
>
> I m trying to modify the Listen.java file for fetching the light value
> as its done in oscilloscope application. In which I have modified some
> of the content of Listen.java file. I have made it ext! ended with
> applets. So when I m trying to run it with
>
> appletviewer Listen.java
>
> It shows the FOLLOWING ERROR
> $ appletviewer Listen.java
> java.lang.NoClassDefFoundError: Listen (wrong name: net/tinyos/tools/Listen)
> at java.lang.ClassLoader.defineClass0(Native Method)
> at java.lang.ClassLoader.defineClass(ClassLoader.java:502)
> at
> java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
> 3)
> at
> sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:148)!
> at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
> at
> sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:114)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
> at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:501)
> at sun.applet.AppletPanel.createApplet(AppletPanel.java:567)
> at sun.applet.AppletPanel.runLoader(AppletPanel.java:496)
> at sun.applet.AppletPanel.run(AppletPanel.java:293)
> at java.lang.Thread.run(Thread.java:536)
>
>
> So I think there is problem with class path setting But where I can set
> the path..
> because It seems ! all files are compiled with make command..
>
> so please let me know which file to edit for setting classpath OR its
> the different problem..
>
> thanks
>
> ------------------------------------------------------------------------
> Yahoo! Photos
> Ring in the New Year with Photo Calendars
> .
> Add photos, events, holidays, whatever.
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tinyos-help mailing list
> [email protected]
> https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to