0
我想提示我的行和列的用户输入我的一个对话框,棋盘(-J选项的东西吗?)在我的棋盘上提示用户输入行和列? (Java编程)
//显示8×8格的红色和黑色矩形
import javax.swing.*; // For JFrame and JPanel
import java.awt.*; // For Color, Container, and GridLayout
public class checkerboard{
public static void main(String[] args){
JFrame theGUI = new JFrame();
theGUI.setTitle("Checkerboard");
theGUI.setSize(300,300);
theGUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container pane = theGUI.getContentPane();
pane.setLayout(new GridLayout(8,8));
Color color1 = Color.black;
Color color2 = Color.red;
for (int i = 1; i<= 64; i++){
JPanel panel = new JPanel();
// Alternate colors on a row
if (i % 2 == 0)
panel.setBackground(color1);
else
panel.setBackground(color2);
pane.add(panel);
// At the end of a row, start next row on the other color
if (i % 8 == 0){
Color temp = color1;
color1 = color2;
color2 = temp;
}
}
theGUI.setVisible(true);
}
}
什么是您的具体问题? –
我需要帮助提示用户输入并显示我的行和列的对话框 – JimJam
您已经尝试过什么? –