i think i have converted my application to an applet..... it use to read lines from a .txt file i have on my hard drive but now i want it to read a .txt file from a URL:
import java.awt.*;
import java.awt.event.*;
import javax.swing.JButton.*;
import javax.swing.event.ListSelectionEvent;
import java.net.*;
import java.io.*;
public class RosterSorter extends JApplet {
ArrayList<String[]> rosterList = new ArrayList<String[]>();
// The TableModel controls all the data:
class MyTableModel extends AbstractTableModel {
private String[] columnNames = { "Name" , "Age", "Pos", "Nat", "St", "Tk", "Ps", "Sh", "Ag", "Kab", "Tab", "Pab", "Sab", "Gam", "Sub", "Min", "Mom", "Sav", "Con", "Ktk", "Kps", "Sht", "Gls", "Ass", "DP", "Inj", "Sus"};
public int getColumnCount() {
return columnNames.length;
}
public int getRowCount() {
return rosterList.size();
}
public String getColumnName(int col) {
return columnNames[col];
}
public Object getValueAt(int row, int col)
{
return rosterList.get(row)[col];
}
}
[B]private void textRead() [/B]
{
BufferedReader br = null;
try {
URL url;
URLConnection urlConn;
DataInputStream dis;
url = new URL("http://afterextratime.net/game/ita/1/Laz.txt");
urlConn = url.openConnection();
urlConn.setDoInput(true);
urlConn.setUseCaches(false);
dis = new DataInputStream(urlConn.getInputStream());
String s;
while ((s = dis.readLine()) != null) {
String [] rowfields = s.split("[ ]+");
rosterList.add(rowfields);
s = dis.readLine();
}
dis.close();
}
catch (MalformedURLException mue) {}
catch (IOException ioe) {}
}
public void init() {
textRead();
Container cp = getContentPane();
TableModel myData = new MyTableModel();
JTable table = new JTable(myData);
table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
table.setAutoCreateRowSorter(true);
table.setRowSelectionAllowed(true);
table.setColumnSelectionAllowed(false);
cp.add(new JScrollPane(table));
}
public static void run(JApplet applet, int width, int height) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(applet);
frame.setSize(width, height);
applet.init();
applet.start();
frame.setVisible(true);
}
}
the JTable shows up but it it wont read the file and display the values in the table :S although the file is virtually identical to the one on my harddrive.