-
Notifications
You must be signed in to change notification settings - Fork 0
/
stopButton.java
139 lines (121 loc) · 5.62 KB
/
stopButton.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package Project;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class stopButton {
public static void main(String[] args) {
//创建一个界面
JFrame frame = new JFrame("stopButton");
frame.setSize(400, 200);
JPanel jp = new JPanel();
//创建停止按键
JButton stopButton = new JButton("Stop Button");
//停止按键所执行的方法
//进行输赢判断
stopButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//创建输赢判断界面
JFrame frameJudge = new JFrame("Winning or Losing");
frameJudge.setSize(400, 200);
JPanel jpJudge = new JPanel();
JLabel labelWin = new JLabel();
JLabel labelLose = new JLabel();
//输赢判断部分
InputStreamReader inputStream = new InputStreamReader(System.in);
BufferedReader buffer = new BufferedReader(inputStream);
ArrayList<String> result = new ArrayList<>();
newSudoku: for (int i = 1; i <= 1; i++) {
int[][] sudoku = new int[9][9];
//将数独输入二维数组
for (int line = 0; line < 9; line++) {
String[] intStr = new String[0];
try {
intStr = buffer.readLine().split(" ");
} catch (IOException ioException) {
ioException.printStackTrace();
}
for (int column = 0; column < 9; column++) {
sudoku[line][column] = Integer.parseInt(intStr[column]);
}
}
//判断是否含0,0代表没有填写
for (int line = 0; line < 9; line++) {
for (int column = 0; column < 9; column++) {
if (sudoku[line][column] == 0) {
result.add("Wrong");
continue newSudoku;
}
}
}
//判断每一行是否符合标准
for (int line = 0; line < 9; line++) {
int[] arrLine = new int[9];
for (int column = 0; column < 9; column++) {
if (arrLine[sudoku[line][column] - 1] > 0) {
result.add("Wrong");
continue newSudoku;
} else {
arrLine[sudoku[line][column] - 1] = 1;
}
}
}
//判断每一列是否符合标准
for (int column = 0; column < 9; column++) {
int[] arrCol = new int[9];
for (int line = 0; line < 9; line++) {
if (arrCol[sudoku[line][column] - 1] > 0) {
result.add("Wrong");
continue newSudoku;
} else {
arrCol[sudoku[line][column] - 1] = 1;
}
}
}
//判断每一方块是否符合标准
for (int line = 0; line < 9; line += 3) {
for (int column = 0; column < 9; column += 3) {
int[] arrSquare = new int[9];
for (int squareLine = line; squareLine < line + 3; squareLine++) {
for (int squareCol = column; squareCol < column + 3; squareCol++) {
if (arrSquare[sudoku[squareLine][squareCol] - 1] > 0) {
result.add("Wrong");
continue newSudoku;
} else {
arrSquare[sudoku[squareLine][squareCol] - 1] = 1;
}
}
}
}
}
result.add("Right");
}
for (String str : result){
if(str.equals("Right")){
jpJudge.add(labelWin);
labelWin.setText("You Win");
labelWin.setFont(new Font("微软雅黑",0,40));
}
if(str.equals("Wrong")){
jpJudge.add(labelLose);
labelLose.setText("You Lose");
labelLose.setFont(new Font("微软雅黑",0,40));
}
}
frameJudge.add(jpJudge);
frameJudge.setVisible(true);
frameJudge.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
});
jp.add(stopButton);
frame.add(jp);
frame.setBounds(300, 200, 600, 300);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}