Java-2 2016 Hafta-5 Örnek-3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
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