using data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • student33
    New Member
    • Feb 2007
    • 3

    #1

    using data

    Take Class PrintStream as the starting point, looked this up on sun microsystems
    and looking through the available methods to find one that will do what i need to do, the problem then becomes how to use it take "public void print(char c)" for example, have tried lots of ways to no avail typically
    Code:
    import java.io.*;
    import java.util.*;
    
    class displayIt{
    
    static OutputStream      outputStream;
    
    public static void main(String[] args)
    {
     System.out.println("Hello ");
    
    
    
    
    }
    
    class PrintStream{
    
    PrintStream.print("help");
    
    }
    }
    can you please correct my errors or post example if possible so i can see where i am going wrong
    Last edited by Nepomuk; May 3 '09, 01:02 AM. Reason: Please use [code] tags
  • chaarmann
    Recognized Expert Contributor
    • Nov 2007
    • 785

    #2
    You are defining object outputStream and class PrintStream, but you don't use it!
    Also how can your computer call method "print" of your class PrintStream if you don't define it anywhere? You should get a compiler error there, don't ignore compiler errors.
    Just do the Java Tutorials first, it will tell you how to write classes and methods (the very basics of programming) and how to use them properly.

    Comment

    • student33
      New Member
      • Feb 2007
      • 3

      #3
      Hi just a bit of background I am a mature student (52) I have studied Borland C++ at Manchester Metropolitan University, and some java, recently I have need to communicate between two computers using COM ports something that Borland C++ does not readily do, looking at the options I found that I could use java to achieve this task. However I realized from the off that there was areas of java that I did not understand, I have followed your advise and started the tutorials! Which are easy to follow more over they overlap my knowledge of Borland C++ in as much that I all ready have a good understanding of things like arrays etc

      So in conclusion I see that to access a method in another class I do the following
      Code:
      Bicycle bike1 = new Bicycle();  //make an instance of the class
      I can then access the printStates(); method in the Bicycle class using

      Code:
      bike1.printStates();
      So applying this to my own project
      Code:
      PrintStream ps = new PrintStream();
      
      ps.print(int 22);
      Which does not work can you please help why? Also you correctly point out that I have define things that I am not using here, they are to be used later they are part of an example that I am trying to modify to meet my needs


      The over all idea is to develop a system to help a child with autism using a word selection and reward scheme controlled by an adult using the second PC , mainly because the nature of the condition of having autism often leads to shyness and the computer screen is easier to tolerate than face to face contact

      Regards Peter
      Last edited by Nepomuk; May 3 '09, 01:03 AM. Reason: Please use [code] tags

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        As you can see from the constructors for the PrintStream class it needs another OutputStream to send its output to; i.e. it 'wraps' the other OutputStream and decorates it with its own methods. We have an article about this design pattern in the 'insights' section of this forum.

        kind regards,

        Jos

        Comment

        Working...