用户单击加入按钮时,应该出现类似“您已加入此事件”的错误。我该如何控制它?
model=(DefaultTableModel) table1.getModel();//table1 is total events
model2=(DefaultTableModel) mytable.getModel();//mytable is user's events
int selected_row=table1.getSelectedRow();//selected row to join
String username=User_Login.username.getText();//taking username from user login page to write joinedevent txt
if(table1.getRowCount()==0)
info.setText("There is no event yet !!");
else
{
if(selected_row==-1)
info.setText("Select a row to join an event !!");
else
{
int event_id=(int) model.getValueAt(selected_row,0);
String event_name=(String) model.getValueAt(selected_row, 1);
String event_loc=(String) model.getValueAt(selected_row, 2);
String date= (String) model.getValueAt(selected_row, 3);
UserInfo.joinedEventWriter(username, event_id, event_name, event_loc, date);
Object [] row_data={event_id,event_name,event_loc,date};
model2.addRow(row_data);
info.setText("You joined " +event_name+ " event successfully ##");
table1.clearSelection();
}
}
答案 0 :(得分:0)
int event_id = (int) model.getValueAt(selected_row,0);
String event_name = (String) model.getValueAt(selected_row, 1);
String event_loc = (String) model.getValueAt(selected_row, 2);
String date = (String) model.getValueAt(selected_row, 3);
Object[] row_data = {event_id, event_name, event_loc, date};
model2.addRow(row_data);