checkbox.java

来自「扫雷系统:和平时的玩法差不多;设定难度」· Java 代码 · 共 88 行

JAVA
88
字号
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CheckBox extends JFrame{
   private Label field;
   private JRadioButton simpButton,middButton,hardButton;
   private ButtonGroup radioGroup;
   private int numOfMine;
   private int colum;
   private int row;
   public CheckBox()
   {
	   super("RadioButton");
	   Container container=getContentPane();
	   container.setLayout(new FlowLayout());
	   field=new Label("Choose the level");
	   container.add(field);
	   simpButton=new JRadioButton("初级",false);
	   container.add(simpButton);
	   middButton=new JRadioButton("中级",false);
	   container.add(middButton);
	   hardButton=new JRadioButton("高级",false);
	   container.add(hardButton);
	   radioGroup =new ButtonGroup();
	   radioGroup.add(simpButton);
	   radioGroup.add(middButton);
	   radioGroup.add(hardButton);
	   simpButton.addItemListener(new RadioButtonHandle());
	   middButton.addItemListener(new RadioButtonHandle());
	   hardButton.addItemListener(new RadioButtonHandle());
	   setSize(300,100);
	   setLocationRelativeTo(getParent());
	   setVisible(true);
	setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
	   
   }
   public int GetNum()
   {
	   return numOfMine;
   }
   public int GetRow()
   {
	   return row;
   }
   public int GetCol()
   {
	   return colum;
   }
   private class RadioButtonHandle implements ItemListener
   {
	  public RadioButtonHandle()
	  {
		  
	  }
	   public void itemStateChanged(ItemEvent event)
	   {
		 if((JRadioButton)event.getItem()==simpButton)
		 {
			 numOfMine=10;
			 row=10;
			 colum=10;
		 }
		 else if((JRadioButton)event.getItem()==middButton)
		 {
			 numOfMine=40;
			 row=16;
			 colum=16;
		 }
		 else if((JRadioButton)event.getItem()==hardButton)
		 {
			 numOfMine=99;
			 row=16;
			 colum=30;
		 }
		 else
		 {
			 numOfMine=16;
			 row=10;
			 colum=10;
	
		 }
		 MineGame game=new MineGame(numOfMine,row,colum);
		 
	   }
   }
	
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?