Im a 15 year old noob to java. I am trying to make a basic program trader that asks for the stock price, the stock name, the stock market value and the type of order. Based on the type of order, i want a new textfield to appear. do i have to add the textfield in the init first or can i do it in the action performed. I googled someother ones but they are a little too complicated for me. heres my code.
import java.awt.*;
import java.applet.*;
// import an extra class for the ActionListener
import java.awt.event.*;
public class mathFair extends Applet implements ActionListener
{
TextField stockPrice2;
TextField stockName2;
TextField orderType2;
TextField marketValue2;
TextField buyOrder2;
TextField sellOrder2;
TextField limitOrder2;
TextField stopLossOrder2;
Label stockPrice1;
Label stockName1;
Label orderType1;
Label marketValue1;
Label buyOrder1;
Label sellOrder1;
Label limitOrder1;
Label stopLossOrder1;
Button calculate;
public void init()
{
stockPrice1 = new Label ("Enter Stock Price:");
stockName1 = new Label ("Enter Name of Stock: ");
orderType1 = new Label ("Enter Type of Order: 1 for Buy, 2 for Sell, 3 for Stop Loss, 4 for Limit");
marketValue1= new Label("Enter The Current Price Of The Market");
stopLossOrder1 = new Label ("Enter The Lowest Price The Stock Can Go");
limitOrder1 = new Label ("Enter The Highest Price The Stock Can Go");
stockPrice2 = new TextField (35);
stockName2 = new TextField (35);
orderType2 = new TextField (35);
marketValue2= new TextField(35);
calculate= new Button("Start The Simulation");
add (stockPrice1);
add (stockPrice2);
add (stockName1);
add (stockName2);
add (marketValue1);
;
add(marketValue2);
add (orderType1);
add (orderType2);
add(calculate);
;
calculate.addActionListener(this);
}
public void actionPerformed (ActionEvent e)
{
String stock= stockPrice2.getText();
int stockPrice= Integer.parseInt(stock);
stockPrice2.setText(stockPrice +"");
String marketV= marketValue2.getText();
int marketValue= Integer.parseInt(marketV);
marketValue2.setText(marketValue+"");
String orderT= orderType2.getText();
int orderType= Integer.parseInt(orderT);
orderType2.setText(orderType+"");
if((e.getSource()==calculate)&& (orderType==1))
{
buyOrder2= new TextField(35);
buyOrder1 = new Label("Enter Price You Would Like To Buy At");
add(buyOrder2);
add(buyOrder1);
}
else
if((e.getSource()==calculate)&& (orderType==2))
{
sellOrder2= new TextField(35);
sellOrder1 = new Label("Enter Price You Would Like To Sell At");
add(sellOrder2);
add(sellOrder1);
}
else
if((e.getSource()==calculate)&& (orderType==3))
{
stopLossOrder2= new TextField(35);
stopLossOrder1=new Label("Enter The Lowest Price The Stock Can Go");
add(stopLossOrder2);
add(stopLossOrder1);
}
else
if((e.getSource()==calculate)&& (orderType==4))
{
limitOrder2=new TextField(35);
limitOrder1= new Label("Enter the Highest Price The Stock Can Go");
add(limitOrder2);
add(limitOrder1);;
}
}
}