버튼을 생성하여 컨테이너 애플릿에 붙인뒤 이벤트 처리
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
{
Button myButton1, myButton2, myButton3;
public void init()
{
myButton1.setLabel("C언어");
myButton1.addActionListener(this);
add(myButton1);
myButton2 =
new Button("C++언어");
myButton2.addActionListener(this);
add(myButton2);
myButton3.addActionListener(this);
add(myButton3);
myLabel.setText("버튼을 눌러주세요!");
myLabel.
setAlignment(Label.
CENTER);
myLabel.
setBackground(Color.
yellow);
add(myLabel);
}
{
if(e.getSource() == myButton1) {
myLabel.setText("선택 : C언어");
} else if(e.getSource()==myButton2) {
myLabel.setText("선택 : C++언어");
} else if(e.getSource()==myButton3) {
myLabel.setText("선택 : 자바");
}
}
}

댓글을 달아 주세요