I need to get the inputs from the scanner in the method main, into the method paint, and I do not know how to do that. Normally I can just do instance.paint(); But it isn't working. I think i have to do something with the parameters in the paint method but i don't know what. Please help.
import javax.swing.*;
import java.awt.*;
import java.util.*;
public class ChessSet extends JPanel
{
public static void main()
{
ChessSet inst1 = new ChessSet();
Scanner key = new Scanner( System.in );
System.out.println( "How many pawns would you like? (0-4): " );
int numPawns = key.nextInt();
System.out.println( "How many bishops would you like? (0-4): " );
int numBishops = key.nextInt();
JFrame ourFrame = new JFrame();
ourFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE);
ourFrame.setSize(1000,1000);
ChessSet ourChessSet = new ChessSet();
ourFrame.add( ourChessSet );
ourFrame.setBackground( Color.white );
ourFrame.setVisible(true);
}
public void paint( Graphics canvas )
{
ChessSet inst1 = new ChessSet();
this.drawPawn( canvas, 100, 140, Color.black );
this.drawKing( canvas, 375, 50, Color.black );
this.drawRook( canvas, 600, 110, Color.black );
this.drawQueen( canvas, 100, 535, Color.black );
this.drawKnight( canvas, 350,480, Color.black );
this.drawBishop( canvas, 700, 480, Color.black );
canvas.drawString( "King 1", 10, 10 );
canvas.drawString( "Rook 1", 10, 30 );
canvas.drawString( "Queen 1", 10, 20 );
canvas.drawString( "Pawn " + numPawn, 100, 10 );
canvas.drawString( "Bishop " + numBishop, 100, 30 );
canvas.drawString( "Knight 1", 100, 20 );
}
}