gameframe2.java
来自「用JAVA进行游戏设计的图书 可以了解JAVA的运行状态 和编写游戏的特点」· Java 代码 · 共 80 行
JAVA
80 行
// 程序:AWT元件事件处理
// 范例文件:GameFrame2.java
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.util.*;
class GameFrame2 extends Frame
implements WindowListener,ActionListener
{
Panel main,top,center;
Menu MU;
MenuBar MB;
MenuItem MI1,MI2;
InfoDialog DW;
public GameFrame2(String Title,int AppletWidth,int AppletHeight,
Applet Game)
{
super(Title);
main = new Panel();
top = new Panel();
center = new Panel();
DW = new InfoDialog(this,"基本信息",true);
addWindowListener(this);
main.setLayout(new BorderLayout());
center.setLayout(new CardLayout());
main.add(top,BorderLayout.NORTH);
main.add(center,BorderLayout.CENTER);
top.add(new Button("按钮1"));
top.add(new Button("按钮2"));
center.add(Game,"main");
add(main);
MB = new MenuBar();
MU = new Menu("选项");
MU.add(MI1 = new MenuItem("基本信息"));
MU.add(MI2 = new MenuItem("离开游戏"));
MB.add(MU);
setMenuBar(MB);
MI1.addActionListener(this);
MI2.addActionListener(this);
setResizable(false);
setSize(AppletWidth,AppletHeight + 100);
show();
}
public void windowClosing(WindowEvent e)
{
dispose();
}
public void windowOpened(WindowEvent e){}
public void windowClosed(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowActivated(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == MI1)
{
DW.show();
}
else if(e.getSource() == MI2)
dispose();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?