Hi, hier mal der Code:
von public static int[] brutto_berechnen() müsste ich jetzt auf die Tabelle tblScoreCard zugreifen und Wert auslesen. Wie kann ich das machen? Hab schon einiges probiert, aber irgendwie komme ich da weder über frmMain noch über getContentPane() hin. Kann jemand helfen?
Code:
import javax.swing.*;
import javax.swing.table.AbstractTableModel;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class Golfrechner extends JFrame implements ActionListener {
public Golfrechner() {
JTable tblScoreCard = new JTable( new MyTableModel() );
tblScoreCard.setFont(fnt1);
tblScoreCard.setSelectionBackground(new Color(0,90,0));
tblScoreCard.setSelectionForeground(c2);
tblScoreCard.setBackground(c2);
JScrollPane scrlPane = new JScrollPane(tblScoreCard);
scrlPane.setBounds(10, 60, 400, 163);
contentpane.add( scrlPane );
}
public static int[] brutto_berechnen() {
int[] ergebnis = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
return ergebnis;
}
public static void main(String[] args) {
Golfrechner frmMain = new Golfrechner();
frmMain.setVisible(true);
}
class MyTableModel extends AbstractTableModel {
private String columnNames[] = {"Loch", "Par", "Hcp", "Score", " ",
"Loch", "Par", "Hcp", "Score"};
private String data[][] = {
{"1", "", "", "", "", "10", "", "", ""},
{"2", "", "", "", "", "11", "", "", ""},
{"3", "", "", "", "", "12", "", "", ""},
{"4", "", "", "", "", "13", "", "", ""},
{"5", "", "", "", "", "14", "", "", ""},
{"6", "", "", "", "", "15", "", "", ""},
{"7", "", "", "", "", "16", "", "", ""},
{"8", "", "", "", "", "17", "", "", ""},
{"9", "", "", "", "", "18", "", "", ""}
};
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();
}
public boolean isCellEditable(int row, int col) {
//Note that the data/cell address is constant,
//no matter where the cell appears onscreen.
if (col < 2) {
return false;
} else {
return true;
}
}
public void setValueAt(String value, int row, int col) {
data[row][col] = value;
fireTableCellUpdated(row, col);
}
}
}
von public static int[] brutto_berechnen() müsste ich jetzt auf die Tabelle tblScoreCard zugreifen und Wert auslesen. Wie kann ich das machen? Hab schon einiges probiert, aber irgendwie komme ich da weder über frmMain noch über getContentPane() hin. Kann jemand helfen?