我在Java中创建一个简单的GUI,我有一个“打开”按钮,打开一个新的内部框架,我可以绘制圆形,矩形等。我注意到新创建的框架覆盖了之前的按钮,如“保存”和'显示图形'(显示绘制框架的矩阵)仅适用于最新的内部框架。我希望能够为所选框架工作 - 我可以有2-3个开放框架,我选择一个,它适用于它。
这是我的代码的一部分:
public void createFrame() {
MyInternalFrame frame = new MyInternalFrame();
frame.setBorder(BorderFactory.createLineBorder(new java.awt.Color(6, 128, 209)));
MyInternalFrame.net=new PetriNet(this.getWidth()/20,(this.getHeight()-this.toolBarPosition)/20,25,this);
frame.actionManager=new PetriActionManager(frame.net,frame);
btnPlace.addActionListener(frame.actionManager);
place.addActionListener(frame.actionManager);
btnDelPlace.addActionListener(frame.actionManager);
delPlace.addActionListener(frame.actionManager);
// Other buttons in the same manner
imageLabel=new JImageLabel(frame.net.getImage());
imageLabel.addMouseListener(frame);
imageLabel.setBounds(0,0,this.getWidth(),
this.getHeight()-this.toolBarPosition);
imageLabel.setVisible(true);
this.paint(this.getGraphics());
frame.add(imageLabel);
frame.setVisible(true);
desktop.add(frame);
try {
frame.setSelected(true);
} catch (Exception e) {
e.printStackTrace();
}
}
这是我调用该函数的位置,该按钮打开一个新的内部框架:
Action actionNew = new AbstractAction("New Board", iconNew) {
public void actionPerformed(ActionEvent e) {
createFrame();
}
};
'显示图表'按钮:
if (ev.getActionCommand().equals("Show Graph"))
{
MyInternalFrame.net.buildTree();
this.graphFrame.setStringTree(MyInternalFrame.net.getStringTree());
MyInternalFrame.net.buildImage();
this.paint(this.getGraphics());
this.graphFrame.setVisible(true);
}