Jump to content

Java code manipulation

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1
Scobcode

Scobcode

    Newbie

  • Members
  • PipPip
  • 16 posts
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

#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
Is it possible to see some code?

Quote

Next question would be How do I write TextField data to a file for printing?
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?

#3
Scobcode

Scobcode

    Newbie

  • Members
  • PipPip
  • 16 posts
That's correct. Gui text fields to file.

#4
Scobcode

Scobcode

    Newbie

  • Members
  • PipPip
  • 16 posts
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
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
wops, totally forgot about you :scared:
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
Scobcode

Scobcode

    Newbie

  • Members
  • PipPip
  • 16 posts
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
Scobcode

Scobcode

    Newbie

  • Members
  • PipPip
  • 16 posts
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?

#8
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
If you have all your textfields set in an array
JTextField[] fields;
then you could do it with a loop yes.

Implementing more than 1 interface is possible.
Just do
class ClassName implements Interface1, interface2
note: 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)