Java JFrame-in-JApplet
我有一个基于JFrame的程序。现在我想在网页上运行它。看来我必须用JApplet。我该怎么办?我可以有JApplet窗口和许多JFrame窗口,并且可以在web上运行吗Java JFrame-in-JApplet,java,jframe,japplet,Java,Jframe,Japplet,我有一个基于JFrame的程序。现在我想在网页上运行它。看来我必须用JApplet。我该怎么办?我可以有JApplet窗口和许多JFrame窗口,并且可以在web上运行吗 package Interface; import java.awt.FlowLayout; import javax.swing.JApplet; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; imp
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;}
}
包接口;
导入java.awt.FlowLayout;
导入javax.swing.JApplet;
导入javax.swing.JButton;
导入javax.swing.JFrame;
导入javax.swing.JLabel;
导入javax.swing.JMenu;
导入javax.swing.JMenuBar;
导入javax.swing.JMenuItem;
导入Interface.Menu.block;
公共类菜单扩展了JApplet{
静态int行=8;
静态int cols=8;
梅努拉贝尔;
公共枚举块
{地面、墙壁、冰、陷阱、盒子;
}
公共静态启动;
@凌驾
公共void init(){
//超级(“菜单”);
//此.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
此.setVisible(true);
此.setLayout(null);
这个.立根(300100600600);
menulabel=新menulabel(8,8);
添加(menulabel);
Main.menu=this;
JMenuBar load=新JMenuBar();
添加(新的Loadbutton());
新建JFrame().setVisible(true);
添加(加载);
Startbutton Start=新的Startbutton(此);
Loadbutton Load=新建Loadbutton();
Editbutton Edit=新建Editbutton();
添加(开始);
添加(加载);
添加(编辑);
绘制(this.getGraphics());
}
};
类MenuLabel扩展了JLabel,实现了可克隆性
{
int行,cols;
公共菜单映射[][]菜单映射;
MenuLabel(整数行,整数列)
{
菜单行=行;
Menu.cols=cols;
这个。行=行;
this.cols=cols;
立根(140100580);
menumap=新的menumap[行][cols];
添加(新按钮(“sds”);
对于(inti=0;i,如果不跳转到您的代码,答案是肯定的,您可以。
您可以创建JFrame,设置其大小(和位置),然后使其可见。您的框架将与浏览器窗口分开显示。唯一的问题是为什么?想想用户:当web应用程序创建大量弹出窗口时,这非常不方便
我有一个基于JFrame的程序
使用链接启动它。@mKorbel:当您有时间尝试它时,请下载我在页面上的一些小示例。每个示例都有一个构建文件,可以轻松启动和运行。它们大多很简单,但希望具有指导意义。)我认为最好使用jpanel而不是jframe,并更改它们的可见性或添加/删除它们。您认为如何。顺便说一句,setLayout(null);
不要这样做。使用布局。setBounds(300100600600);
对嵌入式小程序不起作用。