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
Set Text ()
Collapse
X
-
Tags: None
-
don't think we have sufficent information - can you post the code where the problem is?Originally posted by lenin42001Please 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 -
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 theCode:import java.awt.*; import java.awt.event.*; import java.io.*; class FormDemo extends CloseableFrame implements ActionListener, ItemListener { private FileOutputStream outStream; private PrintWriter outFile; public boolean storeOpen; public boolean fileOpen; public boolean fileSaved; Button closeButton, saveButton; private MenuBar mb = new MenuBar(); private Menu menu1 = new Menu("File"); private Menu menu2 = new Menu("Record"); private MenuItem File,Record,New,Save,ReadIn,Add,Display,Clear; TextField id,Start,Gender,Address,NatInsceNo,PhoneNo, Firstname,Surname,title,Dob,Age, number, street, city, postCode; //Store[] myStore; Employee[] P; Employee P1; int counter; public FormDemo(String fname) throws IOException { outStream = new FileOutputStream(fname); outFile = new PrintWriter(outStream); setTitle("Input Form"); setLayout(new BorderLayout()); setSize(545,450); Panel top = new Panel(new FlowLayout(FlowLayout.CENTER)); top.add(new Label("Applicant Details")); add("North",top); Panel mid = new Panel(new FlowLayout(FlowLayout.LEFT)); mid.add(new Label ("id")); id = new TextField("",5); mid.add(id); mid.add(new Label ("Start")); Start = new TextField("",5); mid.add(Start); mid.add(new Label ("Surname")); Surname = new TextField("",5); mid.add(Surname); mid.add(new Label ("Firstname")); Firstname = new TextField("",15); mid.add(Firstname); mid.add(new Label ("Age")); Age = new TextField("",5); mid.add(Age); mid.add(new Label ("Gender")); Gender = new TextField("",5); mid.add(Gender); mid.add(new Label("Dob")); Dob = new TextField("",5); mid.add(Dob); mid.add(new Label ("Address")); Address = new TextField("",5); mid.add(Address); mid.add(new Label ("NatInsceNo")); NatInsceNo = new TextField("",5); mid.add(NatInsceNo); mid.add(new Label ("PhoneNo")); PhoneNo = new TextField("",5); mid.add(PhoneNo); addMenu(); add("Center",mid); Panel lower = new Panel(new GridLayout (2,3)); closeButton = new Button("close"); saveButton = new Button("save"); saveButton.addActionListener(this); lower.add(saveButton); closeButton.addActionListener(this); lower.add(closeButton); add("South",lower); setVisible(true); } public void actionPerformed (ActionEvent e) { if (e.getSource() == closeButton) { outFile.close(); System.exit(0); } if (e.getSource() == Save) { fileOut(); } if(e.getSource()==Clear) { Storeit(); } } public void Storeit() { if(!storeOpen && !fileSaved) { P = new Employee[100]; storeOpen = true; fileSaved = true; counter=0; } } private void clear() { Surname.setText(""); Firstname.setText(""); Age.setText(""); Gender.setText(""); Dob.setText(""); Address.setText(""); NatInsceNo.setText(""); PhoneNo.setText(""); } private void add() { if(storeOpen) { P1 =new Employee(); id.getText( ); Dob.getText(); Start.getText(); fileSaved =false; P[counter]=P1; counter++; } } private void display() { displayText.setText(); text() = P[0].Start; } public void itemStateChanged (ItemEvent e) { } public void fileOut() { outFile.println(number.getText()+" " + street.getText()); outFile.println(city.getText()); outFile.println(postCode.getText()); } private void addMenu() { // creates each menu item with appropriate label New = new MenuItem("New"); Save = new MenuItem("Save"); ReadIn = new MenuItem("Readin"); Add = new MenuItem("Add"); Display = new MenuItem("Display"); Clear = new MenuItem("Clear"); // adds each item to menu1 menu1.add(New); menu1.add(Save); menu1.add(ReadIn); menu2.add(Add); menu2.add(Display); menu2.add(Clear); //adds menu1 and menu2 to menu bar and adds menu bar to frame mb.add(menu1); mb.add (menu2); setMenuBar(mb); // sets upp actionlistener for each menu item New.addActionListener(this); Save.addActionListener(this); ReadIn.addActionListener(this); Add.addActionListener(this); Display.addActionListener(this); Clear.addActionListener(this); } }
form. Could you help with this please.....the rest is OK. thANKS....Comment
-
setText takes a String as an argument. You haveOriginally posted by lenin42001Please 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
which takes nothing so that wont work.Code:displayText.setText();
Where didi you define displayText? It has to be a some component for that to work?Comment
Comment