I want to read the values of csv file and display that in AWT table when start button is pressed. Pressing stop button should stop reading the values. Reset button must be used to clear the table. I am new to AWT. Here is what i have tried.
package AWTTable;
import java.awt.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.BufferedReader;
import java.io.FileReader;
/**
*
* @author Admin
*/
public class AWTTableUpdate {
public static void main(String[] args) {
Frame f = new Frame();
Label label = new Label("Date and Time ");
Label label1 = new Label(" Name");
Label label2 = new Label("contents");
final Vector columnNames = new Vector();
final Vector data = new Vector();
final TextField text = new TextField(20);
Button b = new Button("Start");
Button b1 = new Button("Stop");
Button b2 = new Button("Reset");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
String strFile = "c:/companylist.csv";
BufferedReader br = new BufferedReader(new FileReader(strFile));
String strLine = "";
StringTokenizer st = null;
int lineNumber = 0, tokenNumber = 0;
ArrayList<String> arrayList = new ArrayList<String>();
while ((strLine = br.readLine()) != null) {
lineNumber++;
st = new StringTokenizer(strLine, ",");
while (st.hasMoreTokens()) {
tokenNumber++;
arrayList.add(st.nextToken());
tokenNumber = 0;
}
Object[] elements = arrayList.toArray();
Scanner input = new Scanner(System.in);
System.out.print("Enter Ticker symbol");
} }catch (Exception e1) {
System.out.println("Exception while reading csv file: " + e1);
}
JTable table = new JTable(data, columnNames);
JScrollPane scrollPane = new JScrollPane(table);
JFrame frame = new JFrame();
frame.add(scrollPane);
frame.setVisible(true);
frame.pack();
frame.repaint();
}
});
Panel p = new Panel(new GridLayout(6, 6));
p.add(label);
p.add(label1);
p.add(label2);
// p.add(text);
p.add(b);
p.add(b1);
p.add(b2);
f.add(p);
f.setVisible(true);
f.pack();
}
}
What I get is not in the form of table. After clicking start button I get blank window. But I want to display the data. Thank you