Ben Fischer

Greenhorn
+ Follow
since Feb 22, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ben Fischer

You might try something like the applet-loading-another-applet trick on this web page.

http://www.wutka.com/hackingjava/ch2.htm
18 years ago
In general, each class is in a separate file. The class has methods that can be called from within the class or from outside the class. If one of the methods is called main() that will be called if the class is run as an application. Otherwise, when an object is created from a class, other than the constructor, nothing is run automatically.

Applets follow the same rules as classes without the "main" method: they just hang around waiting for something to call their methods. The difference is that there's not another java class interacting with them, but a web browser. As mentioned, the web browser calls init(), start(), stop(), destroy(), paint(), update(). The applet has no control over when those methods are called. paint() could be called repeatedly for a few minutes as the user scrolls or otherwise interacts with the web page, then not called again ever unless the applet kicks off a thread to call it periodically with the repaint() method (which simply requests the browser to call the applet's own paint() method).

You can have a main() method in your applet and run it as an application, as long as it's coded correctly. There's more work setting up the context, but some of the things may not apply to one mode of operation or the other, but it can be done.
18 years ago
It doesn't look blurry to me. How exactly do you mean? Does it flicker a lot? It does seem a little slow.
18 years ago
I would think so. Early on applets were where it was at, man. Now books like "Head First Java" (an excellent way to learn Java, by the way) don't even discuss them. There were a lot of problems with applets, some of them political, that probably held them back.

I know that Yahoo! still uses applets for their games, so they aren't dead technology, but clearly they didn't live up to Sun's hype and the current buzz is all centered on other things.
19 years ago
Technically I think you're not supposed to be able to do that. When an applet loses visibility it's supposed to stop. Even when an applet scrolls outside the visible portion of the web page it is supposed to be stopped, but every browser I tried will in fact let it keep running.

I can get your applet to work if i comment out the setVisible(false) line. Perhaps you could move it to the point after where you wake up the other applet, or you could just erase the contents of the original applet. Or you could replace the original applet with whatever you intended the 2nd applet to do.
19 years ago
I believe that any parameter you pass to an applet will get passed in as a string. What you do with that string is up to you. You could use it as a string, use a built-in method to convert it to a number or date or have a parse routine to convert the string into something more complicated.

Applets can access files on server so you can also pass a filename to the applet if what you're trying to pass is difficult or inconvenient to embed in the html.
19 years ago
For applets you don't create a panel, the applet is a panel. Also, the applet size is determined by the html that calls it. So the applet itself is pretty simple something like:

import java.awt.*;
import javax.swing.*;
import java.util.Random;

public class JavaGraphApp extends JApplet {
private final int Width=640;
private final int Height=480;
private int x=0,y=0;
Random rnd;

public void init() {
rnd=new Random();
}

public void paint (Graphics g) {
for (int i=0;i<100;i++) {
x=(int) (rnd.nextFloat()*Width);
y=(int) (rnd.nextFloat()*Height);
g.drawLine(x,y,x,y);
}
}
}

will do what you're looking for. Instead of defining the width and height probably you should use the getSize().width and getSize().height methods in case you specifiy different dimensions in the html.
19 years ago