SwingGUIコンポーネントがEDTで作成および更新されていることを確認してください。
EG 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);
}
});
}
}
EG 2(アプレットビューア以外ではテストされていません)
camickrの例に基づいていますが、0.5秒ごとに起動setFont()
するaにラップされた呼び出しと、それに続く。への呼び出しがあります。Timer
repaint()
// <applet code="AppletBasic" width="300" height="100"></applet>
// The above line makes it easy to test the applet from the command line by using:
// appletviewer AppletBasic.java
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;
/**
* Create the GUI. For thread safety, this method should
* be invoked from the event-dispatching thread.
*/
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) {
// determine a size between 12 & 36.
int size = random.nextInt(24)+12;
appletLabel.setFont(new Font("Serif", Font.PLAIN, size));
// tell the applet to repaint
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
)ディレクトリはサーバー専用であり、アプレットからはアクセスできません。
- code属性は、cassの完全修飾名である必要があるため、。である
com.evanmallory.TellTime.class
必要がありますcom.evanmallory.TellTime
。
<param name="host" value="http://localhost:8080"/>
私は、その値が展開時に不要または間違っているWAGを作成する準備ができています。実行時にApplet.getDocumentBase()
またはを使用して決定することをお勧めしますApplet.getCodeBase()
。
ところで-アプレットは、最近のOracleJavaを実行している最近のFFで正常に機能しました。ただし、EDTの問題は不確定(ランダム)であるため、あまり意味がありません。