資源簡介
用Java語言實現野人過河,有界面,可以設置野人和傳教士個數
代碼片段和文件信息
import?java.awt.BorderLayout;
import?java.awt.Color;
import?java.awt.Component;
import?java.awt.EventQueue;
import?java.awt.GridLayout;
import?java.awt.event.ActionEvent;
import?java.awt.event.ActionListener;
import?java.io.ByteArrayInputStream;
import?java.io.ByteArrayOutputStream;
import?java.io.objectInputStream;
import?java.io.objectOutputStream;
import?java.io.Serializable;
import?java.util.ArrayList;
import?java.util.Collection;
import?java.util.Collections;
import?java.util.HashSet;
import?java.util.Iterator;
import?java.util.Stack;
import?java.util.List;
import?javax.swing.Box;
import?javax.swing.ImageIcon;
import?javax.swing.JButton;
import?javax.swing.Jframe;
import?javax.swing.JLabel;
import?javax.swing.JPanel;
import?javax.swing.JTextField;
import?javax.swing.UIManager;
import?javax.swing.border.EmptyBorder;
public?class?chuan?extends?Jframe{
private?JPanel?contentPane;
private?JPanel?panelS;//上方的最底層
private?JPanel?panelX;//下方的最底層
private?JPanel?panelL;//上方左岸底層
private?JPanel?panelR;//上方右岸底層
private?JLabel?labelL;//上方左岸漢字
private?JPanel?panelLP;//上方左岸人
private?JPanel?panelH;//上方河
private?JLabel?labelover;
private?JLabel?labelH;//漢字河
private?JLabel?labelR;//上方右岸漢字
private?JLabel?labelNull;
private?JTextField?fieldC;//傳教士個數
private?JTextField?fieldY;//野人個數
private?JPanel?panelRP;//上方右岸人
private?JLabel?labelC;//下方傳教士
private?JLabel?labelY;//下方野人
private?JLabel?labelBoat;
private?JPanel?panelSRC;//下方輸入傳教士個數
private?JPanel?panelSRY;
private?JButton?chongshe;//重設
private?JButton?next;//下一步
private?JButton?sure;//確定
private?int?cNum;//傳教士個數
private?int?yNum;//人個數
????private?JLabel?Imagelabel[];
????private?String?stepEach[];
????private?Box?hboxlhboxr;
????private?int?stepAll;//總的步數
????private?int?count;
static?final?object?MISSIONARY?=?“m“?//?Simple?representation
????CANNIBAL???=?“c“?//?of?objects
????BOAT???????=?“v“;?//?in?the?puzzle.
private?int?boat_max_load
boat_min_load?=?1;?//?Shouldn‘t?be?any?other?value.
private?RiverScene?firstScene
???finalScene;
public?class?SolutionNotFoundException?extends?RuntimeException?{?}
public?chuan(){
settitle(“野人過河問題“);
????????setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
????????setBounds(100?100?409?331);
????????contentPane?=?new?JPanel();
????????contentPane.setBorder(new?EmptyBorder(5?5?5?5));
????????contentPane.setLayout(new?BorderLayout(0?0));
????????contentPane.setBackground(Color.green);
????????setContentPane(contentPane);
????????panelS=new?JPanel();
????????panelX=new?JPanel();
????????panelL=new?JPanel();
????????panelR=new?JPanel();
????????panelLP=new?JPanel();
????????panelH=new?JPanel();
????????panelH.setLayout(new?BorderLayout());
????????panelRP=new?JPanel();
????????panelSRC=new?JPanel();
????????panelSRY=new?JPanel();
????????labelover=new?JLabel(“運行結束“);
????????labelL=new?JLabel(“?????????????“);
????????labelR=new?JLabel(“?????????????“);
- 上一篇:javamail jar包
- 下一篇:動物識別Java實現含界面
評論
共有 條評論