Post: Java Netbeans help
09-24-2014, 08:20 PM #1
HaZeYMan
Do a barrel roll!
(adsbygoogle = window.adsbygoogle || []).push({}); Goal: to make a sudoku grid using random numbers. And it has to be in a loop 1000 times

this is my code now what I'm stuck with.:

import java.util.Random;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class Main {


static JButton [][] myBoard;
static ImageIcon myicon;
public static void main(String[] args) {
JFrame myframe = new JFrame();
JPanel mypanel = new JPanel();
myframe.add(mypanel);
myframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mypanel.setLayout(null);

JLabel lbluserid = new JLabel();



lbluserid.setBounds(70,20,230,20);
mypanel.add(lbluserid);

JButton txtsquare;
Random r;
r = new Random(4);

myBoard = new JButton[8][8];
boolean redflag = true;

while (JOptionPane.showConfirmDialog(null,"Continue") == JOptionPane.YES_OPTION) {
mypanel = new JPanel();
mypanel.setLayout(null);
for (int i =1 ; i< 9; i++) {
for (int j = 1; j< 9 ; j++ ){
txtsquare = new JButton();
txtsquare.setText(Integer.toString(r.nextInt(100)) );


myBoard[i-1][j-1] = txtsquare;

mypanel.add(txtsquare);
txtsquare.setBounds( j* 60 , i* 60, 60, 60 );

}
redflag = !redflag;
}
myframe.add(mypanel);
myframe.setSize(1000,800);
myframe.setVisible(true);

for (int i =1 ; i<= 8; i++) {
for (int j = 1; j<= 8 ; j++ ){
if (Integer.parseInt(myBoard[i-1][j-1].getText()) < 50 ) {
myBoard[i-1][j-1].setText("");
}
}
}

}


}
public static JButton getButton(String inpos) {
int row, col;
row = Integer.parseInt(inpos.substring(0, 1));
col = Integer.parseInt(inpos.substring(1,2));
return myBoard[row-1][col-1];
}
}
(adsbygoogle = window.adsbygoogle || []).push({});
10-17-2014, 03:41 PM #2
Umm... I don't know what you are trying to ask for. But what I would use is the SpriteBatch and InputProcessor in Java. It would make what you are doing a lot easier.

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo