jframe - Draw things after board is drawn with paint (JPanel) (java) -


i trying make simple tic tac toe game in java. however, cannot figure out how draw after i've drawn board. here's structure of game.

public class threeinarowmain extends jpanel {      public static final int width = 600, height = 640;      public void paint(graphics g) {         g.setcolor(color.white);         g.fillrect(0, 0, width, height);         g.setcolor(color.black);         g.drawstring("1.", 0,20);         g.drawstring("2.", 210,20);         g.drawstring("3.", 410,20);         g.drawstring("4.", 0,220);         g.drawstring("5.", 210,220);         g.drawstring("6.", 410,220);         g.drawstring("7.", 0,420);         g.drawstring("8.", 210,420);         g.drawstring("9.", 410,420);         //horizontal lines         g.drawline(0, 200, width, 200);         g.drawline(0, 400, width, 400);         //vertical lines         g.drawline(200, 0, 200, height);         g.drawline(400, 0, 400, height);      }      public static void main (string [] args) {     boolean firstorsecond = true;         jframe frame = new jframe("tic tac toe");         frame.setsize(width, height);         frame.getcontentpane().add(new threeinarowmain());         frame.setlocationrelativeto(null);         frame.setbackground(color.black);         frame.setdefaultcloseoperation(jframe.exit_on_close);         frame.setvisible(true);         boolean someonewins = false;         int firstplayerpos, secondplayerpos;         int [] [] board = new int [3] [3];         scanner in = new scanner(system.in);          while (!someonewins){         system.out.println("p1, enter number of square you'd mark.");         firstplayerpos = in.nextint();         drawxoro(firstplayerpos,firstorsecond);           system.out.println("p2, enter number of square you'd mark.");         secondplayerpos = in.nextint();         drawxoro(secondplayerpos,!firstorsecond);          }     }      public static void drawxoro (int position, boolean firstorsecond) {      }  } 

i know badly designed game @ moment; correct later. however, want drawxoro draw x or , o in position player has typed in. how add graphics after using method paint? thanks!


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -