Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Hallo,

das ist mein erster Beitrag.

Also ich möchte in einem Spielautomat, (drei "Lampen", die sich drehen)

einen Button einbauen mit dem ich diese Drehung "triggern" kann.

Ich hab schon versucht mich mit Hilfe von Google usw. zu informieren, kam aber zu keiner Lösung.

Hier jetzt mal der Quelltext. Vielen Dank :D


import java.util.Random;


public class SPIELAUTOMAT

{


    private SPIELWALZE spielwalze1, spielwalze2, spielwalze3;

    private int z1,z2,z3;

    private Random zufall;


    public SPIELAUTOMAT()

    {

        zufall = new Random();

        z1 = 0;

        z2 = 0;

        z3 = 0;

        spielwalze1 = new SPIELWALZE (20, 50,150, z1);

        spielwalze2 = new SPIELWALZE (170, 50, 150,z2);

        spielwalze3 = new SPIELWALZE (320, 50,150, z3);

    }


    private void setzeFarbmuster(int z1Neu, int z2Neu, int z3Neu)

    {

        z1 = z1Neu;

        z2 = z2Neu;

        z3 = z3Neu;

        spielwalze1.faerbeUm(z1);

        spielwalze2.faerbeUm(z2);

        spielwalze3.faerbeUm(z3);

    }


    private void zeichne()

    {    

        spielwalze1.zeichne();

        spielwalze2.zeichne();

        spielwalze3.zeichne();

    }


    private void drehen()

    { 

        setzeFarbmuster (zufall.nextInt(9), zufall.nextInt(9),zufall.nextInt(9));


    }


    public void spiele()

    {  

        int i;

        int summe;        

        zeichne();

        summe=0;


        for (i=1; i <=20; i++)

        {

            drehen(); 

        }

        summe=summe + i;


        if (z1==z2 && z3==z2)

        { 

            System.out.println ("Hauptgewinn!");

        }


        if (z1==z2 || z1==z3 || z2==z3 )

        {

            System.out.println ("Kleiner Gewinn!");

        }

    }


}

Bearbeitet von flashpixx
Code-Tags

Für den Button musst du die Packete

-java.awt

-java.awt.event

importieren.

dann musst du den Button natürlich auch definieren und Konstruieren... D.h.

public class SPIELAUTOMAT

{

private Button b1(b1 ist der Name für den Button);

public SPIELAUTOMAT

{

b1= new Button(Triggern);

}

in der Klammer steht was auf dem Button angezeigt werden soll

Greetz

Steven

Ich weiß, man sollte sowas net sagen, aber ich rate dir, den Kommentar über mir zu ignorieren, AWT als was altes, böses abzulegen und dir Ein (sehr) kleines Swing Tutorial anzuschaun.

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.