我有我的方法,可以对类 dvd 的数组 (dArray) 中的所有电影进行排序。现在我只需要对可用电影(setAvailable == true)进行排序。该数组由客户从菜单中输入电影动态填充。我的代码当前搜索数组并将所有电影从 A 到 B 排序,但现在我希望它只搜索和排序 d.setAvailable(true) 的电影...谢谢您的帮助。非常感激
这是数组中所有电影的排序列表:
if(e.getSource() == sortMovBtn)
{
if(dArray[0]==null)
{
JOptionPane.showMessageDialog(null,"No movies, please enter\na movie from the main menu","Error",JOptionPane.ERROR_MESSAGE);
}
else
{
BtnPanel.setVisible(false);
imgPnl.setVisible(false);
btnBackDvd.setVisible(true);
txtAreaSortDvd.setVisible(true);
sortDvdPnl.setVisible(true);
Dvd tmp;
for (int i = 0; i < manyDvd; i++)
{
for (int j = 0; j < (manyDvd - 1 - i); j++)
{
if (dArray[j].getTitle().compareTo(dArray[j+1].getTitle()) > 0)
{
tmp = dArray[j];
dArray[j] = dArray[j+1];
dArray[j+1] = tmp;
}
}
}
a = "";
for (int k = 0; k <manyDvd /*dArray.length*/; k++)
a += (dArray[k]);
txtAreaSortDvd.setText(a);
txtAreaSortDvd.setVisible(true);
txtAreaSortDvd.setEditable(false);
//Set font of text area
txtAreaSortDvd.setFont(new Font("Arial", Font.BOLD, 12));
//Initialize JScrollPane
JScrollPane pane1 = new JScrollPane(txtAreaSortDvd);
//Enable user to use wheel on mouse to scroll
pane1.setWheelScrollingEnabled(true);
//Set the scrollbar to always show
pane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
//Add ScrollPane to Panel
sortDvdPnl.add(pane1);
//Add panel to frame
add(sortDvdPnl);
}
}