I am presently building an application called Student Registration. I have my classes in separate files. Each class has a list of fields, like student has student information, parent has parent information and so on. I have an Interface file that is going to deal with my swing methods for GUI. Also there are two other classes to be inherited to the main GUI, one of which is Transfer(option to get transferred to another school) . This file has a swing file with it. How would you call these files to the major file. Do I use an actionlisterners with and execute function to call the file?
Next question would be How do I write TextField data to a file for printing?
Mind you I am working my issues out. I just need to hear another point of view and some sample code to see how this would work thank you
Java code manipulation
Started by Scobcode, Jul 11 2009 06:30 AM
7 replies to this topic
#1
Posted 11 July 2009 - 06:30 AM
|
|
|
#2
Posted 12 July 2009 - 02:27 AM
Is it possible to see some code?
so the user of the program writes stuff into textfields of the GUI and the text he/she wrote must be saved to a .txt / .doc file?
Quote
Next question would be How do I write TextField data to a file for printing?
#3
Posted 12 July 2009 - 04:35 PM
That's correct. Gui text fields to file.
#4
Posted 13 July 2009 - 05:33 AM
Could some one point me to code that would possible do such an operation - sending GUI text to file- a link that has suggestive code of some sort.
#5
Posted 13 July 2009 - 06:56 AM
wops, totally forgot about you :scared:
this will save the text from the JTextField "aJTextField" away to the file "file.txt".
note: also seems to work if i change it to file.doc, i will however get a message when i open the file. But after i press ok it opens.
In case you want to write text from multiple textfields to it, first create a String,
then string += JTextfield.getText(); untill all the text is in the string and then write the String.
(i don't really understand the first part of your question :( )
private void save() {
FileWriter writer = null;
try{
writer = new FileWriter(new File("file.txt"));
writer.write(aJTextField.getText());
}
catch(IOException e){
System.out.println("error, can't write");
}
finally{
try{
writer.close();
}
catch(IOException e){
System.out.println("error whilst closing file.");
}
}
}
this will save the text from the JTextField "aJTextField" away to the file "file.txt".
note: also seems to work if i change it to file.doc, i will however get a message when i open the file. But after i press ok it opens.
In case you want to write text from multiple textfields to it, first create a String,
then string += JTextfield.getText(); untill all the text is in the string and then write the String.
(i don't really understand the first part of your question :( )
Edited by wim DC, 13 July 2009 - 06:59 AM.
typo
#6
Posted 14 July 2009 - 02:14 AM
I have an interface file. There are two other interface files that I have to inherit to the main interface file. Do I call the two files by doing a function call so that the windows from the two other files would show?
#7
Posted 14 July 2009 - 02:20 AM
In case you want to write text from multiple textfields to it, first create a String,
then string += JTextfield.getText(); untill all the text is in the string and then write the String.
Oh I set up files created all the strings and other variable type to a get and return methods. So the only thing I would need to do is to write to the string from the JTextfield. So you are saying that this is possible using += JTextfield.getText();. Would I have to do a while loop to receive each each field?
then string += JTextfield.getText(); untill all the text is in the string and then write the String.
Oh I set up files created all the strings and other variable type to a get and return methods. So the only thing I would need to do is to write to the string from the JTextfield. So you are saying that this is possible using += JTextfield.getText();. Would I have to do a while loop to receive each each field?
#8
Posted 14 July 2009 - 05:21 AM
If you have all your textfields set in an array
Implementing more than 1 interface is possible.
Just do
I don't really use interfaces a lot.. I find it annoying to do everything double. (first write the method name in the interface class, then again the name with everything inside the method.. i don't really get the point of interfaces :p)
JTextField[] fields;then you could do it with a loop yes.
Implementing more than 1 interface is possible.
Just do
class ClassName implements Interface1, interface2note: you can only "extends" 1 thing!
I don't really use interfaces a lot.. I find it annoying to do everything double. (first write the method name in the interface class, then again the name with everything inside the method.. i don't really get the point of interfaces :p)


Sign In
Create Account


Back to top









