Wednesday 15 July 2015

java - Values user inputs into a GUI are not saving? -


Below is the code I'm working on. Actually I need a box to open and the user gets to input my data in this text field. Everything is working great, everything is being output correctly when I print it with functional method, but when I call the gi.displayPersonInfo method from the main, it shows all values ​​as zero. This box has been opened in the past, although I have been doing this display PersonInfo method before calling the method. Anyone know what is wrong in my code? (Output below)

  Package user input; Import javax.swing.JFrame; Import java.awt. *; Import javax.swing *; Import java.awt.event. *; Public Sector Person JFrame {String Name; String address; String Phonenom Holmes; String phonemonework; String email; JLable label, label 2; JTextField tf1, tf2, tf3, tf4, tf5, tf6, tf7, tf8; Button button; Public person () {setLayout (new flow layout ()); Label = new jlabel ("enter your name"); (Label); Tf1 = new JTextField (10); Add (TF1); Label = new JLabel ("Enter your address (street number + street name)"); (Label); Tf2 = new JTextField (10); Add (TF2); Label = new JLabel ("Enter your city"); (Label); Tf3 = new JTextField (10); Add (TF3); Label = new JLabel ("Enter your province"); (Label); Tf4 = new JTextField (10); Add (tf4); Label = new jlabel ("enter your postal code"); (Label); Tf5 = new JTextField (10); Add (tf5); Label = new JLabel ("Enter your home phone number (306-xxx-xxx)"); (Label); Tf6 = new JTextField (10); Connecting (TF6); Label = new JLabel ("Enter your work phone number (306-xxx-xxx)"); (Label); Tf7 = new JTextField (10); Add (TF7); Label = new jlab ("enter your email (user@emailservice.xxx"); add (labels); tf8 = new JTextField (10); add (tf8); button = new pocket ("next"); add (button } Event E = New Event (); Button.Ad Action Listener (E);} Implementation of Public Sector Incident Actioneller {Public Zero ActionPerfed (Action Event E) {String Address 1, PNUM, NIM, A; Try { String word = tiff 1.getText (); name = word; system.out.println (name); address = tf2.getText (); address = address + "+" + tf 3.getText (); Address = Address + "" + + tf4.getText (); Address = Address + "+ + + tf5.getText (); Address1 = Address; System.out.printLN (Address); PhoneNameHome = TF 6.getText (); pnum = PhoneNumHome; PhoneNumWork = tf7.getText (); wnum = PhoneNumWork; email = Tf8.getText (); a = email; System.out.println (PhoneNumHome); System.out.println ( PhoneNumWork; System.out.println (email); saveInfo (word, address1, pnum, wnum, a); DisplayPersonInfo (); System.exit (0);} Catch (Exception pre) {}}} Public Zero Display PersonInfo () {System.out.println ("Name:" + N AME); System.out.println ("address:" + address); System.out.println ("Home phone number:" + Phonemanham); System.out.println ("Work phone number:" + PhoneNewwork); System.out.println ("Email:" + Email); } Public save zeroInfo (string name, string address, string hoophone, string wong, string email) {name = name; Address = address; PhoneNumHome = Hphone; PhoneNumWork = Wphone; Email = email; } Public stable zero main (string [] args) {person = new person (); Gui.displayPersonInfo (); Gui.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); Gui.setTitle ("enter information"); Gui.setSize (350,330); Gui.setLocation (500,250); Gui.setVisible (true); }   

}

Here is the output: (This works as before displayPersonInfo occurs)
run:
Names: null
Address: Faucet - Home phone number: blank
Work phone number: blank
Email: blank
A name (now prints from within this action) An ad is sent to a postal code of a province / One number one more number
one email
name: one name address: one advertisement one city one province one postal code
home phone number: number one work phone number: another number < Br> email : An email successfully prepared (total time: 20 seconds)

It seems your The saveInfo function is unnecessary because you already set each value before calling it, but I do not know why saveInfo is revoking values ​​ saveInfo before displayPersonInfo and see what happens.

No comments:

Post a Comment