Results 1 to 7 of 7
  1. #1
    MrSulfat is offline Member
    Join Date
    Jan 2013
    Posts
    12
    Rep Power
    0

    Post Help with FileReader

    Hey i need some help to open my fileReaders, rigth now I wont open it.
    Java Code:
    import javax.swing.JFrame;  
    import javax.swing.JButton;  
      
    import java.awt.GridLayout;  
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.File;
      
    public class GridLayour extends JFrame {
    {  
     final JFrame frame = new JFrame("Set JFrame layout using Grid Layout");  
     GridLayout layout=new GridLayout(4,1);  
     frame.setLayout(layout);  
      
     JButton button1=new JButton("Fysisk");
     button1.addActionListener(new ActionListener(){
    	 public void actionPerformed(ActionEvent e)
            {
    		FileReader1 fr1 = new FileReader1();
    		
            }
        });
     JButton button2=new JButton("Psykisk");
     button2.addActionListener(new ActionListener(){
    	 public void actionPerformed(ActionEvent e)
            {
    		FileReader2 fr2 = new FileReader2();
    		
            }
        });
     JButton button3=new JButton("Andet");
     button2.addActionListener(new ActionListener(){
    	 public void actionPerformed(ActionEvent e)
            {
    		FileReader3 fr3 = new FileReader3();
    		
            }
        });
     JButton button4=new JButton("Q and A");  
      
     frame.add(button1);    
     frame.add(button2);  
      
     //Add third button at row number 2 and column number 1  
     frame.add(button3);  
      
     //Add fourth button at row number 2 and column number 2  
     frame.add(button4);  
      
     //Set default close operation for JFrame  
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
      
     //Set JFrame size :  
     //Width : 400 pixels  
     //Height : 400 pixels  
     frame.setSize(400,400);  
      
     //Make JFrame visible. So we can see it.  
     frame.setVisible(true);  
    }  
    }
    and this is the part i need help too fix
    Java Code:
     JButton button1=new JButton("Fysisk");
     button1.addActionListener(new ActionListener(){
    	 public void actionPerformed(ActionEvent e)
            {
    		FileReader1 fr1 = new FileReader1();
    		
            }
        });

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,950
    Rep Power
    19

    Default Re: Help with FileReader

    What problem are you getting?
    I mean, what are those FileReaders supposed to be reading?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    MrSulfat is offline Member
    Join Date
    Jan 2013
    Posts
    12
    Rep Power
    0

    Post Re: Help with FileReader

    Quote Originally Posted by Tolls View Post
    What problem are you getting?
    I mean, what are those FileReaders supposed to be reading?
    They are supposed to open this
    Java Code:
    import java.io.*;
    
    
    class FileReader3 {
    
    	/**
    	 * @param args
    	 */
    	public static String FileReader3(){
    		// TODO Auto-generated method stub
    	String str;
    		try{
    			  // Open the file that is the first 
    			  // command line parameter
    			  FileInputStream fstream = new FileInputStream("andet.txt");
    
    			  // Get the object of DataInputStream
    			  DataInputStream in = new DataInputStream(fstream);
    			  
    			  BufferedReader br = new BufferedReader(new InputStreamReader(in));
    			  
    			  //Read File Line By Line
    			  
    			  while ((str = br.readLine()) != null)   {
    			  // Print the content on the console
    			  System.out.println (str);
    			  return str;
    			  }
    			  
    			  //Close the input stream
    			 // in.close();
    			  
    		  }catch (Exception e){//Catch exception if any
    			  System.err.println("Error: Her er vores egen fejlmeddelelse" + e.getMessage());
    			  return "der kom en esception"; 
    			  }
    		return "der er blevet læst noget, men heller ikke opstået en exception";
    	}
    
    }

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,950
    Rep Power
    19

    Default Re: Help with FileReader

    That's a static method.
    You seem to be trying to create a FileReader3 object in your ActionListener.
    If you just want to call that method then FileReader3.FileReader3() would do it.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    MrSulfat is offline Member
    Join Date
    Jan 2013
    Posts
    12
    Rep Power
    0

    Default Re: Help with FileReader

    like this?
    Java Code:
     JButton button2=new JButton("Psykisk");
     button2.addActionListener(new ActionListener(){
    	 public void actionPerformed(ActionEvent e)
            {
    		 FileReader2.FileReader2();

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,950
    Rep Power
    19

    Default Re: Help with FileReader

    That's how you would call a static method, yes.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    MrSulfat is offline Member
    Join Date
    Jan 2013
    Posts
    12
    Rep Power
    0

Similar Threads

  1. FileReader errors
    By iochinome in forum Java Applets
    Replies: 1
    Last Post: 12-04-2010, 06:12 AM
  2. Using UNBUFFERED FileReader.
    By Spooge in forum New To Java
    Replies: 1
    Last Post: 10-11-2010, 08:03 AM
  3. FileReader help
    By emp in forum New To Java
    Replies: 1
    Last Post: 07-28-2009, 04:41 AM
  4. add FileReader to GUI
    By VinTiger in forum New To Java
    Replies: 8
    Last Post: 05-11-2009, 12:23 AM
  5. Help with filereader in java
    By zoe in forum Advanced Java
    Replies: 2
    Last Post: 07-26-2007, 09:55 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •