📄 horsetravel1.java
字号:
int swich1=boardPositions[i]; if(m==64)m=63; int swich2=boardPositions[m]; try{ Thread.sleep(250); SetBackColor(swich1,Color.RED); Thread.sleep(300); SetBackColor(swich1,Color.CYAN); SetBackColor(swich2,Color.RED); Thread.sleep(250); SetBackColor(swich1,Color.PINK); }catch(InterruptedException ex){ System.err.println(ex.toString()); } } String ss=""; int ll=1; for(int k=3;k<=10;k++){ for(int f=3;f<=10;f++){ ss=ss+a[k][f]+"\t"; if(ll%8==0)ss=ss+"\n"; ll++; } } jTextArea1.setText(ss); int row=-1,line=-1; int b=bb+2; int c=cc+2; for(int i=3;i<=10;i++) for(int j=3;j<=10;j++) if(a[i][j]==64){row=i;line=j;} if((row-2==b&&line-1==c)||(row-2==b&&line+1==c) ||(row+2==b&&line-1==c)||(row+2==b&&line+1==c) ||(row-1==b&&line-2==c)||(row-1==b&&line+2==c) ||(row+1==b&&line+2==c)||(row+1==b&&line-2==c)){ jTextField3.setText("周游完所有节点,且能回到出发点!"); }else{ jTextField3.setText("周游完所有节点,但未能回到出发点!"); } w=1; k[0]=k[1]=0; jTextField1.setText("1"); jTextField2.setText("1");} private void jTextField1KeyTyped(java.awt.event.KeyEvent evt) { String count=jTextField1.getText().trim();//文本框 for (int i = 0; i < count.length(); i++) { //循环判断是不是数字 if(!Character.isDigit((count.charAt(i)))){ JOptionPane.showMessageDialog(this,"输入不合法,请输入整数!"); jTextField1.setText(""); return; } } } /** Creates new form horseTravel */ public horseTravel1() { initComponents(); this.setVisible(true); this.setSize(800, 750); this.setLocation(300, 0); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jTextField1 = new javax.swing.JTextField(); jTextField2 = new javax.swing.JTextField(); jButton65 = new javax.swing.JButton(); jButton66 = new javax.swing.JButton(); jButton67 = new javax.swing.JButton(); jButton68 = new javax.swing.JButton(); jPanel2 = new javax.swing.JPanel(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jButton4 = new javax.swing.JButton(); jButton5 = new javax.swing.JButton(); jButton6 = new javax.swing.JButton(); jButton7 = new javax.swing.JButton(); jButton8 = new javax.swing.JButton(); jButton9 = new javax.swing.JButton(); jButton10 = new javax.swing.JButton(); jButton11 = new javax.swing.JButton(); jButton12 = new javax.swing.JButton(); jButton13 = new javax.swing.JButton(); jButton14 = new javax.swing.JButton(); jButton15 = new javax.swing.JButton(); jButton16 = new javax.swing.JButton(); jButton17 = new javax.swing.JButton(); jButton18 = new javax.swing.JButton(); jButton19 = new javax.swing.JButton(); jButton20 = new javax.swing.JButton(); jButton21 = new javax.swing.JButton(); jButton22 = new javax.swing.JButton(); jButton23 = new javax.swing.JButton(); jButton24 = new javax.swing.JButton(); jButton25 = new javax.swing.JButton(); jButton26 = new javax.swing.JButton(); jButton27 = new javax.swing.JButton(); jButton28 = new javax.swing.JButton(); jButton29 = new javax.swing.JButton(); jButton30 = new javax.swing.JButton(); jButton31 = new javax.swing.JButton(); jButton32 = new javax.swing.JButton(); jButton33 = new javax.swing.JButton(); jButton34 = new javax.swing.JButton(); jButton35 = new javax.swing.JButton(); jButton36 = new javax.swing.JButton(); jButton37 = new javax.swing.JButton(); jButton38 = new javax.swing.JButton(); jButton39 = new javax.swing.JButton(); jButton40 = new javax.swing.JButton(); jButton41 = new javax.swing.JButton(); jButton42 = new javax.swing.JButton(); jButton43 = new javax.swing.JButton(); jButton44 = new javax.swing.JButton(); jButton45 = new javax.swing.JButton(); jButton46 = new javax.swing.JButton(); jButton47 = new javax.swing.JButton(); jButton48 = new javax.swing.JButton(); jButton49 = new javax.swing.JButton(); jButton50 = new javax.swing.JButton(); jButton51 = new javax.swing.JButton(); jButton52 = new javax.swing.JButton(); jButton53 = new javax.swing.JButton(); jButton54 = new javax.swing.JButton(); jButton55 = new javax.swing.JButton(); jButton56 = new javax.swing.JButton(); jButton57 = new javax.swing.JButton(); jButton58 = new javax.swing.JButton(); jButton59 = new javax.swing.JButton(); jButton60 = new javax.swing.JButton(); jButton61 = new javax.swing.JButton(); jButton62 = new javax.swing.JButton(); jButton63 = new javax.swing.JButton(); jButton64 = new javax.swing.JButton(); jButton1 = new javax.swing.JButton(); jLabel6 = new javax.swing.JLabel(); jPanel3 = new javax.swing.JPanel(); jScrollPane1 = new javax.swing.JScrollPane(); jTextArea1 = new javax.swing.JTextArea(); jLabel4 = new javax.swing.JLabel(); jTextField3 = new javax.swing.JTextField(); jLabel5 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("马周游"); jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("操作区域")); jLabel1.setText("输入行号(1-8):"); jLabel2.setText("输入列号(1-8):"); jTextField2.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent evt) { jTextField2KeyTyped(evt); } }); jButton65.setText("开始"); jButton65.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton65ActionPerformed(evt); } }); jButton66.setText("退出"); jButton66.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton66ActionPerformed(evt); } }); jButton67.setText("查看源代码"); jButton67.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton67ActionPerformed(evt); } }); jButton68.setText("查看实验报告"); jButton68.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton68ActionPerformed(evt); } }); org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup() .addContainerGap() .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false) .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup() .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false) .add(jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .add(jLabel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false) .add(jTextField2) .add(jTextField1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 110, Short.MAX_VALUE))) .add(jPanel1Layout.createSequentialGroup() .add(jButton65, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 83, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .add(jButton66, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 78, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))) .addContainerGap(20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .add(jPanel1Layout.createSequentialGroup() .add(70, 70, 70) .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false) .add(org.jdesktop.layout.GroupLayout.LEADING, jButton67, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .add(org.jdesktop.layout.GroupLayout.LEADING, jButton68, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap()) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jPanel1Layout.createSequentialGroup() .add(21, 21, 21) .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(jLabel1) .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .add(18, 18, 18) .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(jLabel2) .add(jTextField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .add(18, 18, 18) .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(jButton65, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 35, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(jButton66, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 34, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .add(27, 27, 27) .add(jButton67) .add(25, 25, 25) .add(jButton68) .addContainerGap(23, Short.MAX_VALUE)) ); jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("棋盘(动态演示区域)")); jButton2.setText("2"); jButton3.setText("3"); jButton4.setText("4"); jButton5.setText("5"); jButton6.setText("6"); jButton7.setText("7"); jButton8.setText("8"); jButton9.setText("9"); jButton10.setText("10"); jButton11.setText("11"); jButton12.setText("12"); jButton13.setText("13"); jButton14.setText("14"); jButton15.setText("15"); jButton16.setText("16");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -