我需要在 JPanel 上显示不同的图纸。我已将绘图文件放入一个数组中,但是当我使用按钮更改它时,JPanel 仅显示第一张绘图并且不会更改为下一张绘图...
我已经调用了 panel.revalidate(),但它不起作用。
这是我使用但不工作的代码段。JPanel 显示是静态的。
String[] a = {"image1.txt","image2.txt","image3.txt"};
List<String> files = Arrays.asList(a);
public void actionPerformed(ActionEvent e) {
if (e.getSource() == answer1){
fileNumber++;
//call other class for painting (files=array files, fileNumber=index of the array)
draw = new drawingPanel(files,fileNumber);
panel.add(draw);
}
panel.revalidate();
panel.repaint();
}