, GUI Swing EDT.
. 1 ()
package com.evanmallory;
import java.awt.*;
import javax.swing.*;
public class TellTime extends JApplet {
private JLabel mMessage;
public TellTime() {
SwingUtilities.invokeLater( new Runnable() {
public void run() {
mMessage = new JLabel("Set the clock to the given time.",
SwingConstants.CENTER);
mMessage.setFont(new Font("Serif", Font.PLAIN, 36));
getContentPane().add(mMessage);
}
});
}
}
. 2 ( , )
( ), setFont(), Timer, , repaint().
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Random;
public class AppletBasic extends JApplet
{
Timer timer;
private void createGUI()
{
final JLabel appletLabel = new JLabel( "I'm a Swing Applet" );
appletLabel.setHorizontalAlignment( JLabel.CENTER );
ActionListener listener = new ActionListener() {
Random random = new Random();
public void actionPerformed(ActionEvent ae) {
int size = random.nextInt(24)+12;
appletLabel.setFont(new Font("Serif", Font.PLAIN, size));
repaint();
}
};
timer = new Timer(500, listener);
timer.start();
add( appletLabel );
}
public void init()
{
try
{
SwingUtilities.invokeAndWait(new Runnable()
{
public void run()
{
createGUI();
}
});
}
catch (Exception e)
{
System.err.println("createGUI didn't successfully complete: " + e);
}
}
}
.
<html>
<body>
<applet codebase="classes" code="com.evanmallory.TellTime.class"
width=800 height=500>
<param name="level" value="1"/>
<param name="topic" value="TellTime"/>
<param name="host" value="http://localhost:8080"/>
</applet>
</body>
</html>
codebase="classes" . Java, /classes ( /lib) .- ,
com.evanmallory.TellTime.class com.evanmallory.TellTime. <param name="host" value="http://localhost:8080"/> WAG, , . Applet.getDocumentBase() Applet.getCodeBase().
BTW - FF, Oracle Java. EDT (), .