WEB开发网
开发学院WEB开发Jsp applet显示框架代码 阅读

applet显示框架代码

 2008-01-05 18:49:56 来源:WEB开发网   
核心提示:package csdn.net.shao;import javax.swing.*;import java.awt.event.*;import java.awt.*;import java.applet.*;/***全代码抄录java编程思想加入了2个函数适应不同的显示组件*/public class FrameW

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等软件中直接执行.







Tags:applet 显示 框架

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接