http://www.gasuinfo.org/planetarysystem/index.html

<html>
<head>
<title>Planetary system</title>
</head>
<body>
<p> Applet</p>
<p align=center> 
<applet code="applet.class"
	archive="planetary.jar"
	width="900"
	height="600"
>
</applet>
</p>
</body>
</html>

if i run my applet from eclipse, then it works fine.
in command line i wrote jar cvf0 planetary.jar *, jar file was created
and i uploaded it and i have index.html, applet.class and planetary.jar file
the applet just doesn't run. i've googled much about it, made it very simple, without codebase etc. also it doesn't work on my pc i get my applet as transparent and doesn't work. why is it so?

Recommended Answers

All 5 Replies

Where are all the files (jar, class, html) when you try to open the html page in a browser? Is the planetary class in a package?
What messages are in the browser's Java console? Please copy and paste them here.

hey, got it to work, eclipse ran it still as application, there had i a problem with correct extending from JFrame to JApplet.
But now there is another problem, i got

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Label;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.NumberFormat;


import javax.swing.BorderFactory;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;

import javax.swing.JPanel;

import planetary.PSController;



/**
 * Userinterface class / layer
 * 
 * @author Priit Reiser
 * lihtsustused A. Torim
 */
public class UserInterface extends JApplet [B]implements Runnable[/B]{

        [B]Thread t = null;
	boolean threadSuspended;[/B]

	private static final int SLEEP_BETWEEN_TICKS = 50;

	private static final String LBL_TITLE_INFO_PANEL = "Time";
	
	private static final String LBL_TITLE_PLANNED_SHIP_PANEL = "Planned SpaceShip";

	private static final String LBL_SINGLE_TICK = "Tick";

	private static final String LBL_STOP_AUTO_TICK = "Stop auto tick";

	private static final String LBL_START_AUTO_TICK = "Start auto tick";
	
	private static final String LBL_LAUNCH_SHIP = "Launch Spaceship";
	
	private static final String LBL_LAUNCH_PLANNED_SHIP = "Launch Planned Spaceship";
	
	private static final String LBL_LOG = "Log";
	
	private static final long serialVersionUID = 1L;

	private final PSController controller = new PSController(); 
	
	private double cx=0;
	private double cy=0;
	private double zoom=0;
	private double planetWidth=0;

	private static boolean tick = true;
	private static boolean auto = false;

	/**
	 * wait between ticks.
	 */
	private void busy() {
		try {
		Thread.sleep(SLEEP_BETWEEN_TICKS);						
		} catch (InterruptedException e) {
		e.printStackTrace();
			}
	}
	
	private JPanel planetsPanel = new JPanel(new FlowLayout()) {

		private static final long serialVersionUID = -4598415608421582065L;

		@Override
		public void paint(Graphics g) {			
			super.paint(g);
		    drawPlanets(g);		
		}
	};
	private JPanel buttonsPanel = new JPanel();
	private JPanel timeBtnPanel = new JPanel();
	private JPanel flightPlannedShipPanel = new JPanel();
	private JPanel logPanel = new JPanel(new FlowLayout());
	private JButton btnTick = new JButton(LBL_SINGLE_TICK);
	private JButton btnAuto = new JButton(LBL_START_AUTO_TICK);
	private JButton btnShip = new JButton(LBL_LAUNCH_SHIP);
	private JButton btnFLShip = new JButton(LBL_LAUNCH_PLANNED_SHIP);
	/**
	 * different commands 
	 */
	private final static int DIFF_COMMANDS = 3;
	
	/**
	 * [0] - wait(tick)
	 * [1] - direction changing
	 * [2] - speed changing
	 */
	JFormattedTextField ftf[] = new JFormattedTextField[DIFF_COMMANDS];
	JButton btn_flight[] = new JButton[DIFF_COMMANDS];
	Label des[] = new Label[DIFF_COMMANDS];
	{
	des[0] = new Label("Wait(tick):");
	ftf[0] = new JFormattedTextField(NumberFormat.getInstance());
	ftf[0].setToolTipText("Enter number how many ticks to wait before executing next command");
	btn_flight[0] = new JButton("Wait!");
	des[1] = new Label("Direction:");
	ftf[1] = new JFormattedTextField(/*NumberFormat.getInstance()*/);
	ftf[1].setToolTipText("Enter number how much to change angle of the ship");
	btn_flight[1] = new JButton("Change direction!");
	des[2] = new Label("Speed:");
	ftf[2] = new JFormattedTextField(/*NumberFormat.getInstance()*/);
	ftf[2].setToolTipText("Enter number how much to change speed of the ship");
	btn_flight[2] = new JButton("Change Speed!");
	}
	
	public UserInterface() {
		init();
	}
	
	public void init() {
		// 1. create new planetary system
		this.controller.makeSolarSystem();
		//this.controller.launchSpaceShip(3, 0.5, 0.5);
		this.planetWidth = 3;
		this.cx = 350.0;
		this.cy = 350.0;
		this.zoom = 7.0;
		
		timeBtnPanel.add(btnTick);
		timeBtnPanel.add(btnAuto);
		timeBtnPanel.add(btnShip);
		timeBtnPanel.add(btnFLShip);
		timeBtnPanel.setBorder(BorderFactory.createTitledBorder(LBL_TITLE_INFO_PANEL));
		logPanel.setBorder(BorderFactory.createTitledBorder(LBL_LOG));

		for (int i = 0; i < ftf.length; i++) {
			this.flightPlannedShipPanel.add(des[i]);
			this.flightPlannedShipPanel.add(ftf[i]);
			ftf[i].setColumns(4);
			this.flightPlannedShipPanel.add(btn_flight[i]);
			this.flightPlannedShipPanel.add(new JSeparator(SwingConstants.VERTICAL));
		}
		
		this.flightPlannedShipPanel.setBorder(BorderFactory.createTitledBorder(LBL_TITLE_PLANNED_SHIP_PANEL));
		
								
		this.planetsPanel.setBackground(Color.black);

		this.btnTick.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				handleBtnClickSingleTick();				
			}
		});
		
		this.btnAuto.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				handleBtnClickAutoTick();				
			}
		});
		
		this.btnShip.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				handleBtnLaunchSpaceShip();				
			}
		});
		
		this.btnFLShip.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				handleBtnLaunchFPSpaceShip();
			}
		});
		
		// oota(tick)
		btn_flight[0].addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				//handleBtnFPOota
				try {
					controller.wait(Integer.valueOf(ftf[0].getText()));
				} catch (NumberFormatException e) {
					exceptionMsg("wrong entered command");
				}
			}
		});
		
		// suund
		btn_flight[1].addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				//handleBtnFPSuund();
				try {
					controller.direction(Double.valueOf(ftf[1].getText()));
				} catch (NumberFormatException e) {
					exceptionMsg("wrong entered command");
				}
			}
		});
		
		// kiirus
		btn_flight[2].addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				//handleBtnFPKiirus();
				try {
					controller.speedFactor(Double.valueOf(ftf[2].getText()));
				} catch (NumberFormatException e) {
					exceptionMsg("wrong entered command");
				}
			}
		});
		
			
		buttonsPanel.setLayout(new BorderLayout());
		buttonsPanel.add(timeBtnPanel, BorderLayout.NORTH);
		buttonsPanel.add(flightPlannedShipPanel, BorderLayout.CENTER);
		timeBtnPanel.setBackground(Color.GRAY);
		flightPlannedShipPanel.setBackground(Color.GRAY);
		setLayout(new BorderLayout());
		JTextArea log = new JTextArea("here will be log later", 38, 15);
		log.setEditable(false);
		JScrollPane scrollPane = new JScrollPane(log);
		log.setLineWrap(true);
		scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		logPanel.setMinimumSize(new Dimension(100, 20));
		logPanel.setPreferredSize(new Dimension(200, 20));
		
		logPanel.add(scrollPane);
		add(buttonsPanel,BorderLayout.NORTH);
		add(planetsPanel, BorderLayout.CENTER);
		add(logPanel, BorderLayout.EAST);

		
		//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		//setSize(800,800);
		//setVisible(true);
		
	
		
		[B]new Thread(new Runnable() {
	    	public void run() {

	    		while(true) {
	    			
	    			if(tick) {
	    				
	    				
	    				// *** 1. calculate objects new coordinates ***
	    				controller.tick();
		    			
		    			// *** 2. draw changed position on UI***
		    			repaint();
						
		    			// *** 3. if we are in manual mode, then stop moving ***
						if(!auto) {
							tick = false;
						}						
	    			}
	    		
	    			busy();	    			
	    		}
	    	}
	   }).start();[/B]				
	}
	
	public void exceptionMsg(String s) {
		JOptionPane.showMessageDialog(null, s, "Error", 
				JOptionPane.ERROR_MESSAGE);
	}

	public void handleBtnClickSingleTick() {
		
		auto = false;
		tick = true;
		if (tick) this.btnAuto.setText(LBL_START_AUTO_TICK);
	}
	
	public void handleBtnClickAutoTick() {
		
		if(auto) {
			auto = false;
			tick = true;
			this.btnAuto.setText(LBL_START_AUTO_TICK);
		} else {
			auto = true;
			tick = true;
			this.btnAuto.setText(LBL_STOP_AUTO_TICK);
		}				
	}
	
	public void handleBtnLaunchSpaceShip() {
		if (auto) this.controller.launchSpaceShip(3, -0.5, -0.5);
	}
	
	public void handleBtnLaunchFPSpaceShip() {
		this.controller.executeCommands(this.controller.getPSS());
		if (auto) this.controller.launchFPSpaceShip(3, 0.5, 0.5);
	}
	
	public void drawPlanets(final Graphics g) {			
		for (int i=0; i<controller.getPlanetarySystem().size(); i++ ){
			drawPlanet(g, i);
		}

	}
	
	
	public void drawPlanet(final Graphics g, int planetID) {		
		
		double x = controller.getPlanetarySystem().getElement(planetID).getx();
		double y = controller.getPlanetarySystem().getElement(planetID).gety();
		double[] newCoordinates = convCoords(x, y);
		g.setColor(Color.RED);
		g.drawOval((int)newCoordinates[0] ,(int)newCoordinates[1], (int)planetWidth, (int)planetWidth);		
	}

	
 
	/**
	 * Simulation of coordinates convertion for UI suitable shapes
        Depends of attributes: 
        cx, cy - show centerpoint
        zoom - zoom
        planet_width - planet width
        Outputs 4 coordinates for drawing oval
	 */
	public double[] convCoords(double x, double y) {
		
		double x0 = (this.cx + x * this.zoom); 
		double y0 = (this.cy + y * this.zoom);
		double x1 = x0 + this.planetWidth;
		double y1 = y0 + this.planetWidth;
		
		return new double[] {
			x0, y0, x1, y1
		};
	}

[B]public void run() {
    		while(true) {
    			if(tick) {
    				// *** 1. calculate objects new coordinates ***
    				this.controller.tick();
	    			
	    			// *** 2. draw changed position on UI***
	    			repaint();
					
	    			// *** 3. if we are in manual mode, then stop moving ***
					if(!auto) {
						tick = false;
					}						
    			}	
    			busy();	    			
    		}
	}
	
	// Executed when the applet is destroyed.
	public void destroy() {
	      System.out.println("destroy()");
	   }

	   // Executed after the applet is created; and also whenever
	   // the browser returns to the page containing the applet.
	   public void start() {
	      System.out.println("start(): begin");
	      if ( t == null ) {
	         System.out.println("start(): creating thread");
	         t = new Thread( this );
	         System.out.println("start(): starting thread");
	         threadSuspended = false;
	         t.start();
	      }
	      else {
	         if ( threadSuspended ) {
	            threadSuspended = false;
	            System.out.println("start(): notifying thread");
	            synchronized( this ) {
	               notify();
	            }
	         }
	      }
	      System.out.println("start(): end");
	   }

	   // Executed whenever the browser leaves the page containing the applet.
	   public void stop() {
	      System.out.println("stop(): begin");
	      threadSuspended = true;
	   }[/B]

	public static void main(String args[]) {
		
		/*UserInterface content = new UserInterface();
		setContentPane(content);*/
		new UserInterface().show();
	}

}

If you click tick button, then everything will be moved once (a single tick). When i had it as application (the red code was active without green code) clicking on "start autotick" began moving elements without stoping, but now this button acts as single tick when i'm using the green code. took it from here http://www.dgp.toronto.edu/~mjmcguff/learn/java/06-threads/
and always makes a single move...

Have you tried debugging you code to see why it is not acting like you want it to?
Add some println()s to show how variables are changing value and where the code execution is going.

oi http://www.gasuinfo.org/planetarysystem/index.html
got it at last to work. the mistake was in the constructor. i was calling there out init() method, but when i commented out my constructor, then it just started to work.
i think i wont understand all the details soon. can't get it why this init method stopped the runnable, didn't even think about that problem is there. i could call my method from another plain method and another method again from another plain method and it shouldn't change anything..

The browser calls the init() method. Perhaps your calling it and then the browser calling it got it confused.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.