I'm trying to devise a Sudoku solver in order to solve a problem. While I would normally program this in C, I decided to do this one in Java because it would easier to plug in values and keep track of values in order to code it correctly. While it would be easier to use pen and paper, I want to work on my programming skills.
I'm using the Solving Sudoku hint page to give me ideas on how to code this. Anyway, I'm trying to imitate the possible numbers per cell display in order to help me. The problem is that I'm trying to use the Graphics drawString() function, but no text appears. I'm drawing rectangles to closely imitate a Sudoku board.
The code here is a separate window that display the possible numbers per cell and this is where I want to implement this. There is a control class and the main window, but it isn't necessary to include those as this is a graphics issue.
How can I get a graphical string to appear? Thanks.
I'm using the Solving Sudoku hint page to give me ideas on how to code this. Anyway, I'm trying to imitate the possible numbers per cell display in order to help me. The problem is that I'm trying to use the Graphics drawString() function, but no text appears. I'm drawing rectangles to closely imitate a Sudoku board.
The code here is a separate window that display the possible numbers per cell and this is where I want to implement this. There is a control class and the main window, but it isn't necessary to include those as this is a graphics issue.
Code:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Settings {
JFrame window = new JFrame("Analysis");
JPanel row1 = new JPanel();
Box[][] box = new Box[9][9];
public Settings()
{
window.setSize(500,500);
window.setResizable(false);
window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
FlowLayout layout = new FlowLayout();
window.setLayout(layout);
GridLayout layout1 = new GridLayout(9,9);
row1.setLayout(layout1);
for(int x = 0; x < 9; x++)
{
for(int y = 0; y < 9; y++)
{
box[x][y]=new Box();
box[x][y].setPreferredSize(new Dimension(51,51));
row1.add(box[x][y]);
}
}
window.add(row1);
window.setVisible(true);
}
}
class Box extends JComponent
{
boolean[] isThere = new boolean[9];
boolean isFixed= false; //Determines whether this is fixed.
public Box()
{
for(int x= 0; x < 9; x++)
{
isThere[x]=false;
}
}
public void paintComponent(Graphics g)
{
g.drawRect(0, 0, 50, 50);
list(g);
}
void list(Graphics g)
{
Graphics2D g2d = (Graphics2D)g;
//if(isThere[0]==false)
{
g2d.drawString("1", 0, 0);
}
}
}
How can I get a graphical string to appear? Thanks.