Il programma non dev'essere un applet.E' un applicazione stand alone.
Ok.Il programma dovrebbe prendere un testo che si presenta così:
codice:
6233E HIGH 16234_16233 Path In
Detailed results
16033_Low RING ETH 2 15 GHz Path Out
6318 MERCURE AT Path Out H
16030(16314A,16119) RING SDH NORTH 15GHz 4+0 Path
16033_Low RING ETH 2 15 GHz Path Out
e in output mi da:
codice:
6233E HIGH 16234_16233 Path In
16033_Low RING ETH 2 15 GHz Path Out
6318 MERCURE AT Path Out
16030(16314A,16119) RING SDH NORTH 15GHz 4+0 Path Out
16033_Low RING ETH 2 15 GHz Path Out
Ora vi dico come l'ho pensato:
Per prendere in ingresso un documento utilizzo la serializzazione,quindi creo due classi una per salvare il file e una per caricare il file.
codice:
public class FileTopMenuListener implements ActionListener {
public FileTopMenuListener(TopMenu listened) {
listened.openAddActionListener(this);
listened.saveAddActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
//Caso di pressione del menù di caricamento
if (e.getActionCommand() == "open") {
JFileChooser fc = new JFileChooser();
fc.setFileFilter(new IOFilter());
int returnVal = fc.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File document = fc.getSelectedFile();
ObjectInputStream in;
try {
in = new ObjectInputStream(new FileInputStream(document));
in.close();
} catch (Exception err01) {
JOptionPane.showMessageDialog(null,
"Errore durante il caricamento", "Caricamento",
JOptionPane.ERROR_MESSAGE);
}
}
//Caso di pressione del menù di salvataggio
} else if (e.getActionCommand() == "save") {
JFileChooser fc = new JFileChooser();
fc.setFileFilter(new IOFilter());
int returnVal = fc.showSaveDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File document = fc.getSelectedFile();
document = new File(document.getAbsolutePath().endsWith(".out")
? document.getAbsolutePath() : document.getAbsolutePath()+".out");
ObjectOutputStream out;
try {
out = new ObjectOutputStream(new FileOutputStream(document));
out.writeObject(document);
out.close();
} catch (Exception err01) {
JOptionPane.showMessageDialog(null,
"Errore durante il salvataggio", "Salvataggio",
JOptionPane.ERROR_MESSAGE);
}
}
}
}
}
Poi ho una classe che mi filtra il testo in ingresso.
Ora qui iniziano i problemi.Ho pensato che per ordinare e mettere in colonna, sotto le rispettive righe i dati ho pensato che ogni gruppo di stringhe viene messo dentro un array,e questo array dinamico deve essere inserito dentro ogni cella.
Riassumendo
1)Come far si che il ogni stringa di caratteri o un insieme di numeri consecutivi presi dal documento in ingresso diventi un array della dimensione giusta della stringa o gruppo di caratteri
2)successivamente come far si che la tabella si autocompleti,cioè dinamicamente ogni array si sistemi sotto ogni cella
3)Impostare il colore delle righe della tabella di bianco,in modo da confondere le linee della tabella con lo sfondo del foglio.
4)Infine devo salvare il tutto.
Vi posto anche la classe che ho provato a scrivere
codice:
public class Center_Body {
String text new String();
//Prende in ingresso una sequenza di caratteri e verifica se ci sono spazi.In caso affermativo li elimina
if( text.lenght[i] == " "){
for(int i = 0; i < text.lenght; i++){
String s2 = text.lenght[i].replaceAll(" ","");
}
//Ogni sequenza di caratteri isolati è un array dinamico di oggetti
//Creo una tabella dinamica
public TableDemo() {
JTable table = new JTable(new MyTableModel());
}
class MyTableModel extends AbstractTableModel {
private String[] columnNames = { "Radio", "at", "Object", "Direction","Pol.","Interf. signal level (dBm)", "C/I",
"Uncorrelated Threshold degradation (dB)", "Threshold level/interf. signal (dB)", "Correlation", "Correlated Threshold degradation (dB)",
"Bandwidth(MHz)", "Frequency (MHz)", "Channel"};
public int getColumnCount() {
return columnNames.length;
}
public int getRowCount() {
return data.length;
}
public String getColumnName(int col) {
return columnNames[col];
}
public Object getValueAt(int row, int col) {
return data[row][col];
}
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
}
//Controllare come apre il file,cioè vedere se ogni gruppo di parole viene considerato come una stringa
//Creo array di intestazioni
String [] headers = this.getFileTopMenuListener();
//Creo matrice di dati
Object[][] data = new Object[this.lista.size()][headers.length];
int i=0;
for(Iterator < String[]> it=lista.iterator();it.hasNext();)
{ String[] tmp=it.next();
for(int j=0;j<tmp.length;j++){ data[i][j]=tmp[j];
}
i++;
}
//Setto dati e intestazioni della tabella
this.myJTable.setModel(new javax.swing.table.DefaultTableModel(data, headers){
@Override public boolean isCellEditable(int rowIndex, int mColIndex) { return false; }
}
);
//Setto larghezza colonne
this.setTableCellsSize(this.myJTable);
//Imposto allinamento delle celle al centro
DefaultTableCellRenderer renderer=new DefaultTableCellRenderer();
renderer.setHorizontalAlignment(DefaultTableCellRenderer.CENTER);
this.myJTable.setDefaultRenderer(this.myJTable.getColumnClass(0), renderer);
this.myJTable.updateUI();
}
}
if( text == "Radio" || text == "at" || text == "Object" || text == "Direction" || text == "Pol." ||
text == "Interf." || text == "signal" || text == "level" || text == "(dBm)" || text == "C/I" ||
text == "Uncorrelated" || text == "Threshold" || text == "degradation" || text == "(dB)" ||
text == "level/interf." || text == "Correlation" || text == "Correlated" || text == "Bandwidth" ||
text == "(MHz)" || text == "Frequency" || text == "Channel" || text == "=======================================================================================================================================================================================================================================================" ||
text == "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" ||
text == "Detailed results" || text == "Project:"){
text.remove();
}
//Inserisco i risultati nella tabella
}
}
PS.non ho postato niente prima per avere idee spontanee,senza la mia influenza.