Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8228057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:20:26+00:00 2026-06-07T16:20:26+00:00

I´m just starting to learn how to program so excuse me if my question

  • 0

I´m just starting to learn how to program so excuse me if my question is just silly. I have been trying for over two days to find a solution for this problem and I just can’t find it over the net so I need your help. Thanks in advance.

So, I am trying to recreate the Parchisi game in Java. I want to create a method that puts a counter in an specific position every time a player rolls the dice and obtains the number five as a result.
The counter has its own class, that is:

package parchis;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JPanel;

public class Ficha extends JPanel
{
   public static int x;
   public static int y;
   public Image imagenficha;

  @Override
  public void paintComponent(Graphics g){

  super.paintComponent(g);

  System.out.println("Ejecutándose función de pintura de ficha");
  g.drawImage(imagenficha,x,y,this);
  g.setColor(Color.RED);
  g.fillRect(0,0,20,20);
}

 Ficha(int color, int locx, int locy, int ancho, int alto){

    this.setSize(60,60);
    System.out.println("El color es el "+Servidor.turno); 
    this.setBounds(locx,locy,ancho,alto); 
    x=locx;
    y=locy;
    this.setVisible(true);
} 

The checker is put over a jframe by a call of this method:

public void pintarficha(){

    Ficha ficha = new Ficha(Servidor.turno,40,40,100,100);
    jframe.getContentPane().add(ficha);
    Refrescar();
}

Refrescar:

public static void Refrescar(){

   jpanel.add(jlabel);
   jframe.add(jpanel);
  jframe.pack();
}

The problem is that, when the method pintarficha() is called from outside a method (I.E. in the instantiation of one of my classes) it works properly and paints the counter, but when I put it inside of any method, PaintComponent is not being executed and I cannot understand why.

Here it works:

package parchis;
public class Administradordereglas {

      Administradordereglas(){
        ********** Menu.menu.pintarficha(); ****************
      }

     void juegodebots(int jugador){

         System.out.println("LLAMADA A JUEGO DE BOTS");
         int valoraañadiralasposiciones;
         valoraañadiralasposiciones= Ventanadeordenes.dado.Tiraeldado();  

         if(valoraañadiralasposiciones==5){

            System.out.println("Se ha sacado un 5, procedo a crear una nueva ficha");
         }

         Parchis.servidor.Pasarturno();
     }
}

But here it doesn’t:

package parchis;
public class Administradordereglas {

      Administradordereglas(){

      }
     void juegodebots(int jugador) {

         System.out.println("LLAMADA A JUEGO DE BOTS");
         int valoraañadiralasposiciones;
         valoraañadiralasposiciones= Ventanadeordenes.dado.Tiraeldado();  
         if(valoraañadiralasposiciones==5){
             **************This message appears in the console:****************** 
             System.out.println("Se ha sacado un 5, procedo a crear una nueva ficha");

            *****************Menu.menu.pintarficha();*************************
         }
         Parchis.servidor.Pasarturno();
    }
}

Thanks for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T16:20:27+00:00Added an answer on June 7, 2026 at 4:20 pm

    Can you add repaint() to your Refrescar method:

    public void refrescar() {
    
        jpanel.add(jlabel);
        jframe.add(jpanel);
        jframe.pack();
        jframe.repaint();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im just starting to learn about sockets and i have been given this code,
I'm trying to run a simple C++ program (as I'm JUST starting to learn
I am just starting to learn how to use RMI, and I have a
I'm just starting to learn AspectJ, and I have use-case for say, User login.
Hi I'm just starting to learn C#. I am trying to restore a .bak
I am just starting to learn how to script. I'm trying to understand how
I'm just starting to learn Python and have heard about the GIL and how
Just starting to learn scala for a new project. Have got to the point
I am just starting to learn jQuery and have gotten some of the basic
im just starting to learn flex and im trying to understand how Flex does

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.