i am painting a rect in player.java and i want to print in main.java class.
in main i am using paintComponent but in player class iam using paint method.
my 1st question is that shoud i use paintComponent in both classes? or is it right that way i have it.
my 2nd question is that. i have a error:
The method paint(Graphics, main) in the type player is not applicable for the arguments (Graphics, main.Display)
error on line: player_class.paint(g, this)
note if i send 'this' to different class than i get error. but if i only send 'g' than it works fine.
main.java
public class main extends JApplet { Timer timer; Display display_class; player player_class; /*** init method ***/ public void init() { setSize(800, 400); display_class = new Display(); setContentPane(display_class); }/*** end of init method ***/ /*** stat method ***/ public void start() { player_class = new player(); timer = new Timer(30, this); timer.start(); }/*** end of start method ***/ /*** game loop ***/ public void actionPerformed(ActionEvent e) { repaint(); }/*** end of run method ***/ /*** paint method ***/ public class Display extends JPanel { public void paintComponent(Graphics g) { super.paintComponent(g); player_class.paint(g, this); }/** end of paint component method ***/ }/*** end of display class ***/ }/*** end of main class ***/
player.java
public class player { /*** PLAYER VARIABLES ***/ private int x = 10; private int y = 200; private int width = 15; private int height = 100; /*** CONSTRUCTOR METHOD ***/ public player() { } public void paint(Graphics g, main m) { g.setColor(Color.red); g.fillRect(x, y, width, height); } }