commit 4bbf784b5ec16ce99adf8467a243b4f85b614b8d Author: Ulf Gebhardt Date: Sat Feb 27 10:36:58 2016 +0100 init commit diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..06c7b69 --- /dev/null +++ b/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..43603c0 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + StockTicker + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..e74acee --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +#Tue Jan 26 10:12:01 CET 2010 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/Stock Ticker.ump b/Stock Ticker.ump new file mode 100644 index 0000000..8ae7918 --- /dev/null +++ b/Stock Ticker.ump @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..85b6357 --- /dev/null +++ b/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project StockTicker. + + + diff --git a/build/built-jar.properties b/build/built-jar.properties new file mode 100644 index 0000000..fbef39e --- /dev/null +++ b/build/built-jar.properties @@ -0,0 +1,4 @@ +#Sat, 27 Feb 2016 10:30:33 +0100 + + +D\:\\sources\\ulf\ gebhardt\\java\\StockTicker= diff --git a/build/classes/.netbeans_automatic_build b/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/build/classes/.netbeans_update_resources b/build/classes/.netbeans_update_resources new file mode 100644 index 0000000..e69de29 diff --git a/build/classes/StockTicker$1.class b/build/classes/StockTicker$1.class new file mode 100644 index 0000000..b68814c Binary files /dev/null and b/build/classes/StockTicker$1.class differ diff --git a/build/classes/StockTicker.class b/build/classes/StockTicker.class new file mode 100644 index 0000000..c89b95c Binary files /dev/null and b/build/classes/StockTicker.class differ diff --git a/build/classes/StockTicker_Solution$1.class b/build/classes/StockTicker_Solution$1.class new file mode 100644 index 0000000..09ea808 Binary files /dev/null and b/build/classes/StockTicker_Solution$1.class differ diff --git a/build/classes/StockTicker_Solution.class b/build/classes/StockTicker_Solution.class new file mode 100644 index 0000000..f51e9fa Binary files /dev/null and b/build/classes/StockTicker_Solution.class differ diff --git a/dist/README.TXT b/dist/README.TXT new file mode 100644 index 0000000..7aeb8aa --- /dev/null +++ b/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "StockTicker.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/dist/StockTicker.jar b/dist/StockTicker.jar new file mode 100644 index 0000000..08cd0d2 Binary files /dev/null and b/dist/StockTicker.jar differ diff --git a/dist/lib/acm.jar b/dist/lib/acm.jar new file mode 100644 index 0000000..0548ea2 Binary files /dev/null and b/dist/lib/acm.jar differ diff --git a/libs/acm.jar b/libs/acm.jar new file mode 100644 index 0000000..0548ea2 Binary files /dev/null and b/libs/acm.jar differ diff --git a/manifest.mf b/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml new file mode 100644 index 0000000..0a2714a --- /dev/null +++ b/nbproject/build-impl.xml @@ -0,0 +1,1401 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties new file mode 100644 index 0000000..67a1bd7 --- /dev/null +++ b/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=f1c9156f +build.xml.script.CRC32=27859bb6 +build.xml.stylesheet.CRC32=8064a381@1.78.1.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=f1c9156f +nbproject/build-impl.xml.script.CRC32=5fc69be5 +nbproject/build-impl.xml.stylesheet.CRC32=2d327b5d@1.78.1.48 diff --git a/nbproject/private/.gitignore b/nbproject/private/.gitignore new file mode 100644 index 0000000..7b6be20 --- /dev/null +++ b/nbproject/private/.gitignore @@ -0,0 +1 @@ +/private.properties diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..d54554c --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,76 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processor.options= +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/StockTicker.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +file.reference.acm.jar=libs\\acm.jar +file.reference.StockTicker-src=src +includes=** +jar.compress=false +javac.classpath=\ + ${file.reference.acm.jar} +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.external.vm=true +javac.processorpath=\ + ${javac.classpath} +javac.source=1.8 +javac.target=1.8 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=StockTicker +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=${file.reference.StockTicker-src} diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..b526524 --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,13 @@ + + + org.netbeans.modules.java.j2seproject + + + StockTicker + + + + + + + diff --git a/src/StockTicker.java b/src/StockTicker.java new file mode 100644 index 0000000..b387037 --- /dev/null +++ b/src/StockTicker.java @@ -0,0 +1,261 @@ +import java.awt.Color; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.HashMap; +import java.util.Map; +import java.util.Vector; + +import javax.swing.Timer; + +import acm.graphics.GLabel; +import acm.graphics.GLine; +import acm.graphics.GPoint; +import acm.graphics.GRect; +import acm.program.GraphicsProgram; + +public class StockTicker extends GraphicsProgram { + + /** + * Solves a warning; not realy needed + */ + private static final long serialVersionUID = 1L; + + // maximum delay for timers to call updateTicker + private static final int MAX_DURATION = 5000; + + // the maximum value to expect + private static final int MAX_VALUE = 1000; + + // the number of calls to updateTicker + private static final int NR_TIMERS = 3000; + + // the maximum difference of old and new value + private static final int MAX_FLUCTUATION = 15; + + // the ticker symbols traded + private static final String[] SYMBOLS = new String[] { "SNC", "EKDD", + "ATD", "AGN", "HEDM" }; + + private Map oldPos; + + // we keep the timers in this collection to start them after init() + private Vector timers; + + // the appr. time when the timers were startes + private long startedAt; + + // the mapping of ticker symbols to colors + protected Map colors; + + /** + * Create a new StockTicker. + * + * This will instantiate all timers with their calls to updateTicker and put + * them into the timers collection. + */ + public StockTicker() + { + timers = new Vector(NR_TIMERS); + + final Map oldWorth = new HashMap(); + for (String symbol : SYMBOLS) + { + // start somewhere near MAX_VALUE/2 + oldWorth.put(symbol, MAX_VALUE * Math.random() / 2 + (MAX_VALUE / 4)); + } + for (int i = 0; i < NR_TIMERS; i++) + { + // instantiate a timer with a random delay within 0..MAX_DURATION + Timer timer = new Timer((int) (Math.random() * MAX_DURATION), + new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + // get a random ticker symbol + String symbol = SYMBOLS[(int) (Math.random() * SYMBOLS.length)]; + + // calculate the new worth + double newWorth = oldWorth.get(symbol) + + MAX_FLUCTUATION * 2 + * (Math.random() - 0.5); + + // do not increase beyond MAX_VALUE + if (newWorth > MAX_VALUE) { + newWorth -= MAX_FLUCTUATION; + } + // save the new value for next time + oldWorth.put(symbol, newWorth); + + updateTicker(symbol, newWorth); + } + }); + // only fire once + timer.setRepeats(false); + timers.add(timer); + } + + // pre-allocate the color mappings + colors = new HashMap(); + colors.put("SNC", Color.BLUE); + colors.put("EKDD", Color.ORANGE); + colors.put("ATD", Color.MAGENTA); + colors.put("AGN", Color.GRAY); + colors.put("HEDM", Color.RED); + + //initialize oldPos HashMap + oldPos = new HashMap(); + } + + /** + * Start the timers and set the startTime. + */ + public void startTicking() { + startedAt = System.currentTimeMillis(); + for (Timer timer : timers) { + timer.start(); + } + } + + /** + * Correct Height + * Delete this when acm is fixed + */ + @Override + public int getHeight() + { + return super.getHeight() - 30; + } + + /** + * Draw Interface: - Y-Axis + * - X-Lines every 50 pixel + * - Value of every line + * - White Rect + * - Names of TickerSymbols in right Color + */ + @Override + public void init() + { + { //draw horizontal line + GLine hline = new GLine(0,0,0,getHeight()); + add(hline); //draw it + } + + final int distance = 50; //50px distance between vlines + + { //draw vertical lines + for(int i=0; i <= (getHeight()/distance);i++) //lines + { + for(int j=0; j < (getWidth()/10);j++) //small lines every 10px with leght 5 + { + //many small lines per "line" + GLine vline = new GLine( j*10+1, //+1 to not override the x-achsis + getHeight()-i*distance, + j*10+5+1, + getHeight()-i*distance); + vline.setColor(Color.LIGHT_GRAY); //light-gray!!! + add(vline); //draw it + } + + //once per line + GLabel label = new GLabel( String.valueOf((int)(((double)MAX_VALUE/(double)getHeight())*i*distance)), + 3, + getHeight()-i*distance-2); + add(label); //draw it + } + } + + { //Draw white Rect + GRect rect = new GRect(getWidth()-120,0,120,120); + rect.setColor(Color.WHITE); //color + rect.setFilled(true); //do fill + add(rect); //draw it + } + + { //Draw Labels in Rect + for(int i=0;i < SYMBOLS.length; i++) + { + //new label with symbol + GLabel label = new GLabel(SYMBOLS[i],getWidth()-100,i*20+20); + //set the right color + label.setColor(colors.get(SYMBOLS[i])); //load color here + //draw it + add(label); + } + } + + // uncomment this line when you have implemented 6.3 - i have + startTicking(); + } + + /** + * Converts a X-Value relative to startedAt to an Pixel-Value + * relative to MAX_DURATION and Window-Width + * + * @param x X-Value relative to startedAT + * @return Pixel-Value which represents given X-Value + */ + public double XVal2XPix(double x) + { + //pixel_per_timepassed + return ((double)getWidth()/(double)MAX_DURATION)*x; + } + + /** + * Converts a Y-Value(worth) to an Pixel-Value + * relative to MAX_VALUE and Window-Height + * + * @param y Y-Value(worth) + * @return Pixel-Value which represents given Y-Value + */ + public double YVal2YPix(double y) + { + //pixel_per_valuepoint + return ((double)getHeight()/(double)MAX_VALUE)*y; + } + + /** + * Update the graph of a single ticker symbol. + * + * @param symbol A textual representation of the ticker symbol. + * @param worth The new worth of the company. + */ + public void updateTicker(String symbol, double worth) + { + //Calculate new Coordinates with time passed since start(x) and worth(y) + double x_val = XVal2XPix(System.currentTimeMillis() - startedAt); + double y_val = YVal2YPix(worth); + + //Get last Value of given ticker-symbol + GPoint oldgp = oldPos.get(symbol); + + //No old value stored at first call for every ticker-symbol + if(oldgp == null) + { + //create new Point with actual values instead + oldgp = new GPoint(x_val/*1*/,y_val);//x_val,y_val); + } + + //line from oldpos to newpos + GLine line = new GLine( oldgp.getX(), //oldpos + oldgp.getY(), + x_val, //newpos + y_val); + + //set the right color for every ticker-symbol + line.setColor(colors.get(symbol)); + + //paint it + add(line); + + //store new pos as oldpos for next call. + oldPos.put(symbol, new GPoint(x_val,y_val)); + } + + /** + * Instantiate a new StockTicker and start it. + */ + public static void main(String[] args) { + new StockTicker().start(args); + } + +} diff --git a/src/StockTicker_Solution.java b/src/StockTicker_Solution.java new file mode 100644 index 0000000..78b0de4 --- /dev/null +++ b/src/StockTicker_Solution.java @@ -0,0 +1,210 @@ +import java.awt.Color; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.HashMap; +import java.util.Map; +import java.util.Vector; + +import javax.swing.Timer; + +import acm.graphics.GLabel; +import acm.graphics.GLine; +import acm.graphics.GPoint; +import acm.graphics.GRect; +import acm.program.GraphicsProgram; + +public class StockTicker_Solution extends GraphicsProgram { + + /** + * + */ + private static final long serialVersionUID = 1866080068453559421L; + + // maximum delay for timers to call updateTicker + private static final int MAX_DURATION = 5000; + + // the maximum value to expect + private static final int MAX_VALUE = 1000; + + // the number of calls to updateTicker + private static final int NR_TIMERS = 3000; + + // the maximum difference of old and new value + private static final int MAX_FLUCTUATION = 15; + + // the ticker symbols traded + private static final String[] SYMBOLS = new String[] { "SNC", "EKDD", + "ATD", "AGN", "HEDM" }; + + // we keep the timers in this collection to start them after init() + private Vector timers; + + // the appr. time when the timers were startes + private long startedAt; + + // the mapping of ticker symbols to colors + protected Map colors; + + // + protected Map oldPos; + + /** + * Create a new StockTicker. + * + * This will instantiate all timers with their calls to updateTicker and put + * them into the timers collection. + */ + public StockTicker_Solution() { + timers = new Vector(NR_TIMERS); + + final Map oldWorth = new HashMap(); + for (String symbol : SYMBOLS) { + // start somewhere near MAX_VALUE/2 + oldWorth.put(symbol, MAX_VALUE * Math.random() / 2 + (MAX_VALUE / 4)); + } + for (int i = 0; i < NR_TIMERS; i++) { + // instantiate a timer with a random delay within 0..MAX_DURATION + Timer timer = new Timer((int) (Math.random() * MAX_DURATION), + new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + // get a random ticker symbol + String symbol = SYMBOLS[(int) (Math.random() * SYMBOLS.length)]; + + // calculate the new worth + double newWorth = oldWorth.get(symbol) + + MAX_FLUCTUATION * 2 + * (Math.random() - 0.5); + + // do not increase beyond MAX_VALUE + if (newWorth > MAX_VALUE) { + newWorth -= MAX_FLUCTUATION; + } + // save the new value for next time + oldWorth.put(symbol, newWorth); + + updateTicker(symbol, newWorth); + } + }); + // only fire once + timer.setRepeats(false); + timers.add(timer); + } + + // pre-allocate the color mappings + colors = new HashMap(); + colors.put("SNC", Color.BLUE); + colors.put("EKDD", Color.ORANGE); + colors.put("ATD", Color.MAGENTA); + colors.put("AGN", Color.GRAY); + colors.put("HEDM", Color.RED); + + oldPos = new HashMap(); + + } + + + /** + * Start the timers and set the startTime. + */ + public void startTicking() { + startedAt = System.currentTimeMillis(); + for (Timer timer : timers) { + timer.start(); + } + } + + @Override + public void init() { + // add your call to the methods from 6.2 here + GLine line_y = new GLine (0 , 0 , 0 , getHeight() ); + line_y.setColor(Color.black); + add(line_y); + + for (int i = 0; i < (getHeight() / 50) ; i++) + { + GLabel label = new GLabel (Integer.toString(MAX_VALUE - 100*(10-i)), 5 , getHeight() - (50*i + 5) ) ; + add(label); + for (int j = 0; j < (getWidth() / 8) ; j++) + { + GLine line_x = new GLine ( j * 8, getHeight() - (50 * i), j * 8 + 5, getHeight() - (50 * i)); + line_x.setColor(Color.gray); + add(line_x); + } + } + + GRect names = new GRect(getWidth()- 70,0,70,80); + names.setFillColor(Color.white); + names.setColor(Color.white); + names.setFilled(true); + add(names); + + + for (int i = 0 ; i < SYMBOLS.length ; i++) + { + GLabel symbols = new GLabel (SYMBOLS[i], getWidth() - 50 , 5 + ((i+1) * 10)); + symbols.setColor(colors.get(SYMBOLS[i])); + add(symbols); + } + + // uncomment this line when you have implemented 6.3 + startTicking(); + } + + private String InttoString(int maxValue) { + // TODO Auto-generated method stub + return null; + } + + /** + * Update the graph of a single ticker symbol. + * + * @param symbol A textual representation of the ticker symbol. + * @param worth The new worth of the company. + */ + public void updateTicker(String symbol, double worth) { + + + + + if (oldPos.containsKey(symbol)) { + + GLine stock = new GLine ( + oldPos.get(symbol).getX(), //old x + oldPos.get(symbol).getY(), //old y + (System.currentTimeMillis() - startedAt) * getWidth() / MAX_DURATION, //new x + getHeight () - (worth / 2));//new y + stock.setColor(colors.get(symbol)); + add(stock); + + oldPos.put(symbol, new GPoint ( + (System.currentTimeMillis() - startedAt) * getWidth()/ MAX_DURATION , + getHeight() - (worth / 2))); + } else + + { + GLine stock = new GLine(0, + getHeight() - (worth / 2), + (System.currentTimeMillis() - startedAt) * getWidth() / MAX_DURATION, + getHeight() - (worth / 2)); + stock.setColor(colors.get(symbol)); + add(stock); + + oldPos.put(symbol, new GPoint ( + (System.currentTimeMillis() - startedAt) * getWidth() / MAX_DURATION, + getHeight()- (worth / 2))); + } + + + } + + + + /** + * Instantiate a new StockTicker and start it. + */ + public static void main(String[] args) { + new StockTicker_Solution().start(args); + } + +}