我有一个JFrame2 JPanel:a PaintPanel(带paint()方法)和a ButtonPanel(带按钮).当我调用repaint()的PaintPanel(但点击该按钮)的按钮ButtonPanel被涂在PaintPanel!它不是可点击的或任何东西,它就在那里.
我尝试使用此代码重新创建问题:
public class Main {
public static void main(String[] args) {
JFrame frame = new JFrame("frame");
frame.setSize(400,400);
frame.setLayout(new GridLayout(2,1));
PaintPanel paint = new PaintPanel();
ButtonPanel buttons = new ButtonPanel(paint);
frame.add(paint);
frame.add(buttons);
frame.setVisible(true);
}
}
public class PaintPanel extends JPanel{
public void paint(Graphics g){
g.drawRect(10, 10, 10, 10);
}
}
public class ButtonPanel extends JPanel implements ActionListener{
private PaintPanel paintPanel;
public ButtonPanel(PaintPanel …Run Code Online (Sandbox Code Playgroud)