2011-07-15 11 views
1

私はJFrameに基づいたプログラムを持っています。今私はウェブページ上でそれを実行したい。 JAppletを使わなければならないようです。私は何をすべきか ? JAppletウィンドウと多くのJFrameウィンドウを持つことができますか?それはWeb上で実行できますか?JAFlet内のJFrame

package Interface; 
import java.awt.FlowLayout;  
import javax.swing.JApplet; 
import javax.swing.JButton; 
import javax.swing.JFrame; 
import javax.swing.JLabel; 
import javax.swing.JMenu; 
import javax.swing.JMenuBar; 
import javax.swing.JMenuItem;  
import Interface.Menu.block;  

public class Menu extends JApplet { 
    static int rows=8; 
    static int cols=8; 
    MenuLabel menulabel ; 
    public enum block 
     {Ground,Wall,Ice,Trap,Box; 
     } 
    public static Start start; 

    @Override 

    public void init() { 
//  super("Menu");  
//  this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     this.setVisible(true); 
     this.setLayout(null); 
     this.setBounds(300, 100, 600,600); 
     menulabel= new MenuLabel(8,8); 
     add(menulabel); 
     Main.menu=this; 
     JMenuBar load=new JMenuBar(); 
     load.add(new Loadbutton()); 
     new JFrame().setVisible(true); 
     add(load); 

     Startbutton Start = new Startbutton(this); 
     Loadbutton Load =new Loadbutton(); 
     Editbutton Edit = new Editbutton(); 
     add(Start); 
     add(Load); 
     add(Edit); 

     paint(this.getGraphics()); 
    }  
}; 
class MenuLabel extends JLabel implements Cloneable 
{ 
    int rows,cols; 
    public MenuMap [][] menumap; 
    MenuLabel(int rows,int cols) 
    { 
     Menu.rows=rows; 
     Menu.cols=cols; 
     this.rows=rows; 
     this.cols=cols; 
     setBounds(140,100,580,580); 
     menumap=new MenuMap[rows][cols]; 
     add(new JButton("sds")); 
     for(int i=0;i<rows;i++) 
      for(int j=0;j<cols;j++) 
      { 
       menumap[i][j]=new MenuMap(j*50,i*50,block.Ground); 
       menumap[i][j].setBounds(j*50, i*50, 50, 50); 
       add(menumap[i][j]); 
      } 
    } 
    void changeCell(int x ,int y,Menu.block b) 
    { 
     removeAll();    
     menumap[x][y]=new MenuMap(menumap[x][y].getX(), menumap[x][y].getY(),b); 
     for(int i=0;i<Menu.rows;i++) 
      for(int j=0;j<Menu.cols;j++) 
       add(menumap[i][j]); 
    } 
    public MenuLabel(MenuLabel another) 
    { 
     this.cols=another.cols; 
     this.rows=another.rows; 
     setBounds(140,100,580,580); 
     menumap=new MenuMap[rows][cols]; 
     add(new JButton("sds")); 
     for(int i=0;i<rows;i++) 
      for(int j=0;j<cols;j++) 
      { 
       menumap[i][j]=new MenuMap(j*50,i*50, 
       Menu.block.valueOf(another.menumap[i][j].getText())); 
       menumap[i][j].setBounds(j*50, i*50, 50, 50); 
       add(menumap[i][j]); 
      } 
    } 
    MenuMap getCell(int i, int j) 
    { 
     return menumap[i][j]; 
    } 
    public int getRows(){return this.rows;} 
    public int getCols(){return this.cols;}  
} 
+0

BTW 'setLayout(null);'しないでください。レイアウトを使用する。 'setBounds(300、100、600,600);'埋め込みアプレットでは動作しません。 –

答えて

0

あなたのコードに潜ることなく、答えははいです。 JFrameを作成し、そのサイズ(および位置)を設定して表示させることができます。フレームはブラウザのウィンドウとは別に表示されます。唯一の疑問はなぜですか?ユーザーについて考える:Webアプリケーションがポップアップウィンドウの数を作成すると非常に不便です。

+0

jframeの代わりにjpanelを使い、可視性を変更したり、それらを追加/削除したりする方がよいと思います。どう思いますか。 –

2

私はJFrameに基づいたプログラムを持っています。

Java Web Startを使用してリンクから起動します。

+0

hmmmm +1 – mKorbel

+0

@mKorbel:それを試してみるには、[JWS APIの例](http://pscode.org/jws/api.html)の小さなサンプルをダウンロードしてください。ページ。それぞれにはビルドファイルがあり、簡単に起動して実行できます。彼らはほとんどほとんど些細ですが、うまくいけば有益です。 :) –