?? mymainframe.java
字號:
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Dimension;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import java.awt.event.KeyEvent;
import javax.swing.JMenuItem;
import javax.swing.JRadioButtonMenuItem;
import java.awt.GridBagLayout;
import javax.swing.BorderFactory;
import javax.swing.border.EtchedBorder;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.ComponentOrientation;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.JToggleButton;
import javax.swing.JSplitPane;
public class myMainFrame extends JFrame {
JMenuBar bar=new JMenuBar( ); //創建JMenuBar對象
JMenu menu=new JMenu("游戲"); //創建JMenu對象
JMenuItem newgame=new JMenuItem("新開始游戲"); //創建JMenuItem對象
JMenuItem open=new JMenuItem("未實現");
JMenuItem close=new JMenuItem("未實現關閉");
JMenuItem quit=new JMenuItem("退出");
private mymainPanel mp=null;
private mymainPanel getMyPanel(){
return new mymainPanel();
}
public myMainFrame() {
super();
initialize();
}
private void initialize() {
this.setSize(600, 700);
// Container cp=this.getContentPane( ); //創建JFrame的容器對象
mp=getMyPanel();
this.setContentPane(mp);
// Container con=this.getContentPane();
// con.add(mp,"Center");
this.setTitle("五子棋");
//this.setJMenuBar(getMyMenuBar());
// this.setJMenuBar(getMyMenuBar());
//this.setResizable(false);
this.setName("outFrame");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//this.setTitle("Gongbang");
bar.setOpaque(true); //設置bar為不透明,若設置bar為透明,則在選擇菜單時
//會有殘影存留在JMenuBar上
setJMenuBar(bar); //加入bar到Jframe中
menu.add(newgame); //加入JMenuItem對象到menu中
menu.add(open);
menu.add(close);
menu.addSeparator( ); //在JMenu中加入一分隔線
menu.add(quit);
bar.add(menu); //將menu加載到bar上
newgame.addActionListener(new menuAction(mp)); //注冊JMenuItem對象給監聽者對象
open.addActionListener(new menuAction(mp));
close.addActionListener(new menuAction(mp));
quit.addActionListener(new menuAction(mp));
}
class menuAction implements ActionListener{
mymainPanel mp=null;
menuAction(mymainPanel mp){
super();
this.mp=mp;
}
public void actionPerformed(ActionEvent e){
String arg=e.getActionCommand();
// String arg=e.getSource();
if(arg.equals("退出")){
System.exit(0);
}
if(arg.equals("新開始游戲")){
mp.restart();
SwingUtilities.updateComponentTreeUI(mychess.thisGame);
}
}
}
} // @jve:decl-index=0:visual-constraint="16,7"
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -