java - Two Simple Bouncing Ball -


i'm new java , i'm working on graphics , i'm doing simple bouncing ball. @ first created 1 bouncing ball , worked added 1 more ball error occurred. "error: cannot find symbol" occurred on line 33,43,55 , 59. can me pls? seems have called variables needed.

import javax.swing.*; import java.awt.*; import java.awt.*; import java.util.*; import java.awt.event.*; import javax.swing.timer; public class bouncingball extends jpanel { //1st ball int x1 = 250, y1 = 100; int width1 = 50, height1 = 50; int xpos1 = 0, ypos1 = 0; //2nd ball int x2 = 20, y2 = 20; int width2 = 100, height2 = 100; int xpos2 = 0, ypos2 = 0; java.util.timer timer; static jframe frame; public bouncingball() { frame = new jframe("bouncing ball"); frame.setsize(400,400); frame.setvisible(true); setforeground(color.red); timer = new java.util.timer(); timer.scheduleatfixedrate(new timertask() { public void run() { { if(x1 < 0) xpos1 = 1; if(x1 >= getwidth1() - 45) xpos1 = -1; if(y1 < 0) ypos1 = 1; if(y1 >= getheight1() - 45) ypos1 = - 1; x1 += xpos1; y1 += ypos1; repaint(); } { if(x2 < 0) xpos2 = 1; if(x2 >= getwidth2() - 45) xpos2 = -1; if(y2 < 0) ypos2 = 1; if(y2 >= getheight2() - 45) ypos2 = - 1; x2 += xpos2; y2 += ypos2; repaint(); } } }, 0, 5); frame.setdefaultcloseoperation(jframe.exit_on_close); } public void paint(graphics g) { super.paint(g); graphics2d g2d = (graphics2d) g; g2d.setrenderinghint(renderinghints.key_antialiasing,   renderinghints.value_antialias_on); g2d.filloval(x1,y1,width1,height1); g2d.filloval(x2,y2,width2,height2); } public static void main(string args[]) { bouncingball ball = new bouncingball(); frame.add(ball); } } 

here 4 lines in question:

if(x1 >= getwidth1() - 45) if(y1 >= getheight1() - 45) if(x2 >= getwidth2() - 45) if(y2 >= getheight2() - 45) 

none of these methods implemented.

what want frame.getwidth() , frame.getheight().


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -