Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please help me with arrays.

Status
Not open for further replies.

chrisbet

Programmer
Nov 13, 2002
1
0
0
US
I am having great trouble putting an array on this script. I need it so that repeated numbers do not occur. I am self-teaching and very new so the more detail the better.

*/

import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;

public class Random extends Applet implements ActionListener {

static final int TOTAL = 6, BASE=49;


//Define the button

Button pushButton = new Button ("Start the Lottery!");

int targetNumi = (int)(BASE*Math.random()+1);

//Create somewhere to remember which button was last pressed
Button lastButton = null;

// Add a label to write a response into - note the extra spaces here...
Label responseLabel = new Label("To start the lottery, press here :");


public void init() {
// Set the layout to look nice(ish)
//this.setLayout(new GridLayout(4,0,20,20));

//Initialise the button

pushButton.addActionListener(this);

// Add the label to the window
add(responseLabel);


//Now add the button
add(pushButton);}

public void paint(Graphics g) {

// Change the label text according to which button was pressed
if (lastButton==pushButton) {

String numberStatusi = targetNumi + " is ball number" +1;



g.drawString(numberStatusi, 20, 50);

}

}
// actionPerformed runs when any event occurs...

public void actionPerformed(ActionEvent e) {
// if a button was pressed...
if (e.getSource() instanceof Button) {

//set lastButton to whichever one it was
if (e.getSource()==pushButton) {
lastButton = pushButton;
} else {
lastButton = null;
}

// force the window to be repainted
repaint();




}

}

}




Thank you for your help!
 
Want to excuse me but it is probably a french to french problem and it is far easier for me to write in my mom's language :)

=================================================
Bonjour,
tu veux jouer au loto ?
il faut
1) définir un tableau de 6 positions :
int tableau[6] ;
2) une méthode qui cherche un entier dans ce tableau :
boolean serach( int tab[] , int x )
{
}
3) Appeler cette fonction après chaque tirage aléatoire et si elle renvoie true recommencer le tirage.

Et Voila !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top