java - Calling a method from GamePanel -


i believe pretty simple oo question can't seem find answer :/ have game panel load of balls painted onto panel. when ball hits bottom of panel game on message should displayed.

the problem i'm dealing regarding game on joptionpane. believe should kept in class need call in ball class.

here part of ball class want call method (marked **):

private void moveball() {      if (x == panel.getwidth() - size) {         xa -= speed;     } else if (x < 0) {         xa += speed;     }      if (y == panel.getheight() - size) {         ya -= speed;     } else if (y < 0) {         ya += speed;     }      if (collision()) {         ya = -speed;         y = platform.gety() - diameter;     }      if (y == panel.getheight() - size) {          // ***call gameover here***      }     x += xa;     y += ya; } 

here constructor being called ball class in game panel:

// constructor pass colour , platform public ball(jframe frame, jpanel panel, platform platform, color colour,         int x, int y, int size) {      this.platform = platform;      this.frame = frame;     this.panel = panel;     this.colour = colour;      // location of ball     this.x = x;     this.y = y;      // size of ball     this.size = size;      animator = new thread(this);     animator.start(); } 

so how access method?

note (structure): frame -> panel -> ball

thanks

let me know if haven't explained myself or need more information

consider watching position of ball different class, has access gameover function. way don't need expose panels ball class, , problem avoided.

also, can't call gameover function since not exist in jframe, if want use current approach, need supply class, or interface, contains gameover function ball constructor.


Comments

Popular posts from this blog

HTTP/1.0 407 Proxy Authentication Required PHP -

curl - PHP fsockopen help required -

c# - Resource not found error -