Results 1 to 1 of 1
Thread: JTextArea
- 01-13-2008, 01:07 AM #1
Member
- Join Date
- Dec 2007
- Posts
- 34
- Rep Power
- 0
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
-
Can we add JCheckBox array into JTextArea?
By nancyhung in forum AWT / SwingReplies: 1Last Post: 02-17-2008, 12:07 AM -
JTextArea setting
By newtojava7 in forum New To JavaReplies: 1Last Post: 01-29-2008, 02:57 AM -
How to add a shortcut key from JTextArea
By sukatoa in forum Advanced JavaReplies: 2Last Post: 01-28-2008, 08:39 AM -
Jtextarea and scroll
By ziniestro in forum AWT / SwingReplies: 2Last Post: 06-01-2007, 03:59 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks