M
Michele
Hello Everybody!
I need a help about Array and JTable, could somebody help me?
I have some problems with the AbstractModel and the array!
The file I want to parse is simple, because I want to copy the
integers
inside my table:
10 //this number is the dimension of the table = 10x10
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
The required methods to do in the table A & B in row=i and column= j
are:
- int ReadA(i,j): value of A[i,j], 0 if empty
- WriteA(i,j,k): push k in A[i,j]
- PopA(i,j): remove the contents of A[i,j]
- HighA(i,j): show A[i,j] underlined or in a bigger font, ERROR if
empty
- NormalA(i,j): showA[i,j] normally, ERROR if empty
- LowA(i,j): showA[i,j] in a smaller font, ERROR if empty
----> (repeat with B instead A)
Methods to do with the vector X:
- int ReadX(i): value of X, 0 if empty
- WriteX(i,k): push k in X
- PopX(i): remove the contents of X
- HighX(i): show X underlined or in a bigger font, ERROR if empty
- NormalX(i): show X normally, ERROR if empty
- LowX(i): mostra X in a smaller font, ERROR if empty.
I have prepared a .java file, but it only writes the integers in my
output window, it doesn't copy my integers in my table.
How could I create a table useful for this?
Thanks a lot!!!!
Greetings, Michele Feliciani.
public class Ultimate extends JPanel {
public Ultimate() {
super();
// Create some components
JButton b1 = new JButton("Open Button");
b1.setToolTipText("This is the left button");
JButton b2 = new JButton("Run Button");
b2.setToolTipText("This is the middle button");
JLabel label = new JLabel("Matrice");
JTextField text = new JTextField("Numeri Scartati");
JFrame frame;
JFileChooser inputFC;
// Create a table with empty cells
int rows = 10; //Here I should insert the first value read in my
inputfile, this value is yust a try
int cols = 10; //Here I should insert the first value read in my
inputfile, this value is yust a try
JTable table1 = new JTable(rows, cols);
int c;
Vector items = new Vector();
for (int i=1; i<20; i++) {
items.addElement("This is item "+i);
}
int rows2 = 10; //The same as the previous table;
int cols2 = 10; //The same as the previous table;
JTable table2 = new JTable(rows, cols);
//Lay out the content pane.
setLayout(new FlowLayout());
setPreferredSize(new Dimension(800, 900));
add(b1);
add(b2);
add(label);
add(table1);
add(text);
add(table2);
try {
Vector addyIn = new Vector();
StringTokenizer tokens;
String line;
String token = null;
FileInputStream inFile = new FileInputStream("C:\\q.txt");
BufferedReader input = new BufferedReader (new
InputStreamReader(inFile));
int tokenNo;
//Read in line from file
while ((line = input.readLine()) != null ) {
//get tokens
tokens = new StringTokenizer(line," ");
// loop through tokens adding each on to a vector.
// for ( int i = 0 ; i < tokens.countTokens ; i ++) {
token = tokens.nextToken();
addyIn.addElement(token);
// }
// Add Vector as a row to the datamodel.
//dataModel.addRow(addyIn);
//addyIn.clear();
}
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main (String args[]) throws IOException
{
JFrame frame2 = new JFrame("Pretolani");
frame2.setContentPane(new MyApplication());
frame2.pack();
frame2.setVisible(true);
frame2.show();
}
}
I need a help about Array and JTable, could somebody help me?
I have some problems with the AbstractModel and the array!
The file I want to parse is simple, because I want to copy the
integers
inside my table:
10 //this number is the dimension of the table = 10x10
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
The required methods to do in the table A & B in row=i and column= j
are:
- int ReadA(i,j): value of A[i,j], 0 if empty
- WriteA(i,j,k): push k in A[i,j]
- PopA(i,j): remove the contents of A[i,j]
- HighA(i,j): show A[i,j] underlined or in a bigger font, ERROR if
empty
- NormalA(i,j): showA[i,j] normally, ERROR if empty
- LowA(i,j): showA[i,j] in a smaller font, ERROR if empty
----> (repeat with B instead A)
Methods to do with the vector X:
- int ReadX(i): value of X, 0 if empty
- WriteX(i,k): push k in X
- PopX(i): remove the contents of X
- HighX(i): show X underlined or in a bigger font, ERROR if empty
- NormalX(i): show X normally, ERROR if empty
- LowX(i): mostra X in a smaller font, ERROR if empty.
I have prepared a .java file, but it only writes the integers in my
output window, it doesn't copy my integers in my table.
How could I create a table useful for this?
Thanks a lot!!!!
Greetings, Michele Feliciani.
public class Ultimate extends JPanel {
public Ultimate() {
super();
// Create some components
JButton b1 = new JButton("Open Button");
b1.setToolTipText("This is the left button");
JButton b2 = new JButton("Run Button");
b2.setToolTipText("This is the middle button");
JLabel label = new JLabel("Matrice");
JTextField text = new JTextField("Numeri Scartati");
JFrame frame;
JFileChooser inputFC;
// Create a table with empty cells
int rows = 10; //Here I should insert the first value read in my
inputfile, this value is yust a try
int cols = 10; //Here I should insert the first value read in my
inputfile, this value is yust a try
JTable table1 = new JTable(rows, cols);
int c;
Vector items = new Vector();
for (int i=1; i<20; i++) {
items.addElement("This is item "+i);
}
int rows2 = 10; //The same as the previous table;
int cols2 = 10; //The same as the previous table;
JTable table2 = new JTable(rows, cols);
//Lay out the content pane.
setLayout(new FlowLayout());
setPreferredSize(new Dimension(800, 900));
add(b1);
add(b2);
add(label);
add(table1);
add(text);
add(table2);
try {
Vector addyIn = new Vector();
StringTokenizer tokens;
String line;
String token = null;
FileInputStream inFile = new FileInputStream("C:\\q.txt");
BufferedReader input = new BufferedReader (new
InputStreamReader(inFile));
int tokenNo;
//Read in line from file
while ((line = input.readLine()) != null ) {
//get tokens
tokens = new StringTokenizer(line," ");
// loop through tokens adding each on to a vector.
// for ( int i = 0 ; i < tokens.countTokens ; i ++) {
token = tokens.nextToken();
addyIn.addElement(token);
// }
// Add Vector as a row to the datamodel.
//dataModel.addRow(addyIn);
//addyIn.clear();
}
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main (String args[]) throws IOException
{
JFrame frame2 = new JFrame("Pretolani");
frame2.setContentPane(new MyApplication());
frame2.pack();
frame2.setVisible(true);
frame2.show();
}
}