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

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

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

  1. import javax.swing.*;
  2. import java.awt.event.*;
  3. public class LottoApplet extends JApplet implements ActionListener
  4. {
  5. // Components
  6. ClassLoader ldr = this.getClass().getClassLoader();
  7. java.net.URL iconURL = ldr.getResource( "Lotto.png" );
  8. ImageIcon icon = new ImageIcon( iconURL );
  9. JLabel img = new JLabel( icon );
  10. JTextField txt = new JTextField( "", 18 );
  11. JButton btn = new JButton( "Get My Lucky Numbers" );
  12. JPanel pnl = new JPanel();
  13. // Applet entry point
  14. public void init()
  15. {
  16. pnl.add( img );
  17. pnl.add( txt );
  18. pnl.add( btn );
  19. btn.addActionListener( this );
  20. String bgStr = getParameter( "BgColor" );
  21. int bgHex = Integer.parseInt( bgStr, 16 );
  22. pnl.setBackground( new java.awt.Color( bgHex ));
  23. add( pnl );
  24. }
  25. // Event-handler
  26. public void actionPerformed( ActionEvent event )
  27. {
  28. if( event.getSource() == btn )
  29. {
  30. // Declare working variables.
  31. int[] nums = new int[60];
  32. String str = "";
  33. // Fill elements 1-59 with integers 1-59.
  34. for( int i = 1; i < 60; i++ ) { nums[i] = i; }
  35. // Shuffle the values in elements 1-59.
  36. for( int i = 1; i < 60; i++ )
  37. {
  38. int r = (int) Math.ceil( 59 * Math.random() ) + 1;
  39. int temp=nums[i]; nums[i]=nums[r]; nums[r]=temp;
  40. }
  41. // Display the values in elements one to six.
  42. for ( int i = 1; i < 7; i++ )
  43. {
  44. str += " " + Integer.toString( nums[ i ]) + " ";
  45. }
  46. txt.setText( str );
  47. }
  48. }
  49. }

这是网页的代码:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset = "UTF-8">
  5. <title>Lotto Applet Host</title>
  6. </head>
  7. <body>
  8. <object type = "application/x-java-applet" width = "260" height = "160">
  9. <param name = "code" value = "LottoApplet.class">
  10. <param name = "BgColor" value = "FFFF00">
  11. <param name = "archive" value = "LottoApplet.jar">
  12. [ Java Applet - Requires Java Plugin ]
  13. </object>
  14. </body>
  15. </html>

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

暂无答案!

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

相关问题