📄 gameframe2.java
字号:
// 程序: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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -