applet显示框架代码

王朝other·作者佚名  2008-05-31
窄屏简体版  字體: |||超大  

package csdn.net.shao;

import Javax.swing.*;

import java.awt.event.*;

import java.awt.*;

import java.applet.*;

/**

*全代码抄录java编程思想加入了2个函数适应不同的显示组件

*/

public class FrameWork

{

//创建一个class名称的字符串

public static String title(Object o)

{

String t=o.getClass().toString();

//删除tostring()得到的class 的字符

if(t.indexOf("class")!=-1)

t=t.substring(6);

return t;

}

public static void setupClosing(JFrame frame)

{

frame.addWindowListener(new WindowAdapter()

{

public void windowClosing(WindowEvent e)

{

System.exit(0);

}});

}

public static void run(JFrame frame,int width,int height)

{

setupClosing(frame);

frame.setSize(width,height);

frame.setVisible(true);

}

public static void run(JApplet applet,int width,int height)

{

JFrame frame=new JFrame(title(applet));

setupClosing(frame);

frame.getContentPane().add(applet);

frame.setSize(width,height);

applet.init();

applet.start();

frame.setVisible(true);

}

public static void run(Applet applet,int width,int height)

{

JFrame frame=new JFrame(title(applet));

setupClosing(frame);

frame.getContentPane().add(applet);

frame.setSize(width,height);

applet.init();

applet.start();

frame.setVisible(true);

}

public static void run(JPanel panel,int width,int height)

{

JFrame frame=new JFrame(title(panel));

setupClosing(frame);

frame.getContentPane().add(panel);

frame.setSize(width,height);

frame.setVisible(true);

}

public static void run(Panel panel,int width,int height)

{

JFrame frame=new JFrame(title(panel));

setupClosing(frame);

frame.getContentPane().add(panel);

frame.setSize(width,height);

frame.setVisible(true);

}

}

应用时,比如说有一个public class A extends JApplet

那么先 import csdn.net.shao.FrameWork;

在你原先的applet代码的最后一个}前面加上

public static void main(String[] args)

{

FrameWork.run(new A(),200,50);

}

即可直接将applet frame panel japplet jpanel在editplus,ultraledit ,jcreator等软件中直接执行.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航