Results 1 to 16 of 16

Thread: Need Help

  1. #1
    yahyaaa is offline Member
    Join Date
    Sep 2008
    Posts
    28
    Rep Power
    0

    Default Need Help

    Dear All,

    Im new on Java programming and I need to write a code that display a text file content in pop up window. I tried to make some changes on some examples that I found on the net but with no use.

    Please your help

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    We can help you but need to see the code you have already.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  3. #3
    yahyaaa is offline Member
    Join Date
    Sep 2008
    Posts
    28
    Rep Power
    0

    Default

    This is the code that I manage to do so far...
    as you see it displays the string "HIIIIIIIIIIIIIII"

    how can I modifed the below so that the code display a file content
    say " input.txt" in the output window.

    Really appreciate your help,
    ----------------

    package window;

    import java.awt.Frame;
    import java.awt.Label;
    import java.awt.AWTEvent;
    import java.awt.event.WindowEvent;


    public class Window extends Frame {

    public static void main(String[] args) {
    new Window();
    }
    Window() {

    Label label;
    label = new Label("HIIIIIIIIIIIIII");

    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    add(label);
    pack();
    show();
    }
    public void processWindowEvent(WindowEvent event){
    if(event.getID()== WindowEvent.WINDOW_CLOSING)
    System.exit(0);
    }
    }

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,875
    Rep Power
    25

    Default

    display a file content
    say " input.txt" in the output window.
    A couple of steps you need to do.
    1 - create the output window. JTextArea might work.
    2 - read the file into Strings - Several classes to choose from. Do a search for reading a file. Many recent examples on this forum
    3 - put the String into the text area - Read the API doc for JTextArea to see what method to use.
    4 - put steps 2 and 3 in a loop to read/display all the lines from the file
    If you are going to use the AWT classes instead of Swing, remove the J - use TextArea

  5. #5
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    You have everything in the constructor, try this:
    Java JWindow class example
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  6. #6
    yahyaaa is offline Member
    Join Date
    Sep 2008
    Posts
    28
    Rep Power
    0

    Default

    Thanks.... you really help me a lot.

  7. #7
    yasir17 is offline Member
    Join Date
    Sep 2008
    Posts
    3
    Rep Power
    0

    Default Can some one help me please!

    Dear All,

    I am studying Java i have done this but i was told that this is wrong, could you please tell me what do i need to do.

    Exercise Looping Arguments
    Write a simple class that iterates through all the arguments passed in on the command line (not standard-input) and prints them out to the screen.
    If no arguments are specified print a message explaining to the user that they need to supply some arguments.

    Please Help me

    Kind Regards

    Yasir

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,875
    Rep Power
    25

    Default

    i was told that this is wrong
    What does that mean?
    Are you talking about a java program? Do you have any code you can post?
    Do you know how to write a for loop? There are many examples on the forum.

  9. #9
    yahyaaa is offline Member
    Join Date
    Sep 2008
    Posts
    28
    Rep Power
    0

    Default

    Please Please ..

    I end up with this... now I dunno how to display the output in GUI (pop up window )

    Please show me what to modify ?

  10. #10
    yahyaaa is offline Member
    Join Date
    Sep 2008
    Posts
    28
    Rep Power
    0

    Default

    Please Please ..

    I end up with this... now I dunno how to display the output in GUI (pop up window )

    Please show me what to modify ?

    below is the code

    package gui;

    import java.io.*;
    public class FileOper
    {
    public static void main(String args[])throws IOException{

    FileReader fr=new FileReader("c:\\input.txt");
    BufferedReader p=new BufferedReader(fr);

    String s;
    while((s=p.readLine())!=null){
    System.out.println(s);
    }
    p.close();
    }
    }

  11. #11
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,875
    Rep Power
    25

    Default

    You need to use some GUI classes to display data in a window.
    The window is from the JFrame class. There are many other classes that you can add to the JFrame that will allow you to display your text.
    You need to read the Swing tutorial to see how to use those classes. There are many sample programs posted on this forum.

  12. #12
    yahyaaa is offline Member
    Join Date
    Sep 2008
    Posts
    28
    Rep Power
    0

    Default

    I read it, still I dont know how to merge the t ideas with each other, I found out how to make simple GUI. but I dont know how to put my output in that GUI ? :(:(:(:(

  13. #13
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    Quote Originally Posted by yahyaaa View Post
    ......how to put my output in that GUI
    GUI has several text tools, many of them will do what you are told to do.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  14. #14
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,875
    Rep Power
    25

    Default

    One simple GUI component is a JTextArea to display your output.
    Add one to your window.
    Use Search to find the many examples on the forum.

  15. #15
    yahyaaa is offline Member
    Join Date
    Sep 2008
    Posts
    28
    Rep Power
    0

    Default

    have the below script, it runs perfectly on netbeans.6.1... the problem is that when I run it on solaris its compliled with out errors but when I run it I have the below errors....

    any help please..

    The code is:
    package textareaexample;

    import java.io.*;
    import java.awt.*;
    import javax.swing.*;
    class TextAreaExample
    extends JFrame
    {
    public TextAreaExample() throws FileNotFoundException, IOException
    {
    setTitle( "Alarm Window" );
    setSize( 400, 150 );
    setBackground( Color.gray );
    getContentPane().setLayout( new BorderLayout() );
    JPanel topPanel = new JPanel();
    topPanel.setLayout( new BorderLayout() );
    getContentPane().add( topPanel, BorderLayout.CENTER );

    // Create a text area
    JTextArea area = new JTextArea();
    JScrollPane scrollPane = new JScrollPane();
    scrollPane.getViewport().add( area );
    scrollPane.setBounds( 10, 10, 280, 180 );
    topPanel.add( scrollPane, BorderLayout.CENTER );

    // Load a file into the text area, catching any exceptions

    FileReader fileStream = new FileReader( "c:\\input.txt" );
    area.read( fileStream, "c:\\input.txt" );

    }
    public static void main( String args[] ) throws FileNotFoundException, IOException
    {
    // Create an instance of the test application
    TextAreaExample mainFrame = new TextAreaExample();
    mainFrame.setVisible( true );
    }
    }


    The errors :

    exception in thread "main" java.lang.NoClassDefFoundError: TextAreaExample (wrong name: TextArea
    Example/TextAreaExample)

    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass0(ClassLoader.jav a:509)
    at java. security.secureClassLoader.defineClass(secureClass Loader.java:193)
    at java.net.URL ....etc
    at sun.misc.Luncher...etc
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 62)
    at java.lang.ClassLoader.defineClassInternal(ClassLoa der.java:322)

  16. #16
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,875
    Rep Power
    25

    Default

    Your program is in a package. You need to include the package name when executing the program. The code you posted doesn't appear to be the code you are trying to execute. Your code has package: textareaexample
    The class file you tried to execute has package: TextAreaExample
    Remember java is case sensitive.
    What was the command you entered for the above error message?

    To execute a program in a package, enter:
    java <package>.<classname>
    and have the classpath correctly set to the beginning of the package.

Posting Permissions

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