Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Help i dont know how to make it work!

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry Help i dont know how to make it work!

    Hi ive been trying to get the user input from the JTextField into my fileCreation class so i can name the file i am creating.

    Here is the code:

    public class window extends JFrame{
     
    public static JTextField textField;
     
    public window(){
     
       textField = new JTextField(20);
       add(textField);
     
       textField.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e){
                    String input = textField.getText();
                }   
            });
       }
    }
     
    public class fileCreation{    
        public static void files ()throws IOException{ 
        File newFile;
        newFile = new File("C:/Users/Administrator.Dan-HP/Desktop/" + input + ".txt");
     
         if(!newFile.exists()){
             newFile.createNewFile();
          }
       }
    }

    not all the code just the relevant parts.
    Last edited by jps; October 29th, 2012 at 07:26 PM. Reason: added code tags


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Help i dont know how to make it work!

    Please see the announcements page for use of code tags in your post.



    Hi ive been trying to get the user input from the JTextField into my fileCreation class so i can name the file i am creating.
    That gives an idea of what you wanted to do. But does not really ask a question that can be answered. Does the code compile? ...run? ...have any errors?

  3. #3
    Junior Member
    Join Date
    Oct 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help i dont know how to make it work!

    Quote Originally Posted by jps View Post
    Please see the announcements page for use of code tags in your post.



    That gives an idea of what you wanted to do. But does not really ask a question that can be answered. Does the code compile? ...run? ...have any errors?
    yeah it does run when i remove + input +, but i need it to know what input is so i can add it to the fileCreating class so the file can be named but it doesn't recognize it.

Similar Threads

  1. How to make Eclipse work with txt file?
    By Prostak in forum What's Wrong With My Code?
    Replies: 6
    Last Post: November 4th, 2011, 05:43 PM
  2. what's going on? I tried to make a scrollable JFrame and it didn't work!
    By javapenguin in forum What's Wrong With My Code?
    Replies: 4
    Last Post: August 20th, 2011, 09:47 PM
  3. How to make for loop work?
    By Dragonkndr712 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: March 8th, 2011, 02:14 PM
  4. WHY this code dont work?
    By sibbe in forum Java Theory & Questions
    Replies: 7
    Last Post: December 9th, 2010, 10:47 AM
  5. Unnable to make validations work for login screen
    By fierof2 in forum Web Frameworks
    Replies: 8
    Last Post: July 29th, 2010, 07:12 AM