스윙을 활용해서 간단한 카운트 프로그램 만들어보고 있는데요,
궁금한게 이벤트리스너 부분에 한번눌렀을때 "1번 눌렀습니다" 노출되고 2번째 눌렀을때 "1번 눌렀습니다"가 사라지고 "2번 눌렀습니다"가 노출되게 하고싶은데 어떻게 해야하는지 감을 못잡겠네요
알려주세요.
그부분 아래 강조표시해놨습니다.
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
public class Count extends JFrame{
private JPanel menu = new JPanel(new GridLayout(1,2,3,3));
private JPanel main = new JPanel();
private JButton countup = new JButton();
private JButton del = new JButton();
private JTextArea text = new JTextArea();
private String msg = new String(" 번 클릭했습니다.");
private int i = 0;
public void compInit(){
menu.add(countup);
menu.add(del);
main.add(text,BorderLayout.CENTER);
this.add(menu);
this.add(main);
}
public void evenInit(){
this.countup.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
i++;
text.append(i + msg);
}
});
this.del.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
i--;
text.append(i + msg);
}
});
}
public Count(){
super("카운트 프로그램");
this.setSize(500, 400);
this.setLayout(new GridLayout(2,1,3,3));
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.compInit();
this.evenInit();
this.setVisible(true);
}
public static void main(String[] ar){
new Count();
}
}
ㅗ
해결했다 하하핳