java中数组中添加新元素,求解!!!往ArrayList数组里添加元素,貌似没加进去。...
該樓層疑似違規已被系統折疊?隱藏此樓查看此樓
points、pointl、pointp、L、P都是數組,分別是點、線、面。它們的關系是:points里包含多個point,L里包含多條pointl,P里包含多個pointp.我想往里面添加點要素。
private void addActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
add addFrm=new add(null,true);
addFrm.setVisible(true);
int index=0,dianIndex=0;
flag=addFrm.flag;
if(flag==1){
index=addFrm.index;
if(index < 0 || index > points.size() +1){
throw new IndexOutOfBoundsException("順序表索引越界");
//javax.swing.JOptionPane.showMessageDialog(null, "沒有索引號為"+index+"的點");
}else{
points.add(index, aPoint);
points.get(index);
myRepaint();
}
}
else{
index=addFrm.index;
dianIndex=addFrm.dianIndex;
if(flag==2){
if(index < 0 || index > L.size() + 1){
throw new IndexOutOfBoundsException("順序表索引越界");
// javax.swing.JOptionPane.showMessageDialog(null, "沒有索引號為"+index+"的線");
}
else{
Pointl pl=new Pointl();
pl=L.get(index);
L.add(index,pl);
myPoint[] poiArray1=new myPoint[pl.pNumPoints];
poiArray1=pl.pmyPoints;
myPoint[] poiArray2=new myPoint[pl.pNumPoints+1];
if(dianIndex < 0 || dianIndex > pl.pNumPoints + 1){
throw new IndexOutOfBoundsException("順序表索引越界");
// javax.swing.JOptionPane.showMessageDialog(null, "索引號為"+index+"的線上沒有索引號為"+dianIndex+"的點");
}else{
for(int i=0;i
if(i
poiArray2[i]=poiArray1[i];
}
else{
poiArray2[i]=poiArray1[i+1];
}
}
Pointl pl1=new Pointl();
pl1.setPoints(poiArray2);
L.add(index, pl1);
myRepaint();
}
}
}
if(flag==3){
if(index < 0 || index > points.size() + 1){
throw new IndexOutOfBoundsException("順序表索引越界");
// javax.swing.JOptionPane.showMessageDialog(null, "沒有索引號為"+index+"的多邊形");
}
else{
Pointp pp=new Pointp();
pp=P.get(index);
if(pp.pNumPoints>3){
if(dianIndex < 0 || dianIndex > pp.pNumPoints+1){
throw new IndexOutOfBoundsException("順序表索引越界");
// javax.swing.JOptionPane.showMessageDialog(null, "第"+index+"個多邊形上沒有索引號為"+dianIndex+"的點");
}else{
P.remove(index);
myPoint[] poiArray1=new myPoint[pp.pNumPoints];
poiArray1=pp.pmyPoints;
myPoint[] poiArray2=new myPoint[pp.pNumPoints+1];
for(int i=0;i
if(i
poiArray2[i]=poiArray1[i];
}
else{
poiArray2[i]=poiArray1[i+1];
}
}
Pointp pp1=new Pointp();
pp1.setPoints(poiArray2);
P.add(index, pp1);
}
}
myRepaint();
}
}
}
}
總結
以上是生活随笔為你收集整理的java中数组中添加新元素,求解!!!往ArrayList数组里添加元素,貌似没加进去。...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java门槛_Java的入行门槛高吗?对
- 下一篇: 拦截地址栏参数_selenium操作ch