Question
How do I make this grid display in another jframe?
I have coded a MazeClass that paints a grid and has a method to change the color of a block on the grid. I would like to display this grid in a separate class on a jframe in the position I want to. Here is the class:
package mazemania;
import java.awt.*;
public class MazeClass extends javax.swing.JFrame{
private Color[][] colorArr = new Color[20][20];
public MazeClass(){
setVisible(true);
}
public void paint(Graphics g)
{
for(int row = 0; row < 20; row++)
{
for(int column = 0; column < 20; column++)
{
g.setColor(colorArr[row][column]);
g.fillRect(row*15, column*15, 15, 15);
g.setColor(Color.BLACK);
g.drawRect(row*15, column*15, 15, 15);
}
}
} //End of paint method
public void colorBlock(Color c, int row, int col)
{
colorArr[row][col] = c;
repaint();
}
}
I have tried instantiating the MazeClass from another class but it created separate jpanel instead of placing it on the one in the class.
package mazemania;
import java.awt.Graphics2D;
import java.awt.Color;
import java.awt.Graphics;
/**
*
* @author jin06
*/
public class CampaignGUI extends javax.swing.JFrame {
//PauseGUI pauseScreen = new PauseGUI();
/**
* Creates new form CampaignGUI
*/
public CampaignGUI() {
initComponents();
MazeClass maze = new MazeClass();
maze.colorBlock(Color.RED, 1, 1);
maze.setVisible(true);
}
How would I place this grid inside the GUI I have already designed, in the position I would like to? I would appreciate any help. Thank you.