⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mymainframe.java

📁 JAVA编的五子棋游戏
💻 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 + -