Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #1351

Re: Reseting the ball after changes

From Michael Adedeji <yankosmgt@gmail.com>
Newsgroups comp.lang.java.help
Subject Re: Reseting the ball after changes
Date 2011-11-15 13:14 -0800
Organization http://groups.google.com
Message-ID <69a0a206-fa9c-4c7f-be11-1265bd12847d@u6g2000vbg.googlegroups.com> (permalink)
References <1bebffda-d16a-4cb0-b443-6fab7306b8fc@g21g2000yqc.googlegroups.com> <nospam-545B37.11514815112011@news.aioe.org>

Show all headers | View raw


On Nov 15, 4:51 pm, "John B. Matthews" <nos...@nospam.invalid> wrote:
> In article
> <1bebffda-d16a-4cb0-b443-6fab7306b...@g21g2000yqc.googlegroups.com>,
>  Michael Adedeji <yankos...@gmail.com> wrote:
>
> > I have done the menu, but I have problem with reseting of the ball,
> > everytime I change the size or the speed of the ball, it kind of
> > change the way the sounds works. I kinda figure out that I need to
> > reset it everytime I change the size or the speed of the ball.
>
> Exactly, you're changing the (implicit) model's state behind the view's
> back.
>
> > Does anyone have an idea how I could go about it.
>
> I'd reiterate my earlier suggestion on MVC [1]; it's time to re-factor.
> As an alternative, the example cited adjusts the Timer's rate, rather
> than the velocity's norm. A similar problem arises when the simulated
> boundary is resized; the model has a corresponding setWalls() method.
>
> [1] <https://groups.google.com/d/msg/comp.lang.java.help/u2r-L6H_kD4/t2Q16...>
>
> --
> John B. Matthews
> trashgod at gmail dot com
> <http://sites.google.com/site/drjohnbmatthews>

Hey John, How can I use this getColors methods in the public void
paintComponent(Graphics g)...to change the color of the balls...the
idea u gave me the other time, I couldn't use it...maybe if u could be
make it clearer..
private void getColors() {
		//if(randomColorMode){
			// this color is used to represent the
			// random color mode
			Random ran = new Random();
			int ranInt = ran.nextInt(4);

			switch(ranInt){
			case 0: ballColor = Color.white;break;
			case 1: ballColor = Color.blue;break;
			case 2: ballColor = Color.yellow;break;
			default: ballColor = Color.red;break;
			//}
		}


		if(ballColor.equals(Color.white)){
			ballColor = Color.white;
			backgroundColor = Color.black;
		}
		else if(ballColor.equals(Color.blue)){
			ballColor = Color.blue;
			backgroundColor = Color.black;
		}
		else if(ballColor.equals(Color.yellow)){
			ballColor = Color.yellow;
			backgroundColor = Color.black;
		}
		else{
			ballColor = Color.red;
			backgroundColor = Color.black;
		}

Back to comp.lang.java.help | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Reseting the ball after changes Michael Adedeji <yankosmgt@gmail.com> - 2011-11-14 05:14 -0800
  Re: Reseting the ball after changes "John B. Matthews" <nospam@nospam.invalid> - 2011-11-15 11:51 -0500
    Re: Reseting the ball after changes Michael Adedeji <yankosmgt@gmail.com> - 2011-11-15 13:14 -0800
    Re: Reseting the ball after changes Michael Adedeji <yankosmgt@gmail.com> - 2011-11-15 16:34 -0800
      Re: Reseting the ball after changes "John B. Matthews" <nospam@nospam.invalid> - 2011-11-16 00:17 -0500
        Re: Reseting the ball after changes Michael Adedeji <yankosmgt@gmail.com> - 2011-11-16 02:32 -0800
          Re: Reseting the ball after changes "John B. Matthews" <nospam@nospam.invalid> - 2011-11-16 10:37 -0500

csiph-web