개좆같네진짜 마우스리스너 쓰는 예제만 못풀고있는중
문제는 1~10 숫자로 된 레이블이 랜덤위치에 생성되고 클릭하면 사라지게하는건데
public class even extends JFrame {
Container comp;
JLabel jl[]= new JLabel[10];
even(){
setTitle("focus practice");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
comp=getContentPane();
comp.setLayout(null);
for(int i=0; i<jl.length; i++){
jl[i]=new JLabel(Integer.toString(i));
jl[i].setForeground(Color.MAGENTA);
jl[i].setSize(15, 15);
int x= ((int)(Math.random()*400+1));
int y= ((int)(Math.random()*400+1));
jl[i].setLocation(x, y);
comp.add(jl[i]);
jl[i].addMouseListener(new mymouse());
}
setSize(500,500);
setVisible(true);
}
class mymouse extends MouseAdapter{
public void MouseClicked(MouseEvent e){
JLabel jll= (JLabel)e.getSource();
jll.setVisible(false);
}
}
public static void main (String args[]){
new even();
}
}
이런식으로 짜는데 리스너부분 구현이 문젠지 뭔지모르겠음여
비슷한 다른예제도 클릭으로 뭐 하는건데 그거도 안돌아가는데 내가 뭘모르는지를 모르겠음
병신같은 책 해답지도없음
댓글 0