This is Java I am currently stumped on how to add a scoreboa

This is Java,

I am currently stumped on how to add a scoreboard for my game that I am making. I have inclued my code and classes so far. Any help with a working scoreboard would be greatly apperiacted.

Game.java

import javax.swing.JFrame;

public class Game {
  
   public static void main(String[] args)
   {
      
       // create the frame
       JFrame myFrame = new JFrame(\"Platformer\");
      
       // set up the close operation
       myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       // create panel
       Mainpanel myPanel = new Mainpanel();
       // add panel
       myFrame.getContentPane().add(myPanel);
       // pack
       myFrame.pack();
       // set visibility to true
       myFrame.setVisible(true);
   }
}

Mainpanel.java

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.ArrayList;
import java.util.Random;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Timer;

public class Mainpanel extends JPanel implements KeyListener, ActionListener{

   private final int boardWidth =1000;
   private final int boardHeight =1000;

   int x = 0;
   int y = 0;
   int i= 0;
   int goldCount=11;
   int score = 0;
  
   ImageIcon myIcon = new ImageIcon(\"./src/TreasureChest.png\");
  
   Timer mainTimer;
   player player1;
   player player2;
   static ArrayList treasure = new ArrayList();
   Random rand = new Random();
  
   public String ScoreCount = \"Score: \" + score;
  
   public Mainpanel()
   {
       setPreferredSize(new Dimension(boardWidth,boardHeight));
       addKeyListener(this);
       setFocusable(true);
      
       player1= new player (100,100);
       player2= new player (200,200);
      
      
       addKeyListener(new move(player1));
       addKeyListener(new move(player2));
          
       mainTimer = new Timer(10,this);
       mainTimer.start();
      
       startGame();
  
   }

   JLabel scoreLabel = new JLabel(\"Score: 0\");
  
  
   public void paintComponent(Graphics page)
   {
       super.paintComponent(page);
       Graphics2D g2d =(Graphics2D) page;
                      
       player1.draw(g2d);
       player2.draw(g2d);
  
       g2d.
       g2d.setColor(new Color(128, 128, 128));
       g2d.fillRect(0, 0, 50, 1000);         

       g2d.setColor(new Color(128, 128, 128));
       g2d.fillRect(950, 0, 50, 1000);
      
       g2d.setColor(new Color(128, 128, 128));
       g2d.fillRect(50, 0, 900, 50);
         
       g2d.setColor(new Color(128, 128, 128));;
       g2d.fillRect(50, 950, 900, 50);

         
       for (int i=0 ; i < treasure.size(); i++){
           Gold tempGold = treasure.get(i);
           tempGold.draw(g2d);
                  
       }
   }

   public void actionPerformed (ActionEvent arg0){
       player1.update();
       repaint();
   }

   @Override
   public void keyPressed(KeyEvent arg0) {
       // TODO Auto-generated method stub
      
   }

   @Override
   public void keyReleased(KeyEvent arg0) {
       // TODO Auto-generated method stub
      
   }

   @Override
   public void keyTyped(KeyEvent arg0) {
       // TODO Auto-generated method stub
      
   }
  
   public void addGold(Gold g){
       treasure.add(g);
   }
  
   public static void removeGold (Gold g) {
       treasure.remove(g);
   }
  
   public static ArrayList getGoldList() {
       return treasure;
   }
  
   public void startGame() {
       for (int i=0; i < goldCount; i++){
           addGold(new Gold(rand.nextInt(boardWidth), rand.nextInt(boardHeight)));
       }
      
   }
  
   public void someoneScored()
   {
   score++;
   scoreLabel.setBounds(200, 200, 100, 100);
   scoreLabel.setText(\"Score: \" + score);
   }

  
}

Player.java

import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import java.util.ArrayList;

import javax.swing.ImageIcon;

public class player extends Entity{
  
   int velX=0;
   int vely=0;
  
   public player(int x, int y){
       super(x, y);
   }

   public void update(){
       y+= vely;
       x+= velX;
       checkCollisons();
       checkOOB();
   }
  
   public void draw(Graphics2D g2d) {
       g2d.drawImage(getPlayerImg(), x, y, null);
       //g2d.draw(getBounds());
   }
  
   public Image getPlayerImg(){
       ImageIcon ic = new ImageIcon(\"./src/TreasureChest.png\");
       return ic.getImage();
   }
  
   public void keyPressed(KeyEvent arg0){
       int keyCode = arg0.getKeyCode();
      
       if (keyCode == KeyEvent.VK_LEFT)
       {

           velX=-10;
       }
       else if (keyCode == KeyEvent.VK_RIGHT)
       {

           velX=10;
       }
       else if (keyCode == KeyEvent.VK_UP)
       {

           vely=-10;
       }
       else if (keyCode == KeyEvent.VK_DOWN)
       {

           vely=10;
       }
      
   }
  
   public void keyReleased(KeyEvent arg0){
   int keyCode = arg0.getKeyCode();
      
       if (keyCode == KeyEvent.VK_LEFT)
       {

           velX=0;
       }
       else if (keyCode == KeyEvent.VK_RIGHT)
       {

           velX=0;
       }
       else if (keyCode == KeyEvent.VK_UP)
       {

           vely=0;
       }
       else if (keyCode == KeyEvent.VK_DOWN)
       {

           vely=0;
       }
   }
      
   public void checkCollisons(){
       ArrayList treasure = Mainpanel.getGoldList();
      
       for (int i=0; i < treasure.size(); i++){
           Gold tempGold= treasure.get(i);
           if (getBounds().intersects(tempGold.getBounds())) {
               Mainpanel.removeGold(tempGold);
           }
       }  
   }
  
   public Rectangle getBounds(){
   return new Rectangle(x,y, getPlayerImg().getWidth(null), getPlayerImg().getHeight(null));
   }
  
   private void checkOOB() {
       if(x < 50) x = 50;
       if(x > 900) x = 900;
       if(y < 50) y = 50;
       if(y > 915) y = 9;
       }
  
}

Entity.java

import java.awt.Graphics2D;

public class Entity {
  
   int x,y;
  
       public Entity(int x, int y){
           this.x= x;
           this.y=y;
  
   }
      
   public void update(){
   }
   public void draw(Graphics2D g2d){
   }
}

Move.java

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

public class move extends KeyAdapter {
  
   player p;
  
   public move(player player1){
       p= player1;
      
   }
  
   public void keyPressed(KeyEvent e){
       p.keyPressed(e);
   }
  
   public void keyReleased(KeyEvent e){
       p.keyReleased(e);
   }
  

}

Gold.java

import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;

import javax.swing.ImageIcon;

public class Gold extends Entity {
  
   public Gold(int x, int y){
       super(x, y);
   }

   public void update(){
   }
  
   public void draw(Graphics2D g2d) {
       g2d.drawImage(getGoldImg(), x, y, null);
       //g2d.draw(getBounds());
   }
  
   public Image getGoldImg(){
       ImageIcon ic = new ImageIcon(\"./src/TreasureChest.png\");
       return ic.getImage();
   }
  
   public Rectangle getBounds(){
       return new Rectangle(x,y, getGoldImg().getWidth(null), getGoldImg().getHeight(null));
       }
      
}

Solution

import java.applet.*;
import java.awt.*;

public class gamescore extends Applet implements Runnable
{

   //instance fields
   int x_pos=350;
   int y_pos=250;
   int p1_x=0;
   int p1_y=200;
   int p2_x=490;
   int p2_y=200;
   int radius=10;
   int x_speed=1;
   int y_speed=1;
   final int paddle_width=20;
   final int paddle_height=80;
   final int ball_speed=25;
   int p1_score=0;
   int p2_score=0;
   int p1_scoreKeeper=0;
   int p2_scoreKeeper=0;
   String score = p1_score+\" \"+p2_score;;

   //handles mouse down events
   public boolean mouseDown(Event e, int x, int y)
   {
       x_speed*=-1;
       y_speed*=-1;

       return true;
   }

   //handles keyboard events
   public boolean keyDown(Event e, int key)
   {
      //p1 up control
      if(key == Event.UP)
      {
          p1_y+=-6;
      }

      //p1 down control
      if(key == Event.DOWN)
      {
          p1_y+=6;
      }

      return true;
   }


   //called the first time you enter the HTML site with the applet
   public void init() {}

   //called EVERY time you enter the HTML site with the applet
   public void start()
   {
       //define a new thread
       Thread th = new Thread(this);
       //start thread
       th.start();

   }

   //called if you leave the site with the applet
   public void stop() {}

   //called if you leave the page finally (e. g. closing browser)
   public void destroy() {}

   public void run()
   {
       //lower thread priority
       Thread.currentThread().setPriority(Thread.MIN_PRIORITY);

       while(true)
       {

           //if ball leaves applet area, reset
           if(y_pos&gt;500+radius)
           {
               y_pos=100;
           }

           //ball bounces if it reaches bottom edge of applet
           if(y_pos&gt;308-radius)
           {
               y_speed+=-1;
           }

           //ball bounces if it reaches top edge of applet
           if(y_pos&lt;radius)
           {
               y_speed=1;
           }

           if(p1_score&lt;20&amp;&amp;p2_score&lt;20)
           {
               //move ball along x-axis
               x_pos+=x_speed;
               y_pos+=y_speed;
           }

           //SCORING
             
           if(x_pos&gt;600)
           {
               p1_scoreKeeper++;

               //reset ball
               x_pos=350;
               y_pos=150;
           }
           //player 2 scores if ball goes past left edge
           if(x_pos&lt;0)
           {
               p2_scoreKeeper++;

               //reset ball
               x_pos=350;
               y_pos=150;
           }

           //update score
           p1_score+=p1_scoreKeeper;
           p2_score+=p2_scoreKeeper;
           //repaint the applet
           repaint();

           try
           {
               //stop thread for specified time
               Thread.sleep(ball_speed);
           }

           catch(InterruptedException ex)
           {
               //do nothing  
           }

           //set thread to max priority
           Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
       }
   }

   public void paint (Graphics g)
   {
       //set color
       g.setColor(Color.green);

       //set text font
       g.setFont (new Font (\"Monospaced\",Font.PLAIN,24));

       //draw score
       g.drawString(score, 400, 40);

       //paint a filled colored circle
       g.fillOval(x_pos-radius, y_pos-radius,radius*2,radius*2);

       g.setColor(Color.pink);
       //player 1 paddle
       g.fillRect(p1_x, p1_y, paddle_width, paddle_height);

       g.setColor(Color.white);
       //player 2 paddle
       g.fillRect(p2_x, p2_y, paddle_width, paddle_height);
   }

}

This is Java, I am currently stumped on how to add a scoreboard for my game that I am making. I have inclued my code and classes so far. Any help with a working
This is Java, I am currently stumped on how to add a scoreboard for my game that I am making. I have inclued my code and classes so far. Any help with a working
This is Java, I am currently stumped on how to add a scoreboard for my game that I am making. I have inclued my code and classes so far. Any help with a working
This is Java, I am currently stumped on how to add a scoreboard for my game that I am making. I have inclued my code and classes so far. Any help with a working
This is Java, I am currently stumped on how to add a scoreboard for my game that I am making. I have inclued my code and classes so far. Any help with a working
This is Java, I am currently stumped on how to add a scoreboard for my game that I am making. I have inclued my code and classes so far. Any help with a working
This is Java, I am currently stumped on how to add a scoreboard for my game that I am making. I have inclued my code and classes so far. Any help with a working
This is Java, I am currently stumped on how to add a scoreboard for my game that I am making. I have inclued my code and classes so far. Any help with a working
This is Java, I am currently stumped on how to add a scoreboard for my game that I am making. I have inclued my code and classes so far. Any help with a working

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site