problemo


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: problemo

  1. #1
    Java Newbie Guest

    problemo


    Ok, I'm a high school junior and I have a java programming class in which
    the WHOLE class is stuck and cant figure the assignment out. our assignment
    is to make a read from file, and present it in a window. I have completed
    that part but what I need to do is find a way, code, or some help to make
    each line of the text file I had my original applet create, read into a dialogue
    box with an 'ok' button, I know JOptionPane and all that good stuff but I
    dont know how to get this deal to work and its really frustrating, today
    is the eigth day we've been working on this and I'm ready to give up. ANY
    help would be much appreciated.

  2. #2
    Rajkamal Gopinath Guest

    Re: problemo


    Hi,

    This code reads from an application so you should not have any problem

    but if you wish to read from the applet the same code will work but you need
    to change the policy file to give the permission for the applet to have local
    access to file


    import java.io.*;
    import javax.swing.*;

    public class ShowLines extends JDialog
    {
    String fileName;
    public ShowLines(String fileName)
    {
    this.fileName=fileName;
    }

    public static void main(String args[]) throws Exception
    {
    ShowLines win=new ShowLines(args[0]);
    win.setSize(300,300);
    win.setVisible(true);
    win.showLines();
    }

    public void showLines() throws Exception
    {
    BufferedReader cin=new BufferedReader(new FileReader(fileName));
    String tmp;
    tmp=cin.readLine();
    while(tmp!=null)
    {
    JOptionPane.showMessageDialog(this,tmp,"Showline Dialog",0);
    tmp=cin.readLine();
    }
    }

    }





    "Java Newbie" <onw_co@hotmail.com> wrote:
    >
    >Ok, I'm a high school junior and I have a java programming class in which
    >the WHOLE class is stuck and cant figure the assignment out. our assignment
    >is to make a read from file, and present it in a window. I have completed
    >that part but what I need to do is find a way, code, or some help to make
    >each line of the text file I had my original applet create, read into a

    dialogue
    >box with an 'ok' button, I know JOptionPane and all that good stuff but

    I
    >dont know how to get this deal to work and its really frustrating, today
    >is the eigth day we've been working on this and I'm ready to give up. ANY
    >help would be much appreciated.



  3. #3
    Roberta Carr Guest

    Re: problemo


    "Rajkamal Gopinath" <funkamal@yahoo.com> wrote:
    >
    >Hi,
    >
    >This code reads from an application so you should not have any problem
    >
    >but if you wish to read from the applet the same code will work but you

    need
    >to change the policy file to give the permission for the applet to have

    local
    >access to file
    >
    >
    >import java.io.*;
    >import javax.swing.*;
    >
    >public class ShowLines extends JDialog
    >{
    >String fileName;
    > public ShowLines(String fileName)
    > {
    > this.fileName=fileName;
    > }
    >
    > public static void main(String args[]) throws Exception
    > {
    > ShowLines win=new ShowLines(args[0]);
    > win.setSize(300,300);
    > win.setVisible(true);
    > win.showLines();
    > }
    >
    > public void showLines() throws Exception
    > {
    > BufferedReader cin=new BufferedReader(new FileReader(fileName));
    > String tmp;
    > tmp=cin.readLine();
    > while(tmp!=null)
    > {
    > JOptionPane.showMessageDialog(this,tmp,"Showline Dialog",0);
    > tmp=cin.readLine();
    > }
    > }
    >
    >}
    >
    >
    >
    >
    >
    >"Java Newbie" <onw_co@hotmail.com> wrote:
    >>
    >>Ok, I'm a high school junior and I have a java programming class in which
    >>the WHOLE class is stuck and cant figure the assignment out. our assignment
    >>is to make a read from file, and present it in a window. I have completed
    >>that part but what I need to do is find a way, code, or some help to make
    >>each line of the text file I had my original applet create, read into a

    >dialogue
    >>box with an 'ok' button, I know JOptionPane and all that good stuff but

    >I
    >>dont know how to get this deal to work and its really frustrating, today
    >>is the eigth day we've been working on this and I'm ready to give up. ANY
    >>help would be much appreciated.

    >

    try adding actionPreformed to you code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center