Java-2 2016 Hafta-5 Örnek-3
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class secenek implements ActionListener { JRadioButton jrb1,jrb2,jrb3; JLabel jlab; public secenek() { JFrame jfrm = new JFrame("Seçenekler"); jfrm.setSize(150,150); jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jfrm.setLayout(new FlowLayout()); JPanel jpn = new JPanel(); jpn.setLayout(new FlowLayout(FlowLayout.LEFT)); jpn.setPreferredSize(new Dimension(140,140)); jrb1 = new JRadioButton("Galatasaray"); jrb2 = new JRadioButton("Beşiktaş"); jrb3 = new JRadioButton("İskenderun BBS"); jrb1.addActionListener(this); jrb2.addActionListener(this); jrb3.addActionListener(this); ButtonGroup bg = new ButtonGroup(); bg.add(jrb1); bg.add(jrb2); bg.add(jrb3); jlab = new JLabel("Seçiniz"); jpn.add(jrb1); jpn.add(jrb2); jpn.add(jrb3); jpn.add(jlab); jfrm.add(jpn); jfrm.setVisible(true); } public void actionPerformed(ActionEvent ae) { JRadioButton jrb = (JRadioButton) ae.getSource(); jlab.setText(jrb.getText()); /* if(jrb1.isSelected()) jlab.setText(jrb1.getText()); if(jrb2.isSelected()) jlab.setText(jrb2.getText()); if(jrb3.isSelected()) jlab.setText(jrb3.getText());*/ } public static void main(String[] args) { new secenek(); } }
kodlar çok işime yaradı teşekkürler