📄 TekSoru.java .java dosyası
⬇️ İndir
import java.awt.event.*;
import javax.swing.*;
public class TekSoru {
public TekSoru() {
JFrame frame = new JFrame("Karyatid Tek Soru Örnek");
ImageIcon handbellIcon = new ImageIcon("src/images/04_handbell.jpg");
int x = 50;
int y = 15;
JRadioButton h1 = new JRadioButton("Doorbel");
JRadioButton h2 = new JRadioButton("Snowberry");
JRadioButton h3 = new JRadioButton("Peppercorn");
JRadioButton h4 = new JRadioButton("Handbell"); // Dogru cevap.
ButtonGroup handbell = new ButtonGroup(); // RadioButton'lari grupluyoruz.
JLabel label = new JLabel("What is this?", handbellIcon, JLabel.CENTER);
label.setVerticalTextPosition(JLabel.TOP);
label.setHorizontalTextPosition(JLabel.CENTER);
label.setBounds(x, y, 150, 180); y = y + 190;
h1.setBounds(x, y, 140, 20); y = y + 17 ;
h2.setBounds(x, y, 140, 20); y = y + 17 ;
h3.setBounds(x, y, 140, 20); y = y + 17 ;
h4.setBounds(x, y, 140, 20); y = y + 50 ;
JButton buton = new JButton("Sent");
buton.setBounds(50, y, 150, 20);
buton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
String açıklama = " ";
if (h4.isSelected()) {
açıklama = "Doğru cevap";
} else if (h1.isSelected() || h2.isSelected() || h3.isSelected()) {
açıklama = "Yanlış cevap";
} else {
açıklama = "Cevaplanmadı";
}
JOptionPane.showMessageDialog(null, açıklama, "Sonuç" , JOptionPane.INFORMATION_MESSAGE);
}
});
frame.add(label);
frame.add(h1);
frame.add(h2);
frame.add(h3);
frame.add(h4);
frame.add(buton);
handbell.add(h1);
handbell.add(h2);
handbell.add(h3);
handbell.add(h4);
frame.setSize(250,400);
frame.setLayout(null);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
frame.setVisible(true);
}
}