Java .

Java Random DJIA Stock Applet

Random DJIA Stock Applet

import java.awt.*;

public class RandomDJIA extends java.applet.Applet { Font f = new Font("TimesRoman", Font.BOLD, 36); Font f2 = new Font("TimesRoman", Font.BOLD, 12); String s1; String s2; int i1 = 30; Button fortune = new Button("Press This Button for a Random DJIA Stock");

public void init() { setBackground(Color.white); add(fortune); }

public boolean action(Event evt, Object arg) { if(evt.target.equals(fortune)) repaint(); return true; }

public void paint(Graphics screen) { switch (i1) { case 1: s1 = "AA Alcola"; break; case 2: s1 = "AXP American Express"; break; case 3: s1 = "BA Boeing"; break; case 4: s1 = "C Citigroup"; break; case 5: s1 = "CAT Caterpillar"; break; case 6: s1 = "DD E.I. DuPont"; break; case 7: s1 = "DIS Disney"; break; case 8: s1 = "EK Eastman Kodak"; break; case 9: s1 = "GE General Electric"; break; case 10: s1 = "GM General Motors"; break; case 11: s1 = "HD Home Depot"; break; case 12: s1 = "HON Honeywell"; break; case 13: s1 = "HWP Hewlett-Packard"; break; case 14: s1 = "IBM IBM"; break; case 15: s1 = "INTC Intel"; break; case 16: s1 = "IP International Paper"; break; case 17: s1 = "JNJ Johnson & Johnson"; break; case 18: s1 = "JPM J.P. Morgan Chase"; break; case 19: s1 = "KO Coca Cola"; break; case 20: s1 = "MCD McDonald's"; break; case 21: s1 = "MMM 3M"; break; case 22: s1 = "MO Phillip Morris"; break; case 23: s1 = "MRK Merk"; break; case 24: s1 = "MSFT Microsoft"; break; case 25: s1 = "PG Proctor & Gamble"; break; case 26: s1 = "SBC SBC Communications"; break; case 27: s1 = "T AT&T"; break; case 28: s1 = "UTX United Technology"; break; case 29: s1 = "WMT Wal-Mart"; break; case 30: s1 = "XOM Exxon Mobil"; break; case 31: s1 = "Press Button for a Random DJIA Stock"; break; }

screen.setFont(f); FontMetrics fm = getFontMetrics(f); screen.setColor(Color.black); int x = (getSize().width - fm.stringWidth(s1)) / 2; screen.drawString(s1, x, 100);

screen.setFont(f2); s2 = "Copyright 1999-2002 Lawrence Truett & FluffyCat.com"; screen.drawString(s2, 100, 175);

Integer r1 = new Integer((int)(Math.random() * 30)); i1 = r1.intValue(); }

}
To download source right-click here and "Save As...".
Run the Applet in a new window
Comments
Sign in to be the first to comment on Java Random DJIA Stock Applet.