gpt4 book ai didi

java - JApplet 内的 JFrame

转载 作者:行者123 更新时间:2023-11-30 05:01:05 25 4
gpt4 key购买 nike

我有一个基于JFrame的程序。现在我想在网页上运行它。看来我必须使用 JApplet 。我应该怎么办 ?我可以有 JApplet 窗口和许多 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;}
}

最佳答案

I have program which based on JFrame.

使用 Java Web Start 从链接启动它.

关于java - JApplet 内的 JFrame,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6703943/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com