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:
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:
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. :-)