我遇到了问题我无法修复它... 如果你能看一下这个,我将不胜感激。
问题是,按下按钮后,JPanel中没有任何操作。 看看这个:
这是我调用按钮的代码(铅笔,画笔等):
if(action.getSource() == newDrawingArea) { drawingArea = new Drawing(); }
if(action.getSource() == pencilButton) { Drawing.pencil = new Pencil(drawingArea); pencil_condition = true;
lines_condition = false; paintbrush_condition = false; Drawing.paintbrush = null; Drawing.lines = null; }
if(action.getSource() == linesButton) { Drawing.lines = new Lines(drawingArea); lines_condition = true;
pencil_condition = false; paintbrush_condition = false; Drawing.paintbrush = null; Drawing.pencil = null; }
if(action.getSource() == paintbrushButton) { Drawing.paintbrush = new Paintbrush(drawingArea); paintbrush_condition = true;
lines_condition = false; pencil_condition = false; Drawing.lines = null; Drawing.pencil = null; }
Objects应该创建的类是:
public class Drawing extends JPanel {
public static Pencil pencil;
public static Lines lines;
public static Paintbrush paintbrush;
public Drawing() {
setBackground(Color.WHITE);
pencil = new Pencil(this);
GUI.pencil_condition = true;
addMouseListener(pencil);
addMouseMotionListener(pencil);
addMouseListener(lines);
addMouseMotionListener(lines);
addMouseListener(paintbrush);
addMouseMotionListener(paintbrush);
this.repaint();
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
if(GUI.pencil_condition == true) {
GUI.lines_condition = false; GUI.paintbrush_condition = false; paintbrush = null; lines = null;
pencil.paintComponent(g);
}
if(GUI.lines_condition == true) {
System.out.println("include lines!");
GUI.pencil_condition = false; GUI.paintbrush_condition = false; paintbrush = null; pencil = null;
lines.paintComponent(g);
}
if(GUI.paintbrush_condition == true)
paintbrush.paintComponent(g);
}
}
正如您所看到的,我添加了布尔类型条件,但它无法正常工作。 在调用例如Pencil之后,它还将从之前的“绘图”中清除JPanel。
感谢您的帮助!
编辑:// 我编辑了一下代码,但它仍然不起作用......
如何解决这个问题?
编辑://有人帮忙吗? :}