我的代码:
package try2;
import java.awt.BorderLayout;
import javax.swing.*;
public class bayes
{
JFrame frame;
JTable table;
JPanel panel;
JScrollPane tableContainer;
int i,j;
int countC=0,countR=0,countS=0;
int count=0;
int[] CAge=new int[3];
public bayes()
{
frame = new JFrame("JTable Test Display");
panel = new JPanel();
panel.setLayout(new BorderLayout());
String row[][]={{"consultancy","30","phd","9"},
{"service","21","mtech","1"} ,
{"research","26","mtech","2"},{"service","28","btech","10"},
{"consultancy","40","mtech","14"},{"research","35","phd","10"},
{"research","27","btech","6"},{"service","32","mtech","9"},
{"consultancy","45","btech","17"},{"research","36","phd","7"}};
String column[]={"job","age","qualification","experience"};
table=new JTable(row,column);
tableContainer = new JScrollPane(table);
panel.add(tableContainer, BorderLayout.CENTER);
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
//work type count
for(i=0;i<10;i++)
{
if(table.getValueAt(i,0)=="consultancy")
{
countC++;
}
if(table.getValueAt(i,0)=="research")
{
countR++;
}
if(table.getValueAt(i,0)=="service")
{
countS++;
}
}
//consultancy age count
for(i=0;i<10;i++)
{
if(((table.getValueAt(i, 0))=="consultancy") && ((Integer.parseInt((String)table.getValueAt(i, 1))>=20) && (Integer.parseInt((String)table.getValueAt(i, 1))<=30)) )
{
count++;
}