0
사용자가 입력을 제공 한 후에 테이블을 표시하려고합니다. 나는 왜 테이블이 보이지 않는지 알 수 없다. 내가 추가 할 수있는 테이블을 만들기 위해 here (Stack Overflow) 및 here (Rose India)을 설명Java Applet 테이블에 실행시 표시되지 않음
나는
, 내 테이블을 생성하지만, 내 코드는 특히 여기에, 애플릿에 테이블을 추가하지 않습니다
aTable = new MDTable(mdList);
add(aTable);
코드의
나머지, 전체 붙여 넣기 here (Pastebin) :
public class FMCSAApplet extends Applet implements ActionListener {
String zipcode;
Label lab1;
TextField t1;
Button submitButton;
MDTable aTable;
public void init()
{
setLayout(new FlowLayout());
submitButton = new Button("Submit");
lab1 = new Label("Enter a zipcode:");
t1 = new TextField(15);
add(lab1);
add(t1);
add(submitButton);
submitButton.addActionListener(this);
}
public void paint(Graphics g)
{
g.drawString("Zip code: "+zipcode,30,100);
if(zipcode!=null) {
g.drawString("dotNum\t inputZip\t name\t\t city\t state\t mileage\t unsafe\t fatigued\t fitness\t substance\t maintenance\t inspections",30,120);
try {
..Code Stripped..
// get info from database, add to ArayList<MData> mdList
..Code Stripped..
mdList.add(motorcoach);
}
} // end while
rs.close();
aTable = new MDTable(mdList);
add(aTable);
}catch (Exception f) {
System.out.println(f);
}
}
}
public void actionPerformed(ActionEvent evt)
{
// Here we will ask what component called this method
if (evt.getSource() == submitButton) {
zipcode = t1.getText();
repaint();
}
}
public boolean action(Event e,Object o)
{
zipcode = t1.getText();
repaint();
return true;
}
} //end FMCSAApplet Class
class MDTable extends JPanel {
public MDTable(ArrayList<MData> md) {
Object[][] cellData = {
{1,2,"3","4","5",6,7,8,9,10,11,12}
};
String[] columnNames = {"dotNum","inputZip", "name","city","state","mileage","unsafe","fatigued","fitness","substance","maintenance","inspections"};
add( new JTable(cellData, columnNames)) ;
DefaultTableModel model = new DefaultTableModel(cellData,columnNames);
JTable table = new JTable(model);
for (MData md1 : md) {
model.insertRow(table.getRowCount(),new Object[]{md1.getDotNum(), md1.getInputZip(), md1.getName(), md1.getCity(), md1.getState(), md1.getMileage(), md1.getUnsafe(), md1.getFatigued(), md1.getFitness(), md1.getSubstance(), md1.getMaintenance(), md1.getInspections()});
}
} //end MDTable Constructor
} //end MDTable Class
class MData {
..Code Stripped..
public MData(int d, int i, String n, String c, String s, int m, int u, int f, int fi, int su, int ma, int in)
..Code Stripped..
}