国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

applet顯示框架代碼

2019-11-18 11:20:02
字體:
來源:轉載
供稿:網友

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等軟件中直接執行.








發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 肇源县| 吉安县| 舒城县| 香港| 郑州市| 安岳县| 通城县| 乌恰县| 桐梓县| 修武县| 柳江县| 贵定县| 南召县| 陕西省| 东源县| 富川| 玛多县| 台南市| 佛学| 常德市| 无极县| 买车| 贺兰县| 葵青区| 左贡县| 论坛| 普宁市| 苍梧县| 塔河县| 翁源县| 双流县| 嘉定区| 通榆县| 建阳市| 桐乡市| 肥乡县| 民乐县| 新宾| 米林县| 涪陵区| 黄冈市|