Java applet does not display anything

前端 未结 5 683
无人及你
无人及你 2021-01-19 03:06

Does anyone know why my Java applet does not display anything?

This is my first Java applet so I am new to creating one. I researched this problem and haven\'t found

相关标签:
5条回答
  • 2021-01-19 03:39

    Put this into your code before any line in the paint

    super.paint(screen);
    
    0 讨论(0)
  • 2021-01-19 03:45

    Both the applet and the HTML page appear correct, so its likely the problem is a result of a misconfiguration on either the server end, or the status of the Java plugin for your browser. I'd need to know more about your situation to completely diagnose it. [I tested this in Google Chrome using the 1.7.0.11 plugin, and it worked as expected]

    On the server end, make sure you have the class file and the HTML file deployed to the same location on the server (or a local directory if you are loading it that way)

    In addition, it is possible that the browser you are using either does not have Java installed or has an incompatible version of Java. This is the next thing I would check. Common problems include compiling the applet with against the 1.7 API, but trying to load it into a browser with an older Java plugin.

    0 讨论(0)
  • 2021-01-19 03:49

    Here is a screenshot of this working code. Except shortened from the applet height specified.

    JavaRocksApplet

    So, as Neet noted in a comment. 'It works here.'

    import java.applet.Applet;
    import java.awt.Graphics;
    import java.awt.Font;
    import java.awt.Color;
    
    /*
    <applet code = "JavaRocksApplet.class" width = 400 height = 200> </applet>
    */
    public class JavaRocksApplet extends Applet
    {
        public void paint( Graphics screen )
        {
            Font f = new Font( "TimesRoman", Font.ITALIC, 36 );
            screen.setFont( f );
            Color c = new Color( 40, 80, 120 );
            screen.setColor( c );
            screen.drawString( "Java Rocks!!", 100, 60 );
        }
    }
    

    Likely more details on the actual cause of the problem can be found by viewing the console. See How do I enable and view the Java Console?

    0 讨论(0)
  • 2021-01-19 03:56

    Typically, you define an init() method and add initialize some GUI components inside of it. I wouldn't override paint(). I'm not sure what exactly that would do.

    0 讨论(0)
  • 2021-01-19 04:04

    I had the same issue with my applet. Added comment

    <applet code = "JavaRocksApplet.class" width = 400 height = 200> </applet>
    

    in JavaRocksApplet worked for me.

    0 讨论(0)
提交回复
热议问题