为什么我的java小程序只是显示我的回退消息?

zmeyuzjn  于 2021-07-12  发布在  Java
关注(0)|答案(0)|浏览(107)

我的javaapplet只是在所有浏览器中显示回退消息。我有:
谷歌浏览器
microsoft边缘
internet explorer
以下是小程序的代码:

import javax.swing.*;
import java.awt.event.*;

public class LottoApplet extends JApplet implements ActionListener
{
    // Components
    ClassLoader ldr = this.getClass().getClassLoader();
    java.net.URL iconURL = ldr.getResource( "Lotto.png" );
    ImageIcon icon  = new ImageIcon( iconURL );
    JLabel img      = new JLabel( icon );
    JTextField txt  = new JTextField( "", 18 );
    JButton btn     = new JButton( "Get My Lucky Numbers" );
    JPanel pnl      = new JPanel();

    // Applet entry point
    public void init()
    {
        pnl.add( img );
        pnl.add( txt );
        pnl.add( btn );
        btn.addActionListener( this );
        String bgStr = getParameter( "BgColor" );
        int bgHex = Integer.parseInt( bgStr, 16 );
        pnl.setBackground( new java.awt.Color( bgHex ));
        add( pnl );
    }

    // Event-handler
    public void actionPerformed( ActionEvent event )
    {
        if( event.getSource() == btn )
        {
            // Declare working variables.
            int[] nums = new int[60];
            String str = "";

            // Fill elements 1-59 with integers 1-59.
            for( int i = 1; i < 60; i++ ) { nums[i] = i; }

            // Shuffle the values in elements 1-59.
            for( int i = 1; i < 60; i++ )
            {
                int r = (int) Math.ceil( 59 * Math.random() ) + 1;
                int temp=nums[i]; nums[i]=nums[r]; nums[r]=temp;
            }

            // Display the values in elements one to six.
            for ( int i = 1; i < 7; i++ )
            {
                str += "  " + Integer.toString( nums[ i ]) + "  ";

            }
            txt.setText( str );
        }
    }
}

这是网页的代码:

<!DOCTYPE html>
<html>
	<head>
		<meta charset = "UTF-8">
		<title>Lotto Applet Host</title>
	</head>
	<body>
		<object type = "application/x-java-applet" width = "260" height = "160">
			<param name = "code" value = "LottoApplet.class">
			<param name = "BgColor" value = "FFFF00">
			<param name = "archive" value = "LottoApplet.jar">
			[ Java Applet - Requires Java Plugin ]
		</object>
	</body>
</html>

我已经从“java的简单步骤”得到了代码,所以它应该是可靠的。只是因为我的浏览器不支持它吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题