码迷,mamicode.com
首页 > 移动开发 > 详细

让applet像应用程序一样运行

时间:2015-10-09 00:38:56      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:

尽管java applet不再流行,但让java程序以多种方式运行会更有意思。

技术分享

DisplayLabel.html 代码

<!DOCTYPE HTML>
<html>
<head>
    <title>Java Applet Demo</title>
    </head>
    <body>
    <applet
        code="DisplayLabel.class"
        width=250
        height=50>
    </applet>
    </body>
</html>

  

 

DisplayLabel.java 代码

import javax.swing.*;

public class DisplayLabel extends JApplet{
    public DisplayLabel(){
        add(new JLabel("Hello World!", JLabel.CENTER));
    }

    public static void main(String[] args){
        // Create a frame
        JFrame frame = new JFrame("Applet is in the frame");

        // Create an instance of the applet
        DisplayLabel applet = new DisplayLabel();

        // Add the applet to the frame
        frame.add(applet);

        // Display the frame
        frame.setSize(300,100);
        frame.setLocationRelativeTo(null); // Center the frame
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
}

  

 

让applet像应用程序一样运行

标签:

原文地址:http://www.cnblogs.com/7explore-share/p/4862745.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!