Results 1 to 5 of 5
  1. #1
    Robben is offline Member
    Join Date
    Feb 2015
    Posts
    67
    Rep Power
    0

    Default How to view an applet

    How can I view an applet? I have a source code, for the wave equation, that I am trying to view. I am on the command prompt and tried appletviewer wave.java but nothing happens. How can I view this applet?

    Source code:

    Java Code:
    /*****************************************************************************/
    /**                                                                          */
    /** (c) Copyright 1996 by                                                    */
    /**     SINTEF, Oslo, Norway.                                                */
    /**     All rights reserved.                                                 */
    /**                                                                          */
    /**     See the file Copyright.h for further details.                        */
    /**                                                                          */
    /*****************************************************************************/
    
    import java.awt.*;
    
    /*<wave:*/
    public class wave extends java.applet.Applet implements Runnable {
        int width;
        float func[];
        float func1[];
        int height;
        int time;
        Color clut[];
        Thread show;
        int speed;
        int prevx;
        int prevy;
        /*Image backBuffer;
        Graphics backGC;*/
    
        private void color(int[] l, int[] h) {
    	for (int x=l[0]; x<h[0]; x++) {
    	  float a = (x-l[0]) / (float)(h[0]-l[0]) / 65535.f;
    	  float b = 65535.f - a;
    	  clut[x] = new java.awt.Color(b*l[1]+a*h[1],
    					b*l[2]+a*h[2],b*l[3]+a*h[3]);
    	}
        }
        private void funcstart() {
    	width = size().width;
    	height = size().height;
    	func  = new float[width+1];
    	func1 = new float[width+1];
            for (int x = 0 ; x <= width ; x++) {
    	  float w = x / (float)width;
    	  func1[x] = func[x]  = height/2 * (float)
    		(1 + Math.sin(10.5f * 3.1415692f * w * w));
    	}
    	clut = new Color[height+1];
    	int n = 6;
    	int[][] table = {{0, 0, 0, 65535}, {1, 0, 65535, 65535}, 
    			{2, 0, 65535, 0}, {3, 65535, 65535, 0},
    			{4, 65535, 0, 0}, {5, 65535, 0, 65535}, 
    			{6, 0, 0, 65535}};
    	for (int i=0; i<n; i++) {
    	  table[i+1][0] = (int)((i+1) * (height+1) / (float)n);
    	  color(table[i], table[i+1]);
    	}
    	time = 0;
    	prevx = -10;
        }
        private void funccalc() {
    	float lap[];
    	lap = new float[width+1];
            for (int x = 1 ; x < width ; x++)
                lap[x] = 2 * func[x] - func[x+1] - func[x-1]; /* laplace */
    	float w;
            for (int x = 1 ; x < width ; x++) {
    	    w = func1[x];
    	    func1[x] = func[x];
                func[x] = (2 * func[x] - w) - lap[x];
            }
            for (int x = 1 ; x < width ; x++) { /* damp */
    	    lap[x] = func[x-1] + func[x+1];
            }
    	float a = .95f; /* [0,1], 1 is no damping */
    	float b = .5f * (1.f - a);
            for (int x = 1 ; x < width ; x++) {
                func[x] = a * func[x] + b * lap[x];
            }
    	func[width] = func[width-1]; /* boundary conditions */
    	time++;
    	if (prevx>=0) {
    	    func1[prevx] = func[prevx] = prevy;
    	}
        }
        private void funcpaint(Graphics g) {
            for (int x = 0 ; x < width ; x++) {
    	    g.setColor(clut[((int)func[x]+time) % height]);
                g.drawLine(x, (int)func[x], x + 1, (int)func[x + 1]);
    	}
        }
        public void init() {
            String att = getParameter("speed");
            speed = (att == null) ? 400 : (1000 / Integer.valueOf(att).intValue());
        }
        public void paint(Graphics g) {
             /*if (backBuffer != null) {
                    backGC.setColor(getBackground());
                    backGC.fillRect(0,0,size().width,size().height);
                    funcpaint(backGC);
                    g.drawImage(backBuffer, 0, 0, this);
              } else */
                    funcpaint(g);
        }
        public void start() {
    	funcstart();
    	show = new Thread(this);
    	show.start();
        }
        public void stop() {
    	func = new float[0];
    	func1= new float[0];
    	clut = new Color[0];
    	width= -1;
    	prevx= -1;
            show.stop();
        }
        public boolean mouseDown(Event e, int x, int y) {
    	if (x<0) x = 0;
    	if (x>width) x = width;
    	func1[x] = func[x] = y;
    	prevx = x;
    	prevy = y;
    	repaint();
            return true;
        }
        public boolean mouseUp(Event e, int x, int y) {
    	if (x<0) x = 0;
    	if (x>width) x = width;
    	func1[x] = func[x] = y;
    	prevx = -1;
    	prevy = y;
    	repaint();
            return true;
        }
        public boolean mouseDrag(Event e, int x, int y) {
    	if (x<0) x = 0;
    	if (x>width) x = width;
    	if (x==prevx) {
    	   func1[x] = func[x] = y;
    	} else if (x>prevx) {
    	  float h = (prevy-y)/(prevx-x);
    	  for (int i=prevx; i<=x; i++) {
    	     func1[i] = func[i] = y + (int)((i-x) * h);
    	     }
    	} else {
    	  float h = (prevy-y)/(prevx-x);
    	  for (int i=x; i<=prevx; i++) {
    	     func1[i] = func[i] = y + (int)((i-x) * h);
    	     }
    	}
    	prevx = x;
    	prevy = y;
    	repaint();
            return true;
        }
        public void update(Graphics g) {
            /*if (backBuffer == null)*/
                g.clearRect(0, 0, size().width, size().height);
            paint(g);
        }
        public void run() {
            while (true) {
    		try {Thread.currentThread().sleep(speed);}
    		catch (InterruptedException e){}
    		/*backBuffer = createImage(size().width, size().height);
    		backGC = backBuffer.getGraphics();*/
     		if (width != size().width)
    			funcstart();
    		repaint();
    		funccalc();
            }
        }
    }
    
    /*>wave:*/
    
    /*Class:wave
    
    NAME:  "wave" - java applet, 1D interactive wave equation
    
    SYNTAX:     @wave
    
    KEYWORDS:
    
      wave equation, finite differences
    
    
    DESCRIPTION:
    
      1D time-dependent wave equation simulator. Use mouse down to change
    single values. and mouse drag to change a sequence of values. Left boundary
    is Dirichlet, right boundary is homogeneus Neumann condition. No source
    term present.
    
    MEMBER FUNCTIONS:
    
      parameters: speed
    
    SEE ALSO:
    
    DEVELOPED BY:
    
                    SINTEF Applied Mathematics, Oslo, Norway, and
                    University of Oslo, Dept. of Mathematics, Norway
    
    AUTHOR:
    
                    Gerhard W. Zumbusch, SINTEF
    End:
    */

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: How to view an applet

    That looks like rather archaic code. AWT was replace by Swing around 15 years ago.

    Why don't you rewrite the program to display in a JPanel?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: How to view an applet

    ... or contact the author of the code if you need details.

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: How to view an applet

    What file is passed to the appletviewer program when you try to execute this applet?
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Robben is offline Member
    Join Date
    Feb 2015
    Posts
    67
    Rep Power
    0

    Default Re: How to view an applet

    Oh I see. It's going to be a long night for me then. Thanks for the help!

Similar Threads

  1. Error when trying to view applet in a .htm file
    By deapee in forum New To Java
    Replies: 7
    Last Post: 06-20-2011, 04:55 AM
  2. How enter this mode-gui/design-view/code-view
    By lse123 in forum NetBeans
    Replies: 0
    Last Post: 02-28-2010, 09:09 PM
  3. Applet - enter URL and view the page
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-10-2008, 02:38 PM
  4. Unable to view japanese in java applet
    By rogermakrm in forum Java Applets
    Replies: 5
    Last Post: 01-16-2008, 06:07 AM
  5. How to view applet from html page.
    By jwzumwalt in forum Java Applets
    Replies: 2
    Last Post: 11-24-2007, 04:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •