import java.awt.*; import java.applet.Applet; /** * @title UK National Lottery number picker * @author John V. Keogh * @date 27.10.98. * @comment My third Java program! */ public class NatLot4 extends Applet { public void init () { setBackground(Color.cyan); } int[] nu = new int[6]; public void paint (Graphics g) { int match; for (int n=0; n<6; n++) { nu[n]=(int)(Math.random()*49)+1; } do { // generate 6 different numbers match=6; for (int n=1; n<6; n++) { for (int m=n-1; m>=0; m=m-1) { while (nu[n]==nu[m]) { nu[n]=(int)(Math.random()*49)+1; } match=match-1; } } } while (match > 0); for (int n=1; n<6; n++) { // sort for (int m=1; m<6; m++) { if (nu[m-1]>nu[m]) { match=nu[m-1]; nu[m-1]=nu[m]; nu[m]=match; } } } g.setColor(Color.blue); g.drawString(" JVK's LUCKY Number Picker ",10,10); g.setColor(Color.yellow); g.fillRect(0,15,190,20); g.setColor(Color.green); for (int n=0; n<6; n++) { g.fillOval((n*28)+8,16,19,19); } g.setColor(Color.black); for (int n=0; n<6; n++) { g.drawString(Integer.toString(nu[n]),(n*28)+10,30); } g.setColor(Color.red); g.drawString(" Press the mouse button here",10,50); g.drawString(" to pick another six numbers",10,61); } public boolean mouseDown(Event event,int x,int y) { repaint(); return true; } }