Game.java calls a function getLabel()
present in board.java. When I am running Game.java, I am getting error "cannot find symbol method getLabel()
" in the terminal. I am not able to correct it.
Game.java
import java.awt.*;
import javax.swing.*;
import javax.swing.JLabel;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class Game {
private board b;
private bishop bis1;
private JLabel q;
public static void main(String[] args) {
Game f = new Game();
f.start();
}
public void start() {
b = new board();
bis1 = new bishop();
bis1.setLocation(0, 0);
ImageIcon m = bis1.getImage();
q = b.getLabel();
q.addMouseListener(new Mouselist());
b.squares[0][0].add(q);
}
class Mouselist implements MouseListener {
public void mouseClicked(MouseEvent e) {
//k.setIcon(null);
b.squares[1][1].add(new JLabel(new ImageIcon("rook.png")));
}
// mouse entered the JLabel increment count and display it
public void mouseEntered(MouseEvent e) {
b.squares[1][1].add(new JLabel(new ImageIcon("rook.png")));
}
public void mouseExited(MouseEvent e) {
b.squares[1][2].add(new JLabel(new ImageIcon("rook.png")));
}
// mouse was presssed (cliked and released)
// increment counter and display it
public void mousePressed(MouseEvent e) {
b.squares[1][1].add(new JLabel(new ImageIcon("rook.png")));
}
public void mouseReleased(MouseEvent e) {
b.squares[1][1].add(new JLabel(new ImageIcon("rook.png")));
}
}
}
board.java
import javax.swing.*;
import java.awt.*;
import javax.swing.JLabel;
public class board {
public JFrame frame;
public JPanel squares[][] = new JPanel[3][3];
private JLabel sqk = new JLabel(new ImageIcon("knight.png"));
public board() {
frame = new JFrame("Simplified Chess");
frame.setSize(1200, 800);
frame.setLayout(new GridLayout(2, 3));
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 3; j++) {
squares[i][j] = new JPanel();
if ((i + j) % 2 == 0) {
squares[i][j].setBackground(Color.black);
} else {
squares[i][j].setBackground(Color.white);
}
frame.add(squares[i][j]);
}
}
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public JLabel getLabel() {
return sqk;
}
}
What is possibly wrong here ?