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 7837719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:49:00+00:00 2026-06-02T14:49:00+00:00

I’m a student programming a frogger game, when the frog collides with an object

  • 0

I’m a student programming a frogger game, when the frog collides with an object or reaches the end zone either the score is incremented or lives decremented and the frog returned to the start position. this section works and the decrement and increment work when outputting them to the console, I try to pass the variable to the other jpanel and display it there but it doesnt update and display the variable in the textField.

Game Panel

    public GamePanel() {
    super();
    setFocusable(true);
    addKeyListener(new KeyList());
    System.out.println("GAME PANE FOCUS:" + this.isFocusOwner());

    scores.setVisible(true);
    lives = p.STARTLIVES;
    scores.setCurrentLives(lives);
    txtTest.setText("Hello");
    txtTest.setVisible(true);
    add(scores,new AbsoluteConstraints(0,550,50,800));
    Boolean displayable = scores.isDisplayable();
    System.out.println("Displayable" + displayable);

    scores.setEnabled(false);
    scores.revalidate();
    scores.repaint();
    scores.setVisible(true);

    System.out.println("Displayable" + displayable);



   car1.start();
   car2.start();
   car3.start();
   car4.start();
   Log1.start();
   Log2.start();
   Log3.start();
   Log4.start();
   Log5.start();
   Log6.start();
   Log7.start();
   Log8.start();



    //check for collisions
}

final public void winZone(Rectangle object){

    if(myFrog.frogArea().intersects(object)){
        currentScore = currentScore + 100;
        System.out.println("current Score " + currentScore);
        p.setScore(currentScore);
        scores.myScore().setText("hello");

        myFrog.lostLife();
    }

scores panel

public class jplScores extends JPanel {
 Properties p = new Properties();
 int currentLives;
 int i;

/** Creates new form jplScores */
public jplScores() {
    initComponents();




}
public void setCurrentLives(int Lives){
 currentLives = Lives;
}
public String getCurrentLives(){
    String L = Integer.toString(currentLives);
    return L;
}


public JTextField myScore(){
    return txtScore;
}

Currently it will display the jpanel from the frame that they are both in but i have tried to make it so its a panel within a panel but i cant get the panel to display from within the game panel.

Any help would be great thanks

    public FroggerGame() {

    initComponents();
    setFocusable(true);
    //repaint();
   // p.setHeight(550);
   // p.setWidth(800);
   // p.setLives(3);
   // p.setScore(0);
    PANELHEIGHT = p.getHeight();
    PANELWIDTH = p.getWidth();
    welcomePanel();

    /*
    Toolkit tool = Toolkit.getDefaultToolkit();
    imgBackground = tool.getImage(imageBackground);
    background = new ImageIcon(imgBackground);
    //setDefaultCloseOperation(EXIT_ON_CLOSE);
    */

    jps.myScore().addPropertyChangeListener(new java.beans.PropertyChangeListener() {
        public void propertyChange(java.beans.PropertyChangeEvent evt) {
           // txtScorePropertyChange(evt);

    jps.myScore().setText(Integer.toString(gp.currentScore()));
    System.out.println(Integer.toString(gp.currentScore()));

    jps.getScore(gp.currentScore());
    System.out.println(" main score " + gp.currentScore());
        }
    });


}

….

private void btnEnterActionPerformed(ActionEvent evt) {

    welcomePanel.setVisible(false);
    getContentPane().setLayout(new AbsoluteLayout());
    getContentPane().add(gp,new AbsoluteConstraints(0,0,800,550));
    getContentPane().add(jps,new AbsoluteConstraints(0,550,800,100));

    //gp.setSize(800, 550);
   // gp.setBounds(0, 0, 800, 550);
    gp.setVisible(true);
    gp.requestFocusInWindow();

    jps.setVisible(true);

gp is the game panel and jps is the score panel.

  • 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-02T14:49:01+00:00Added an answer on June 2, 2026 at 2:49 pm

    This really has little to do with “panels” or Swing GUI coding and all to do with the basic OOPS issue of passing information from one class to another. One way to solve this is to give your Scores panel a public method, say

    public void changeScore(int value) {
       // in here add the new value to the currently 
       // displayed value and display the new value.
    }
    

    Then the main class, the one with a Scores panel reference, you can call this method, passing in 1 if score is to increase or -1 if it is to decrease.

    I think of this as the “push” solution, where one class pushes information into the other class. Another way to solve this is via listeners where the Scores class listens to critical properties of the other class and then changes its own score when an appropriate event occurs, and this often involves using PropertyChangeListeners or other more Swing-specific listener classes. This is sometimes a nicer solution, but I consider it a slightly more advanced concept.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is

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.