PDA

Click to See Complete Forum and Search --> : [Java] Really need some help


Azriq_Rieqhael
Oct 8th, 2010, 02:20 AM
I have a problem with my program..

i have three class which is separated with each other

the first class is jPanelTable class


import javax.swing.*;
import java.awt.*;
public class jPanelTable extends JPanel {

protected JTable tblOne;
private String rowData[][];
private String columnData[];
private JScrollPane sp1;
public jPanelTable(String rowData[][],String columnData[])
{
this.rowData = rowData;
this.columnData = columnData;
add(getScrollPane());
revalidate();
repaint();
}
public JTable getTable()
{
tblOne = new JTable(rowData,columnData);
return tblOne;
}
public JScrollPane getScrollPane()
{
sp1 = new JScrollPane(getTable());
sp1.setPreferredSize(new Dimension(750,180));
return sp1;
}

}


the second class is jPaneButton

import java.awt.event.ActionEvent;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
public class jPanelButton extends JPanel {

private JButton jbtnOne;
private jPanelTable jPTblOne ;
public jPanelButton()
{

jbtnOne = new JButton("Click It");
jbtnOne.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e) {
String[] columnName = {"School Name","Teachers Name"};
String[][] rowData = {{"University 1","Mr Larry"},{"Universiti 2","Mr Harrold"}};
jPTblOne = new jPanelTable(rowData,columnName);
jPTblOne.revalidate();
jPTblOne.repaint();
}

});
setLayout(new FlowLayout());
add(jbtnOne);
}
}


and the last class is testClass

import javax.swing.*;
import java.awt.*;
public class testClass {

public static void main(String[] args) {
JFrame one = new JFrame("Test");
String columnName[] = {"FirstName", "LastName", "Hobby"};
String[][] data = {
{"Kathy", "Smith", "Snowboarding"},
{"John", "Doe", "Rowing"},
{"Sue", "Black", "Knitting"},
{"Jane", "White", "Speed reading"},
{"Joe", "Brown", "Pool"}};
one.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container con = one.getContentPane();
con.setLayout(new GridLayout(2,1,5,5));
con.add(new jPanelTable(data,columnName));
con.add(new jPanelButton());
one.setSize(new Dimension(800,600));
one.setVisible(true);
}
}


that's all my class file code.. ok for the output.. when the program run JTable component should list all the data in the array that had been declared in classTest and for this.. i can say it as success..

the second thing is i want to replace the old data in JTable with the new array of string value that had been declared in jPanelButton class in the actionPerformed method which is override from the ActionListener interfaces
and this is my major problem.. i can't replace the old data with the new one.. or in another word, i cannot make a change in JTable when i click the button declared in jPanelButton class... so i really need a help here to tell me where do i slacking off here.. there is no error in my code but why i can't replace the old data in JTable with the new one..

i'll really appreciate if you all can help me out about this.. :)