Results 1 to 2 of 2
Thread: adding textfields
- 12-27-2010, 10:04 PM #1
Member
- Join Date
- Dec 2010
- Posts
- 1
- Rep Power
- 0
adding textfields
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.
Java 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);; } } }
- 12-28-2010, 03:56 AM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
Similar Threads
-
How to validate textfields if data is modifier
By sasi.tati in forum AWT / SwingReplies: 1Last Post: 07-26-2010, 09:10 AM -
Show/Hide Textfields in Struts 2 form
By aruna.hcu in forum Web FrameworksReplies: 3Last Post: 07-08-2010, 03:36 PM -
Buttons and TextFields
By Xystus777 in forum New To JavaReplies: 27Last Post: 03-17-2009, 01:26 AM -
How can I place Buttons and TExtfields within an Applet window?
By sergioTOOL in forum JCreatorReplies: 0Last Post: 02-11-2009, 11:12 PM -
information from a textfields
By bbq in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 06-28-2007, 05:28 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks