JApplet没有显示在HTML文档中

时间:2019-08-29 13:26:14

标签: java html applet

我无法使用Firefox或Chrome打开HTML文档中的小程序。

请参阅我附加到此问题的小程序和HTML代码。

有人知道为什么它不起作用吗?我还尝试在HTML代码中使用MemoSaver.class加上双引号和单引号,并用\,\和/编写完整的路径名作为文件夹分隔符:似乎不合适。    我非常感谢您会提出所有建议。

      Raoul Bertorello

这是applet代码(从GUI解决方案重用)...:

public class MemoSaver extends JApplet implements ActionListener
{
public static final int WIDTH = 600;
public static final int HEIGHT = 300;
public static final int LINES = 10;
public static final int CHAR_PER_LINE = 40;

private JTextArea theText;
private String memo1 = "No Memo 1.";
private String memo2 = "No Memo 2.";

public void init( )
{
    setSize(WIDTH, HEIGHT);
    // addWindowListener(new WindowDestroyer( ));
    // setTitle("Memo Saver");
    Container contentPane = getContentPane( );
    contentPane.setLayout(new BorderLayout( ));

    JPanel buttonPanel = new JPanel( );
    buttonPanel.setBackground(Color.WHITE);
    buttonPanel.setLayout(new FlowLayout( ));

    JButton memo1Button = new JButton("Save Memo 1");
    memo1Button.addActionListener(this);
    buttonPanel.add(memo1Button);

    JButton memo2Button = new JButton("Save Memo 2");
    memo2Button.addActionListener(this);
    buttonPanel.add(memo2Button);

    JButton clearButton = new JButton("Clear");
    clearButton.addActionListener(this);
    buttonPanel.add(clearButton);

    JButton get1Button = new JButton("Get Memo 1");
    get1Button.addActionListener(this);
    buttonPanel.add(get1Button);

    JButton get2Button = new JButton("Get Memo 2");
    get2Button.addActionListener(this);
    buttonPanel.add(get2Button);
    contentPane.add(buttonPanel, BorderLayout.SOUTH);

    JPanel textPanel = new JPanel( );
    textPanel.setBackground(Color.BLUE);

    theText = new JTextArea(LINES, CHAR_PER_LINE);
    theText.setBackground(Color.WHITE);
    textPanel.add(theText);
    contentPane.add(textPanel, BorderLayout.CENTER);
}

public void actionPerformed(ActionEvent e)
{
    String actionCommand = e.getActionCommand( );
    if (actionCommand.equals("Save Memo 1"))
        memo1 = theText.getText( );
    else if (actionCommand.equals("Save Memo 2"))
        memo2 = theText.getText( );
    else if (actionCommand.equals("Clear"))
        theText.setText("");
    else if (actionCommand.equals("Get Memo 1"))
        theText.setText(memo1);
    else if (actionCommand.equals("Get Memo 2"))
        theText.setText(memo2);
    else
        theText.setText("Error in memo interface");
}
/**
public static void main(String[] args)
{
    MemoSaver guiMemo = new MemoSaver( );
    guiMemo.setVisible(true);
}
*/
}

...这是HTML代码:

<html>
<head>
    <title>
        Budget Help
    </title>
</head>

<body>
    <h1>
        The Budget Help Home Page
    <br>
        Helpful Hints for a Balanced Budget 
    </h1>

    <h2>
        Pay off your credit cards every month.
    </h2>

    <h2>
        Do not spend more than you earn.
    </h2>

    <h2>
        Here is an adder to help you plan your budget:
    </h2>
        <object code="MemoSaver.class" width=400 height=200>
        </object>

    <br><br>
</body>

</html>

0 个答案:

没有答案