我有問題每增加一個點擊一次。Java增量錯誤()代碼
class window extends JPanel implements MouseListener{
int a=0;
public void paint(Graphics g){
super.paint();
g.drawLine(5, 5, 200, 200); // TEST draw
}
@Override
public void mousePressed(MouseEvent e) {
a++; // increment by one
System.out.println(a);// print out
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
}
class drawSpline_frame extends JFrame {
public drawSpline_frame(){
setSize(500,500);
setTitle("Spline");
Container cp = this.getContentPane(); // EDITED
cp.add(window, BorderLayout.CENTER);
window.addMouseListener(window);
}
}
class drawSpline{
public static void main(String[] args) {
JFrame frame = new drawSpline_frame();
frame.setVisible(true);
}
}
你有沒有那樣的問題 –
你忽略的答案通過不回覆他們來回答您的原始問題,並且您在這裏複製相同的問題。這不是好行爲。投票結束重複。 –
我想在類Window中實現2個mouseListeners。 – th3shad0w