error:
The method paint(Graphics, main) in the type player is not applicable for the arguments (Graphics, main.Display)

on line: player_class.paint(g)

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);   
        }/** 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)
    {
        g.setColor(Color.red);
        g.fillRect(x, y, width, height); 
    }   
}

Edited 3 Years Ago by game06

Ona completely separate point - you seem to be using a jaax.swing.Timer to run your game loop. Your architecture for this (separating the game loop from the screen painting) is exactly right, but that's not the best Timer for this purpose. The swing Timer will run your game loop on the swing event dispatch thread, where it will compete with the screen painting. If you use a java.util.Timer your game loop will run in its own thread, simultaneously if you have a dual processor. That wil allow you to achieve higher frame rates and smoother animation for no extra effort.
The syntax for java.util.Timer is slightly different, but it should only take a minute or two to change the code over.

i just check again and this is the error. it doesnt give error but when i hover over it, it give me this error.

also in main i have Player p lower case.
and two line were wrong. srry.

 player_class.paint(g, this);

and

  public void paint(Graphics g, main m)

thanks for the timer tip. i will try to change it.

Edited 3 Years Ago by game06

ahhh got it. it was 'main.this' and not 'this'

Edited 3 Years Ago by game06

This question has already been answered. Start a new discussion instead.