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!
*/
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!