473,387 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Set Text ()

Please can you help. We've set defaults to a class employee & added data for each of the input form values 'age', 'dob', 'street' etc now we are asked to print void display for the values we have added . Have tried setText=P[0].age but this is not recognised, what is the syntax please to display the data we have read in onto the screen? All clues gratefully recieved
Mar 16 '07 #1
4 3679
horace1
1,510 Expert 1GB
Please can you help. We've set defaults to a class employee & added data for each of the input form values 'age', 'dob', 'street' etc now we are asked to print void display for the values we have added . Have tried setText=P[0].age but this is not recognised, what is the syntax please to display the data we have read in onto the screen? All clues gratefully recieved
don't think we have sufficent information - can you post the code where the problem is?
Mar 16 '07 #2
Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import java.io.*;
  4. class FormDemo extends CloseableFrame implements ActionListener, ItemListener
  5. {
  6.     private FileOutputStream outStream;
  7.     private PrintWriter outFile;
  8.     public boolean storeOpen;
  9.     public boolean fileOpen;
  10.     public boolean fileSaved;
  11.     Button closeButton, saveButton;
  12.     private MenuBar mb = new MenuBar();
  13.     private Menu menu1 = new Menu("File");
  14.     private Menu menu2 = new Menu("Record");
  15.     private MenuItem File,Record,New,Save,ReadIn,Add,Display,Clear;
  16.     TextField id,Start,Gender,Address,NatInsceNo,PhoneNo, Firstname,Surname,title,Dob,Age, number, street, city, postCode;
  17.     //Store[] myStore;
  18.     Employee[] P;
  19.     Employee P1;
  20.     int counter;
  21.  
  22.     public FormDemo(String fname) throws IOException
  23.     {
  24.         outStream = new FileOutputStream(fname);
  25.         outFile = new PrintWriter(outStream);
  26.         setTitle("Input Form");
  27.         setLayout(new BorderLayout());
  28.         setSize(545,450);
  29.         Panel top = new Panel(new FlowLayout(FlowLayout.CENTER));
  30.             top.add(new Label("Applicant Details"));
  31.         add("North",top);
  32.  
  33.         Panel mid = new Panel(new FlowLayout(FlowLayout.LEFT));        
  34.             mid.add(new Label ("id"));
  35.             id = new TextField("",5);
  36.             mid.add(id);
  37.             mid.add(new Label ("Start"));
  38.             Start = new TextField("",5);
  39.             mid.add(Start);
  40.  
  41.             mid.add(new Label ("Surname"));
  42.             Surname = new TextField("",5);
  43.             mid.add(Surname);
  44.             mid.add(new Label ("Firstname"));
  45.             Firstname = new TextField("",15);
  46.             mid.add(Firstname);
  47.             mid.add(new Label ("Age"));
  48.             Age = new TextField("",5);
  49.             mid.add(Age);
  50.             mid.add(new Label ("Gender"));
  51.             Gender = new TextField("",5);
  52.             mid.add(Gender);
  53.             mid.add(new Label("Dob"));
  54.             Dob = new TextField("",5);
  55.             mid.add(Dob);
  56.             mid.add(new Label ("Address"));
  57.             Address = new TextField("",5);
  58.             mid.add(Address);
  59.             mid.add(new Label ("NatInsceNo"));
  60.             NatInsceNo = new TextField("",5);
  61.             mid.add(NatInsceNo);
  62.             mid.add(new Label ("PhoneNo"));
  63.             PhoneNo = new TextField("",5);
  64.             mid.add(PhoneNo);
  65.             addMenu();
  66.         add("Center",mid);
  67.  
  68.         Panel lower = new Panel(new GridLayout (2,3));
  69.             closeButton = new Button("close");
  70.             saveButton = new Button("save");
  71.             saveButton.addActionListener(this);
  72.             lower.add(saveButton);
  73.             closeButton.addActionListener(this);
  74.             lower.add(closeButton);
  75.         add("South",lower);
  76.         setVisible(true);
  77.     }
  78.  
  79.     public void actionPerformed (ActionEvent e) 
  80.     {
  81.         if (e.getSource() == closeButton)
  82.         {
  83.         outFile.close();
  84.                 System.exit(0);    
  85.         }
  86.         if (e.getSource() == Save)
  87.         {    
  88.                 fileOut();
  89.         }
  90.         if(e.getSource()==Clear)
  91.         {
  92.             Storeit();
  93.         }
  94.        }
  95.         public void Storeit()
  96.         {
  97.           if(!storeOpen && !fileSaved)
  98.               {
  99.                    P = new Employee[100];
  100.                    storeOpen = true;
  101.                    fileSaved = true;
  102.                    counter=0;
  103.                 }
  104.             } 
  105.    private void clear()
  106.         {
  107. Surname.setText("");
  108. Firstname.setText("");
  109. Age.setText("");
  110. Gender.setText("");
  111. Dob.setText("");
  112. Address.setText("");
  113. NatInsceNo.setText("");
  114. PhoneNo.setText("");
  115.       }    
  116.  
  117.     private void add() 
  118.     {
  119.    if(storeOpen)
  120.    {
  121.    P1 =new Employee();
  122.    id.getText( );
  123.     Dob.getText(); 
  124.     Start.getText();
  125.     fileSaved =false;   
  126.     P[counter]=P1;
  127.     counter++;
  128.         } 
  129.     } 
  130.     private void display() 
  131.     {
  132.      displayText.setText(); 
  133.     text() = P[0].Start;
  134.          }
  135.           public void itemStateChanged (ItemEvent e)
  136.     {
  137.  
  138.     }
  139.  
  140.     public void fileOut() 
  141.     {
  142.  
  143.         outFile.println(number.getText()+" " + street.getText());
  144.         outFile.println(city.getText());
  145.         outFile.println(postCode.getText());
  146.  
  147.  
  148.     }
  149.      private void addMenu()
  150.         {
  151.               // creates each menu item with appropriate label
  152.  
  153.         New = new MenuItem("New");
  154.         Save = new MenuItem("Save");
  155.         ReadIn = new MenuItem("Readin");
  156.         Add = new MenuItem("Add");
  157.         Display = new MenuItem("Display");
  158.         Clear = new MenuItem("Clear");
  159.  
  160.         // adds each item to  menu1
  161.  
  162.         menu1.add(New);
  163.         menu1.add(Save);
  164.         menu1.add(ReadIn);
  165.         menu2.add(Add);
  166.         menu2.add(Display);
  167.         menu2.add(Clear);
  168.         //adds menu1 and menu2 to menu bar and adds menu bar to frame
  169.  
  170.         mb.add(menu1);
  171.         mb.add (menu2);
  172.         setMenuBar(mb);
  173.  
  174.         // sets upp actionlistener for each menu item
  175.  
  176.         New.addActionListener(this);
  177.         Save.addActionListener(this);
  178.         ReadIn.addActionListener(this);
  179.         Add.addActionListener(this);
  180.         Display.addActionListener(this);
  181.         Clear.addActionListener(this);
  182.  
  183.         }
  184. }
  185.  
The code seems to work up until private void display then it says it doesnt recognise the syntax getText to return the info we would have added to the
form. Could you help with this please.....the rest is OK. thANKS....
Mar 16 '07 #3
horace1
1,510 Expert 1GB
is displayText a TextArea? if so you use method append() to add a String to it
http://java.sun.com/j2se/1.4.2/docs/api/java/awt/TextArea.html
Mar 16 '07 #4
r035198x
13,262 8TB
Please can you help. We've set defaults to a class employee & added data for each of the input form values 'age', 'dob', 'street' etc now we are asked to print void display for the values we have added . Have tried setText=P[0].age but this is not recognised, what is the syntax please to display the data we have read in onto the screen? All clues gratefully recieved
setText takes a String as an argument. You have
Expand|Select|Wrap|Line Numbers
  1.  displayText.setText(); 
which takes nothing so that wont work.

Where didi you define displayText? It has to be a some component for that to work?
Mar 17 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: joes | last post by:
Hello there ! I rendering a PDF with XSLT using Xalan and FOP. I like to place in my article an image, so that the text is floating around the image. I tried several things but it didn't work so...
3
by: Xerxes | last post by:
Hi, I need help in setting up a page where the text wraps around an image. Right now, I am using table, with text in one <td> and the image in the adjacent <td>. The problem is when the text is...
2
by: Macsicarr | last post by:
Hi All Wonder if you could help me. I have created a CMS system that allows the user to enter text and pic 'tags' for their own About us page, eg text.... text.... text.... text.......
2
by: Jiri Palecek | last post by:
I have a question on web authoring (probably HTML+CSS). Is it somehow possible to put two words above each other inside a paragraph so the result would be valid and render at least in Mozilla? I...
4
by: Arif Çimen | last post by:
Hi to everybody, I have chnged a button text in design mode. But After compiling and executing the program the text of the button do not change to new value. Any Ideas? Thaks for helps.
3
by: jweinberg1975 | last post by:
I would like for users to be able to select from a small number of options that come from a little drop down menu which then closes. .....
3
by: bbepristis | last post by:
Hey all I have this code that reads from one text file writes to another unless im on a certian line then it writes the new data however it only seems to do about 40 lines then quits and I cant...
3
by: acecraig100 | last post by:
I am fairly new to Javascript. I have a form that users fill out to enter an animal to exhibit at a fair. Because we have no way of knowing, how many animals a user may enter, I created a table...
3
by: jonniethecodeprince | last post by:
Hi all, I have trouble getting an array of data stored in a separate javascript file i.e. a file called books.js into a table of data for a .xhtml file. There are 50 Records in this file....
10
by: bluemountain | last post by:
Hi there, Iam new to python forms and programming too I had a text file where i need to extract few words of data from the header(which is of 3 lines) and search for the keyword TEXT1, TEXT2,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.