Google Docs
setLayout(new FlowLayout()); //자율적 레이아웃 설정 \
setLayout(new GridLayout(13)); // 지정된 칸안에 레이아웃 설정
JLabel
JCheckBox
JRadioButton
Submit(JButoon)~ActionEvent로 구현
점수 : 80 점 ( Jlabel~setText(" ") )
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CheckBoxEventTest extends JFrame{
JLabel q1, q2;
JLabel lScore;
JCheckBox q1a, q1b, q1c, q1d;
JRadioButton q2a, q2b, q2c, q2d;
ButtonGroup group;
JButton submit;
CheckBoxEventTest(String title){
super(title);
setSize(500, 300);
setLayout(new GridLayout(13,1));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
q1 = new JLabel("1.다음 중 actionPerformed가 호출되는 경우는?");
q2 = new JLabel("2.Frame의 기본 배치 Layout 매니저는? ");
q1a = new JCheckBox("Button을 눌렀을 때");
q1b = new JCheckBox("TextField에서 엔터키를 칠 때");
q1c = new JCheckBox("MenuItem을 클릭 할 때");
q1d = new JCheckBox("List에서 Item을 더블 클릭할 때");
q2a = new JRadioButton("FlowLayout", false);
q2b = new JRadioButton("GridLayout", false);
q2c = new JRadioButton("BorderLayout", false);
q2d = new JRadioButton("CardLayout", false);
group = new ButtonGroup();
group.add(q2a);
group.add(q2b);
group.add(q2c);
group.add(q2d);
lScore = new JLabel("* 결과: ");
submit = new JButton("답변제출(결과는 아래에)");
add(q1);
add(q1a); add(q1b); add(q1c); add(q1d);
add(new JLabel(""));
add(q2);
add(q2a); add(q2b); add(q2c);add(q2d);
add(submit);
add(lScore);
submit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
float total = 0;
if(q1a.isSelected()) total += 12.5;
if(q1b.isSelected()) total += 12.5;
if(q1c.isSelected()) total += 12.5;
if(q1c.isSelected()) total += 12.5;
if(q2c.isSelected()) total += 50;
lScore.setText(" * 결과: 당신의 점수는" + total +"점 입니다.");
} //별도의 클래스 이름이 없다
});
setVisible(true);
}
public static void main(String[] args) {
new CheckBoxEventTest("Quiz #1");
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CheckBoxEventTest extends JFrame{
JLabel q1, q2;
JLabel lScore;
JCheckBox q1a, q1b, q1c, q1d;
JRadioButton q2a, q2b, q2c, q2d;
ButtonGroup group;
JButton submit;
CheckBoxEventTest(String title){
super(title);
setSize(500, 300);
setLayout(new GridLayout(13,1));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
q1 = new JLabel("1.다음 중 actionPerformed가 호출되는 경우는?");
q2 = new JLabel("2.Frame의 기본 배치 Layout 매니저는? ");
q1a = new JCheckBox("Button을 눌렀을 때");
q1b = new JCheckBox("TextField에서 엔터키를 칠 때");
q1c = new JCheckBox("MenuItem을 클릭 할 때");
q1d = new JCheckBox("List에서 Item을 더블 클릭할 때");
q2a = new JRadioButton("FlowLayout", false);
q2b = new JRadioButton("GridLayout", false);
q2c = new JRadioButton("BorderLayout", false);
q2d = new JRadioButton("CardLayout", false);
group = new ButtonGroup();
group.add(q2a);
group.add(q2b);
group.add(q2c);
group.add(q2d);
lScore = new JLabel("* 결과: ");
submit = new JButton("답변제출(결과는 아래에)");
add(q1);
add(q1a); add(q1b); add(q1c); add(q1d);
add(new JLabel(""));
add(q2);
add(q2a); add(q2b); add(q2c);add(q2d);
add(submit);
add(lScore);
setVisible(true);
}
class EventHandler implements ActionListener{
public void actionPerformed(ActionEvent e){
float total = 0;
if(q1a.isSelected()) total += 12.5;
if(q1b.isSelected()) total += 12.5;
if(q1c.isSelected()) total += 12.5;
if(q1c.isSelected()) total += 12.5;
if(q2c.isSelected()) total += 50;
lScore.setText(" * 결과: 당신의 점수는" + total +"점 입니다.");
}
}
public static void main(String[] args) {
new CheckBoxEventTest("Quiz #1");
}
}
AdjustmentListener (조정자)
sb.getalude
Banner
'Studynote > Computer Science 12' 카테고리의 다른 글
MouseMotionListener (0) | 2018.11.05 |
---|---|
11.25.Tue ch13-5. 이벤트처리 (0) | 2018.11.05 |
14.11.18.화요일 13장 폰트~ (0) | 2018.11.05 |
14.11.17 13장 awt와 애플릿 (0) | 2018.11.05 |
14.11.11.Tue (0) | 2018.11.05 |
댓글