2016-02-12 25 views
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); 
    } 
} 
+0

什么是您的具体问题? –

+0

我需要帮助提示用户输入并显示我的行和列的对话框 – JimJam

+0

您已经尝试过什么? –

回答

0

你试过

columns = Integer.parseInt(JOptionPane.showInputDialog("Enter number of columns")); 
+0

是的,谢谢,这是我所做的和工作。 – JimJam

+0

那你能接受答案吗? –