Results 1 to 5 of 5
  1. #1
    mitty is offline Member
    Join Date
    Jan 2010
    Posts
    16
    Rep Power
    0

    Default Calling from the output from one class to another

    I have a class called FileInput with the following code
    Java Code:
    class FileInput{
    	public static void main(String[] args)throws IOException{
        String text;
        Writer output = null;
      
        
      
        text =  JOptionPane.showInputDialog("Please enter your sentence here");
        String text2 = null;
       File file = new File("inputtest.txt");
        output = new BufferedWriter(new FileWriter(file));
       
     	  
    
    	    
    	      
    	      
    	      	StringTokenizer st2;
    			
    			st2 = new StringTokenizer (text, " ");
    	      
    			while (st2.hasMoreElements()){
    	    	// System.out.println(" \" " + st2.nextToken() + " \", ");
    	    	  text2 = (" \" " + st2.nextToken() + " \", ");
    	    	  System.out.println (text2);
    	  	    output.write (text2);
    			}
    	      
    	   
    	    if(file.exists()) {
    	    	  String absolutePathOfFirstFile = file.getAbsolutePath();
    	    	  System.out.println(absolutePathOfFirstFile);
    	    	} else {
    	    	  System.out.println("file does not exist");
    	    	}
    		
    		  output.close ();
    	  }
    	}
    and i have another class called ParserDemo
    Java Code:
    import java.util.*;
    import java.io.*;
    import javax.swing.JOptionPane;
    import edu.stanford.nlp.trees.*;
    import edu.stanford.nlp.parser.lexparser.LexicalizedParser;
    
    
    
    
    
    
    class ParserDemo {
      public static void main(String[] args) {
    	String sent;
        LexicalizedParser lp = new LexicalizedParser("C:/Documents and Settings/Mitesh/Desktop/eclipse/stanford-parser-2010-02-26/bin/englishPCFG.ser.gz");
        //lp.setOptionFlags(new String[]{"-maxLength", "80", "-retainTmpSubcategories"});
    
        //String[] sent1 = { " This " , " is " , " an " , " easy " , " sentence " , " . " };
        sent =  JOptionPane.showInputDialog("Please enter your sentence here");
        Tree parse = (Tree) lp.apply(Arrays.asList(sent));
        parse.pennPrint();
        System.out.println();
    
     TreebankLanguagePack tlp = new PennTreebankLanguagePack();
     GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory();
      GrammaticalStructure gs = gsf.newGrammaticalStructure(parse);
      Collection tdl = gs.typedDependenciesCollapsed();
      System.out.println(tdl);
      System.out.println(sent);
    
        TreePrint tp = new TreePrint("penn,typedDependenciesCollapsed");
        tp.printTree(parse);
        
        System.err.println("Penn format:");
        TreePrint treePrint = new TreePrint("penn");
        treePrint.printTree(parse);
      }
    }
    Im trying to call the file from the FileInput screen and parse it in the ParserDemo but im having problems with this.

    Is there an easy way to do this?

    Thanks in advance

    /Mitty
    Last edited by Eranga; 04-06-2010 at 04:27 AM. Reason: code tags added

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Create an object of the class which you want to use in the other class, and call a public method with relevant arguments.

    Your coding practice is not that much good. In each class you've only one method, main. Do you know how to construct a code in use of OO concepts?

  4. #4
    mitty is offline Member
    Join Date
    Jan 2010
    Posts
    16
    Rep Power
    0

    Default

    Hi, sorry about that I will make sure I use code tags next time.

    I'm a complete beginner in programming so my code is not that great. I would love to spend time learning about it but at the moment I need to have a program which works by the end of April for my final year project at university.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Okay can you go through the following code? And try to understand the code. Actually I hope you know what really happen there.

    Java Code:
    public class Class1 {
    
        public static void main(String[] args) {
            // Create object of Class2
            Class2 objClass2 = new Class2();
            
            // Call a method
            objClass2.displayMessage();
        }
    
    }
    
    class Class2 {
    
        public void displayMessage() {
            System.out.println("Message");
        }
    
    }

Similar Threads

  1. Replies: 9
    Last Post: 01-23-2014, 08:17 PM
  2. Child-Class Calling a Method in a Parent-Class
    By Blah_ in forum New To Java
    Replies: 5
    Last Post: 09-29-2009, 03:48 AM
  3. Calling a class method from another class
    By caro in forum New To Java
    Replies: 4
    Last Post: 06-10-2009, 02:12 AM
  4. problem calling function from class to class
    By alin_ms in forum New To Java
    Replies: 3
    Last Post: 12-19-2008, 08:35 PM
  5. Calling a method on original class from created class
    By kpedersen in forum Advanced Java
    Replies: 4
    Last Post: 08-20-2008, 01:25 AM

Posting Permissions

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