🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: be.comp.programming
Article #2596

Re: wat is er fout in deze code?

#2596
From: Kristoffel
Date: Thu, 29 Apr 2004 10:55
81 lines
3391 bytes
Gekkie wrote:
> Hallo iedereen,
> 
> ik heb een opgave van een boek ( En dan is er java) en daar zit ik in
> hoofdstuk 4.
> de opgave luit als volgd "Maak een applet die een rode cirkel tegen een gele
> achtergrond tekent. Voeg vervolgens een knop toe aan de applet die ervoor
> zorgt dat de cirkel zich een stukje naar rechts beweegt telkens als je op de
> knop klikt.
> Aanwijzing: declareer een variabele voor de x-co�rdinaat van de cirkel. Voeg
> ook een knop toe die ervoor zorgt dat de cirkel zich naar links beweegt."
> 
> De vraag luit nu wat is er fout ik krijg mijn cirkel niet in beweging. Help
> Aub.
> 
> import java.awt.*;
> import java.applet.*;
> import java.awt.event.*;
> 
> 
> public class Hs04_Vr04 extends Applet
> {
>  int cordinaten;
>  Button Rechts, Links;
> 
>  public void init()
>  {
>   setBackground ( Color.yellow );
> 
>   Rechts = new Button ( "R" );
>   Rechts.addActionListener( new knopHandlerRechts() );
> 
>   Links = new Button( "L" );
>   Links.addActionListener( new knopHandlerLinks() );
> 
>   add( Rechts );
>   add( Links );
>  }
>  public void paint( Graphics g )
>  {
>   cordinaten=100;
>   g.setColor ( Color.red );
>   g.fillOval( cordinaten, 100, 50, 50 );
> 
>  }
> 
>  class knopHandlerRechts implements ActionListener
>  {
>   public void actionPerformed( ActionEvent e )
>   {
>    cordinaten=+100;
>   }
>  }
> 
>  class knopHandlerLinks implements ActionListener
>  {
>   public void actionPerformed( ActionEvent e )
>   {
>    cordinaten=-100;
>   }
>  }
> 
> }
> 

1) In method paint wordt 'cordinaten' telkens gelijkgemaakt aan 100 !
Initialiseer cordinaten gelijk aan 100 in method init of geef cordinaten 
een waarde mee als je dit declareerd ( int cordinaten = 100;). En 
verwijder de eerste regel in method paint

2) in uw twee methods actionPerformed staat 'cordinaten =-100' en 
'cordinaten =+ 100'. ik vermoed dat dit 'cordinaten -= 100' en 
'cordinaten += 100' moet zijn !

3) in uw twee methods actionPerformed moet nog een aanroep naar de 
method 'repaint ()' gebeuren, anders wordt uw method paint niet 
opgeroepen. Doe 'repaint()' na aanpassing van cordinaten.

Vriendelijke groeten.

K
Technical Details
Message-ID: <va5kc.90426$SV7.5414964@phobos.telenet-ops.be>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!ecngs!feeder.ecngs.de!feed1.news.be.easynet.net!ossa.telenet-ops.be!phobos.telenet-ops.be.POSTED!not-for-mail
References: <4090ac1a$0$41763$5fc3050@dreader2.news.tiscali.nl>

Show Full Headers
Complete Article Headers
X-Google-Language: DUTCH,ASCII
X-Google-Thread: fcea4,568d2f06f1227321
X-Google-Attributes: gidfcea4,public
X-Google-ArrivalTime: 2004-04-29 03:55:23 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!ecngs!feeder.ecngs.de!feed1.news.be.easynet.net!ossa.telenet-ops.be!phobos.telenet-ops.be.POSTED!not-for-mail
From: Kristoffel <kdg1955@yahoo.com>
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040113
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: be.comp.programming
Subject: Re: wat is er fout in deze code?
References: <4090ac1a$0$41763$5fc3050@dreader2.news.tiscali.nl>
In-Reply-To: <4090ac1a$0$41763$5fc3050@dreader2.news.tiscali.nl>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
Lines: 81
Message-ID: <va5kc.90426$SV7.5414964@phobos.telenet-ops.be>
Date: Thu, 29 Apr 2004 10:55:23 GMT
NNTP-Posting-Host: 195.130.143.213
X-Complaints-To: abuse@telenet.be
X-Trace: phobos.telenet-ops.be 1083236123 195.130.143.213 (Thu, 29 Apr 2004 12:55:23 MEST)
NNTP-Posting-Date: Thu, 29 Apr 2004 12:55:23 MEST
Organization: Telenet Internet