Hi everyone i'm a newby with java
I have a JTable where birdwatchers can put in the column "[Bird Seen] ,how much birds they have seen.
And if you push the >SEND> button this account of [Birds Seen] must be accumelated on the [Birds Total] column.
For example if you put 3 in column [Birds Seen] then also 3 must appear in the column [Birds Total] after you push the >SEND> button.
But if you put for the second time lets say 4 in column [Bird Seen] then 7 must appear on the column [Birds Total]. Because you saw the first time 3 birds and the second time 4 birds so 3+4=7.
I hope you understand what i mean, if not don't bother to ask.
Here is a picture of how my table looks like, And the java code.
every help is welcom!
package Tabel01; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.ScrollPaneConstants; import javax.swing.table.AbstractTableModel; public class TableDemo extends JPanel implements ActionListener { /** * */ private static final long serialVersionUID = 1L; public JButton actieknop; public JFrame venster; public JTable table; public JPanel panel1, panel2; public TableDemo() { //Create and set up the window. venster = new JFrame("BirdCount"); //make panels panel1 = new JPanel(); panel2 = new JPanel(); //Create and set up the content pane. venster.add(panel1, BorderLayout.CENTER); venster.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); venster.setSize(450,300); //make table table = new JTable(new MyTableModel()); panel1.add(table); JScrollPane scroller1 = new JScrollPane(table); scroller1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); scroller1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); panel1.add(scroller1); table.setPreferredScrollableViewportSize(new Dimension(250, 150)); //Make button actieknop = new JButton(">SEND>"); actieknop.addActionListener(this); panel2.add(actieknop); //panel2.add(actieknop2); venster.add(panel2, BorderLayout.EAST); //Display the window. venster.setVisible(true); } class MyTableModel extends AbstractTableModel { /** * */ private static final long serialVersionUID = 1L; String[] columnNames = { "Bird", "Birds seen", "Birds Total", }; Object[][] data = { {"falck", "", "", new Integer(0) , new Integer(0)}, {"pigeon", "", "", new Integer(0), new Integer(0)}, }; 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 boolean isCellEditable(int row, int col) { //Note that the data/cell address is constant, //no matter where the cell appears onscreen. if (col == 0 || col == 4){ return false; } else { return true; } } } public static void main(String[] args) { new TableDemo(); } @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub } }