Article View: be.comp.programming
Article #2400probleem met switch statment met methode.( java)
From: Gekkie
Date: Fri, 11 Jun 2004 07:53
Date: Fri, 11 Jun 2004 07:53
129 lines
4332 bytes
4332 bytes
Hallo,
hier onder ziet u mijn code die ik heb gebruikt voor een dobbelsteen maar
hoe moet ik de ogen laten zien van de dobbelsteen. Ik heb hierbij gebruik
gemaakt van een switch statment gebruikt.
maar blijkbaar zit daar iets fout of zo omdat hij die niet laat zien.
Kan er iemand mij de code voor geven om dit probleem op te lossen.
Ik dank u bij voorbaat
Gekkie
file://Hs09_Vr06.java 1.0
// Dobbelsteen. Maak een klasse voor een dobbelsteen. Bedenk welke atributen
een dobbelsteen
// heeft om een bepaalde worp op het scherm te kunnen laten zien. Geef de
klasse een
// constructor, een methode public int werp() waarmee random het aantal ogen
wordt bepaald,
// en een methode public void teken( Graphics g ) om een dobbelsteen te
kunnen tekenen.
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class Hs09_Vr06 extends Applet
{
Dobbelsteen dobbelsteen1;
Button knop;
public void init()
{
dobbelsteen1 = new Dobbelsteen( Color.black, 50, 20, 100, 100 );
knop = new Button ( "Gooi" );
knop.addActionListener( new KnopHandler() );
add( knop );
}
public void paint( Graphics g )
{
dobbelsteen1.teken( g );
}
class KnopHandler implements ActionListener
{
public void actionPerformed( ActionEvent e )
{
dobbelsteen1.worp();
repaint();
}
}
}
class Dobbelsteen
{
private Color kleur;
private int xOog = 15;
private int yOog = 15;
private int xDobbel;
private int yDobbel;
private int Basis;
private int Hoogte;
public Dobbelsteen( Color kleur, int xDobbel, int yDobbel, int Basis, int
Hoogte )
{
this.kleur = kleur;
file://this.xOog = xOog;
file://this.yOog = yOog;
this.xDobbel = xDobbel;
this.yDobbel = yDobbel;
this.Basis = Basis;
this.Hoogte = Hoogte;
}
public int worp()
return (int) (6 * Math.random() + 1);
}
public void teken( Graphics g )
{
g.setColor( this.kleur );
g.fillRoundRect( this.xDobbel, this.yDobbel, this.Basis, this.Hoogte, 30,
30);
switch ( worp() )
{
case 1: g.fillOval( 90, 65, this.xOog, this.yOog );
break;
case 2: g.fillOval( 60, 35, this.xOog, this.yOog );
g.fillOval( 120, 95, this.xOog, this.yOog );
break;
case 3: g.fillOval( 60, 35, this.xOog, this.yOog );
g.fillOval( 90, 65, this.xOog, this.yOog );
g.fillOval( 120, 95, this.xOog, this.yOog );
break;
case 4: g.fillOval( 60, 35, this.xOog, this.yOog );
g.fillOval( 120, 35, this.xOog, this.yOog );
g.fillOval( 60, 95, this.xOog, this.yOog );
g.fillOval( 120, 95, this.xOog, this.yOog );
break;
case 5: g.fillOval( 60, 35, this.xOog, this.yOog );
g.fillOval( 120, 35, this.xOog, this.yOog );
g.fillOval( 90, 65, this.xOog, this.yOog );
g.fillOval( 60, 95, this.xOog, this.yOog );
g.fillOval( 120, 95, this.xOog, this.yOog );
break;
case 6: g.fillOval( 70, 35, this.xOog, this.yOog );
g.fillOval( 110, 35, this.xOog, this.yOog );
g.fillOval( 70, 65, this.xOog, this.yOog );
g.fillOval( 110, 65, this.xOog, this.yOog );
g.fillOval( 70, 95, this.xOog, this.yOog );
g.fillOval( 110, 95, this.xOog, this.yOog );
break;
}
}
}
Technical Details
Message-ID:
<40c964b2$0$41753$5fc3050@dreader2.news.tiscali.nl>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsrout1.ntli.net!news-in.ntli.net!newsfeed.wirehub.nl!newshub3.home.nl!newshub2.home.nl!home.nl!amsnews01.chello.com!newsfeeder.wxs.nl!transit.news.xs4all.nl!195.241.76.212.MISMATCH!tiscali!transit1.news.tiscali.nl!dreader2.news.tiscali.nl!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: DUTCH,ASCII-7-bit X-Google-Thread: fcea4,77f17db311924003,start X-Google-Attributes: gidfcea4,public Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsrout1.ntli.net!news-in.ntli.net!newsfeed.wirehub.nl!newshub3.home.nl!newshub2.home.nl!home.nl!amsnews01.chello.com!newsfeeder.wxs.nl!transit.news.xs4all.nl!195.241.76.212.MISMATCH!tiscali!transit1.news.tiscali.nl!dreader2.news.tiscali.nl!not-for-mail From: "Gekkie" <emiel.rutten@tiscali.be> Newsgroups: be.comp.programming Subject: probleem met switch statment met methode.( java) Date: Fri, 11 Jun 2004 09:53:03 +0200 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2919.6700 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700 Lines: 131 Message-ID: <40c964b2$0$41753$5fc3050@dreader2.news.tiscali.nl> Organization: Tiscali bv NNTP-Posting-Date: 11 Jun 2004 09:52:18 CEST NNTP-Posting-Host: 83.134.127.161 X-Trace: 1086940338 dreader2.news.tiscali.nl 41753 83.134.127.161:1430 X-Complaints-To: abuse@tiscali.nl