Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在ArrayList中删除JPanel上的形状索引时自动删除该形状?_Java_Arraylist_Graphics_Repaint - Fatal编程技术网

Java 如何在ArrayList中删除JPanel上的形状索引时自动删除该形状?

Java 如何在ArrayList中删除JPanel上的形状索引时自动删除该形状?,java,arraylist,graphics,repaint,Java,Arraylist,Graphics,Repaint,我想知道如何从我的JPanel中删除特定的形状。 形状存储在ArrayList中,当形状的索引被删除时,我希望形状也从我的JPanel中删除 有谁能指导我找到解决这个问题的办法吗?我应该使用什么来删除我的JPanel上的形状 即使在ArrayList中删除了形状的索引,形状仍然存在于JPanel上,有人有解决方案吗 编辑的代码: 导入java.awt.AlphaComposite; 导入java.awt.BasicStroke; 导入java.awt.BorderLayout; 导入java.

我想知道如何从我的JPanel中删除特定的形状。 形状存储在
ArrayList
中,当形状的索引被删除时,我希望形状也从我的
JPanel
中删除

有谁能指导我找到解决这个问题的办法吗?我应该使用什么来删除我的
JPanel
上的形状

即使在
ArrayList
中删除了形状的索引,形状仍然存在于
JPanel
上,有人有解决方案吗

编辑的代码:

导入java.awt.AlphaComposite;
导入java.awt.BasicStroke;
导入java.awt.BorderLayout;
导入java.awt.Color;
导入java.awt.Dimension;
导入java.awt.Graphics;
导入java.awt.Graphics2D;
导入java.awt.Point;
导入java.awt.RenderingHints;
导入java.awt.Shape;
导入java.awt.Stroke;
导入java.awt.event.ActionEvent;
导入java.awt.event.ActionListener;
导入java.awt.event.MouseAdapter;
导入java.awt.event.MouseEvent;
导入java.awt.event.MouseMotionAdapter;
导入java.awt.geom.Ellipse2D;
导入java.awt.geom.Line2D;
导入java.text.DecimalFormat;
导入java.util.ArrayList;
导入java.util.Iterator;
导入javax.swing.Box;
导入javax.swing.Icon;
导入javax.swing.ImageIcon;
导入javax.swing.JButton;
导入javax.swing.JColorChooser;
导入javax.swing.JComponent;
导入javax.swing.JFrame;
导入javax.swing.JMenu;
导入javax.swing.JMenuBar;
导入javax.swing.JMenuItem;
导入javax.swing.JOptionPane;
导入javax.swing.JPanel;
导入javax.swing.JTextField;
公共类测试_1扩展了JFrame{
私家侦探;
//公共整数getSizes(){
//回程透镜;
//}
私有静态最终长serialVersionUID=-1402742716086522L;
梅努巴;
JMenu文件,退出;
JMenuItem新建,打开;
JC组件式绘图板;
JPanel小组;
int选项;
JButton lineBut、ellipseBut、rectBut、strokeBut、trianBut、mulBut、diamondBut、,
阿罗布特,衍生布特,原始布特;
JTextField check,defaultCon,length,attName;
DecimalFormat dec=新的DecimalFormat(“#.##”);
//包含绘图的所有规则
图形2D图形设置,虚线;
//将用于监视下一步要绘制的形状
int currentAction=1;
int x,y;
双a=10.0;
双b=10.0;
字符串checkCon;
//形状的透明度
//默认笔划和填充颜色
Color strokeColor=Color.BLACK;
公共静态void main(字符串[]args){
新测试_1();
}
公共测试_1(){
//定义JFrame的默认值
这个。设置大小(800600);
本文件为setTitle(“ERD建造商”);
此.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
这个.setJMenuBar(菜单栏);
JMenuBar menuBar=新的JMenuBar();
//将菜单栏添加到框架中
JPanel buttonPanel=新的JPanel();
JPanel FieldPanel=新的JPanel();
//可容纳所有按钮的回转箱
Box theBox=Box.createVerticalBox();
Box theBoxs=Box.createVerticalBox();
//通过传递
//按钮图标。
lineBut=makemebutions(“./src/line.png”,2);
ellipseBut=makemebutions(“./src/eliple.png”,3);
//通过传递
//按钮图标和true表示笔划颜色,false表示填充
strokeBut=makeMeColorButton(“./src/stroke.png”,5,true);
check=新的JTextField();
defaultCon=新的JTextField();
长度=新的JTextField();
attName=new JTextField();
//将字段添加到框中
//添加(画笔);
添加(lineBut);
添加(省略号ebut);
按钮面板。添加(框);
现场面板。添加(theBoxs);
添加(buttonPanel,BorderLayout.WEST);
添加(FieldPanel,BorderLayout.EAST);
buttonPanel.setPreferredSize(新尺寸(200480));
FieldPanel.setPreferredSize(新尺寸(200480));
//使绘图区域占据框架的其余部分
//添加(新DrawingBoard(),BorderLayout.CENTER);
最终绘图板drawPanel=新绘图板();
添加(drawPanel,BorderLayout.CENTER);
this.getContentPane().setBackground(Color.WHITE);
//显示框架
此.setVisible(true);
}
公共JButton makeMeButtons(字符串iconFile,final int actionNum){
JButton theBut=新JButton();
图标图标图标=新的图像图标(图标文件);
theBut.setIcon(butIcon);
theBut.addActionListener(新ActionListener(){
已执行的公共无效操作(操作事件e){
currentAction=actionNum;
}
});
返回theBut;
}
公共JButton makeMeColorButton(字符串iconFile,final int actionNum,
最终布尔笔划){
JButton theBut=新JButton();
图标图标图标=新的图像图标(图标文件);
theBut.setIcon(butIcon);
theBut.addActionListener(新ActionListener(){
已执行的公共无效操作(操作事件e){
如果(笔划){
//JColorChooser是一个弹出窗口,允许您选择颜色
strokeColor=JColorChooser.showDialog(空,
“选择一笔”,颜色:黑色);
}否则{
}
}
});
返回theBut;
}
公共类DrawingBoard扩展JComponent{
私有静态最终长serialVersionUID=-4431176095451940075L;
//ArrayList形状=新的ArrayList();
ArrayList shapeStroke=新的ArrayList();
ArrayList dottedShape=新建
JPanel panelWithShapes ...
List<ShapeComponent> myShapes ...

void removeShape(int index) {
  panelWithShapes.remove(myShapes.remove(index));
}