当用户单击“加入”按钮时,应该出现类似“您已加入此事件”的错误。如何控制它?

时间:2019-12-19 07:24:48

标签: java

用户单击加入按钮时,应该出现类似“您已加入此事件”的错误。我该如何控制它?

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();
     }
}

1 个答案:

答案 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);