This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Can someone help me with this code. The stock tracker is supposed to start the grapher when numbers are entered.
Stock Tracker code:
/** * StockTracker.java * * StockTracker Application built with AWT components * * The Stock Tracker charts the price movements of a particular * ASX share after the user enters the ASX code, buying price and * the quantity purchased. The user can start the tracker with the * BUY button. The tracker plots a graph based on generating random * prices and simultaneously displays status information such as * running totals of profit and prices. The user can buy, sell suspend * and resume the trading of their shares. The user can trigger a * status report displaying details of their purchase and profit at * any point in time. * @author Stefan Batsas * @version 1.00 2005-08-30 * */
// initialise price field txtPrice = new TextField(5); //txtPrice.setHorizontalAlignment(TextField.RIGHT); txtPrice.addKeyListener(this);
// initialise quantity field txtQuantity = new TextField(5); //txtQuantity.setHorizontalAlignment(TextField.RIGHT); txtQuantity.addKeyListener(this);
// initialise buy button btnBuy = new Button("Buy"); btnBuy.addActionListener(this);
// initialise sell button btnSell = new Button("Sell"); btnSell.addActionListener(this);
// initialise suspend button btnSuspend = new Button("Suspend"); btnSuspend.addActionListener(this);
btnResume = new Button("Resume"); btnResume.addActionListener(this);
// initialise reset button btnReset = new Button("Reset"); btnReset.addActionListener(this);
// initialise current price label lblCurrentPrice = new Label("0.00"); lblCurrentPrice.setForeground(Color.RED);
// initialise profit label lblProfit = new Label("0.00"); lblProfit.setForeground(Color.RED);
// initialise stock name label lblStockName = new Label(" "); lblStockName.setForeground(Color.RED);
//------------------------------------------- // initialise grapher | // set the seed of grapher to 0.5 | //-------------------------------------------
/** * initialise timer that controls status info * Anonymous ActionListener created as argument */
/** * Implementing ItemListener interface * for Choice component. Choice component does not fire action events * respond to Choice selection to set asx stock code */ public void itemStateChanged(ItemEvent e){ asxcode = (String)((Choice)e.getSource()).getSelectedItem();
// Get the unicode value int key = e.getKeyCode();
if(key == VK_ENTER||key == VK_DOWN){ // Constants available via static import // Enter key moves cursor to next field ((TextField)e.getSource()).transferFocus();
/** * Grapher.java * *The Grapher class is a Java Canvas component; The Canvas class * is a suitable component for drawing or rendering graphics. It will * be used to plot the share price graph. The Grapher should plot the * share price using a random price generator, store the initial buy price, * the current price and calculate the current profit as the graph is plotted. * The graph animation should be controlled with a timer thread that can * be started, stopped and restarted. * * * @author Stefan Batsas * @version 1.00 2005-08-30 */
public class Grapher extends Canvas implements ActionListener {
/** Timer thread that calls repaint to plot stock price graph */ private Timer timer;
/** The current share price */ private double price;
/** x co-ordinate denotes period in time to graph */ private int xpos;
/** y co-ordinate denotes current price to graph */ private int ypos;
/** * delta is
Martin Simons
Ranch Hand
Joined: Mar 02, 2006
Posts: 196
posted
0
That's a lot of code without any real question being posted with it.
What, exactly, is your question/problem? Are you getting an exception? Are you confused how to open a specific Panel/Frame?
jimmy siljanoski
Greenhorn
Joined: May 28, 2006
Posts: 4
posted
0
This is the grapher code:
/** * Grapher.java * *The Grapher class is a Java Canvas component; The Canvas class * is a suitable component for drawing or rendering graphics. It will * be used to plot the share price graph. The Grapher should plot the * share price using a random price generator, store the initial buy price, * the current price and calculate the current profit as the graph is plotted. * The graph animation should be controlled with a timer thread that can * be started, stopped and restarted. * * * @author Stefan Batsas * @version 1.00 2005-08-30 */
/** * @return current price * */ public double getPrice(){
return price;
} // getPrice
/** * @param price * sets the current price * */ public void setPrice(double price){
this.price = price;
} // setBuyPrice
/** * @param seed * sets the seed value at start */ public void setSeed(double seed){
this.seed = seed;
} // setSeed
/** * @param x, y coordinates * sets the x and y coordinates where graph begins on canvas */ public void setStartXY(int x, int y){ xpos = x; ypos = y;
} // setStart
/** * @param delta - the y change in pixels * */ public void setDelta(int delta){ this.delta = delta; }
} // Grapher
I'm supposed to create a stock tracker program. Most of the code is there all that has to be done is be modified. The modification points are where the comments are placed telling you what to do. Hope it makes it a little clearer. Your help will be much appreciated.
Ernest Friedman-Hill
author and iconoclast
Marshal
We don't do homework for people -- we help them learn to do their own. If I see someone posting homework answers, I will actually delete the posts. Now, if you have a specific question about Java, we'll be happy to answer it or help you to find the answer. But "Some help" isn't a question and we won't try to answer it.
Its not my homework. My mate gave me this code because they are making him do some java in his IT course for no reason. All he wants to do is pass it not excel at it because he will never use it again.
If you cant help than maybe you can answer these questions:
What is object oriented programming? Where do you place definitions for data fields in a class? Why are radio buttons added to a button group? What is a java interface? Definitions of private and public? Which object created at runtime is responsible for rendering your Frame object? What class would you use to display a Message Dialog Box for YES or NO confirmation?
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
> All he wants to do is pass it not excel at it because he will never use it again.
I hope he fails...
at everything he does.
jimmy siljanoski
Greenhorn
Joined: May 28, 2006
Posts: 4
posted
0
All i wanted was some help but it appears that people here are unnecessarily rude and arrogant.
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35247
7
posted
0
It doesn't matter much whether it's your homework or your buddys - what Ernest said still aplies. And it's not a very appealing proposition to try to help someone who doesn't want to learn, just get it over with.
You're right that Michaels comment is certainly borderline in regard to the "Be Nice" rule.
> You're right that Michaels comment is certainly borderline in regard to the "Be Nice" rule.
nice to fellow ranchers, no probs
nice to those who are even too lazy to post their own request for a handout - never..... :-)
jimmy siljanoski
Greenhorn
Joined: May 28, 2006
Posts: 4
posted
0
/** * StockTracker.java * * StockTracker Application built with AWT components * * The Stock Tracker charts the price movements of a particular * ASX share after the user enters the ASX code, buying price and * the quantity purchased. The user can start the tracker with the * BUY button. The tracker plots a graph based on generating random * prices and simultaneously displays status information such as * running totals of profit and prices. The user can buy, sell suspend * and resume the trading of their shares. The user can trigger a * status report displaying details of their purchase and profit at * any point in time. * @author Stefan Batsas * @version 1.00 2005-08-30 * */
// initialise price field txtPrice = new JTextField(5); //txtPrice.setHorizontalAlignment(JTextField.RIGHT); txtPrice.addKeyListener(this);
// initialise quantity field txtQuantity = new JTextField(5); //txtQuantity.setHorizontalAlignment(JTextField.RIGHT); txtQuantity.addKeyListener(this);
// initialise buy button btnBuy = new JButton("Buy"); btnBuy.addActionListener(this);
// initialise sell button btnSell = new JButton("Sell"); btnSell.addActionListener(this);
// initialise suspend button btnSuspend = new JButton("Suspend"); btnSuspend.addActionListener(this);
btnResume = new JButton("Resume"); btnResume.addActionListener(this);
// initialise reset button btnReset = new JButton("Reset"); btnReset.addActionListener(this);
// initialise current price label lblCurrentPrice = new JLabel("0.00"); lblCurrentPrice.setForeground(Color.RED);
// initialise profit label lblProfit = new JLabel("0.00"); lblProfit.setForeground(Color.RED);
// initialise stock name label lblStockName = new JLabel(" "); lblStockName.setForeground(Color.RED);
//------------------------------------------- // initialise grapher | // set the seed of grapher to 0.5 | //-------------------------------------------
grapher = new Grapher(); grapher.setSeed(0.5);
/** * initialise timer that controls status info * Anonymous ActionListener created as argument */
/** * Implementing ItemListener interface * for JComboBox component. JComboBox component does not fire action events * respond to JComboBox selection to set asx stock code */ public void itemStateChanged(ItemEvent e){ asxcode = (String)((JComboBox)e.getSource()).getSelectedItem();
// Get the unicode value int key = e.getKeyCode();
if(key == VK_ENTER||key == VK_DOWN){ // Constants available via static import // Enter key moves cursor to next field ((JTextField)e.getSource()).transferFocus();