Results 1 to 1 of 1

Thread: JTextArea

  1. #1
    saytri is offline Member
    Join Date
    Dec 2007
    Posts
    34
    Rep Power
    0

    Default problem

    I have a problem, where i need to call the ReadDataFileToPanel class into the GQ class. I tried to use the method setVisible but its not working. Here are the two classes:

    Class that contains the dialog:

    Java Code:
    import java.awt.BorderLayout;
    import java.io.DataInputStream;
    import java.io.File;
    import java.io.FileInputStream;
     
    import javax.swing.JDialog;
    import javax.swing.JTextArea;
     
     
    public class ReadDataFileToPanel {
     
    private JTextArea textArea;
    public ReadDataFileToPanel() {
    super();
     
    try{
    JDialog dialog = new JDialog();
    dialog.getContentPane().setLayout(new BorderLayout(10, 10));
     
    String record = null;
    File file = new File("players.txt");
    FileInputStream fileInput = new FileInputStream(file);
    DataInputStream dis = new DataInputStream(fileInput);
     
    String string = dis.readLine();
    textArea = new JTextArea();
    while(string != null){
    textArea.append(string + "\n");
    string = dis.readLine();
    textArea.setEditable(false);
    }
    dialog.getContentPane().add(BorderLayout.CENTER, textArea);
    dialog.setTitle("Scores");
    dialog.setSize(400, 300);
    dialog.setVisible(true);
    }catch (Exception e){
    e.printStackTrace();
    }
    }
    public static void main(String[] args){
    new ReadDataFileToPanel();
    }
     
    }

    And this is part of the code found in another class (class called GQ) where i have to call the ReadDataFileToPanel:


    Java Code:
    try {
                 
                 BufferedWriter out;
                  String text = JOptionPane.showInputDialog(null, "Enter your name");
                  out = new BufferedWriter(new FileWriter("players.txt",true));
                 out.write(text);
                 out.write("      ");
                 out.write(String.valueOf(count));
                 out.newLine();
                 
                 out.close();
              }catch(IOException e){
                 System.out.println("There was a problem:" + e);
     
                                 }
        
              ReadDataFileToPanel scorelist = new ReadDataFileToPanel ();   // i think i wrote a wrong command over here.
              scorelist.setVisible(true);
            
    }

    Thanks for taking time to read and help. :-)
    Last edited by saytri; 01-13-2008 at 05:17 PM.

Similar Threads

  1. Can we add JCheckBox array into JTextArea?
    By nancyhung in forum AWT / Swing
    Replies: 1
    Last Post: 02-17-2008, 12:07 AM
  2. JTextArea setting
    By newtojava7 in forum New To Java
    Replies: 1
    Last Post: 01-29-2008, 02:57 AM
  3. How to add a shortcut key from JTextArea
    By sukatoa in forum Advanced Java
    Replies: 2
    Last Post: 01-28-2008, 08:39 AM
  4. Jtextarea and scroll
    By ziniestro in forum AWT / Swing
    Replies: 2
    Last Post: 06-01-2007, 03:59 PM

Posting Permissions

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