Nesne Tabanlı Programlama-2 (Bahar-2016) Hafta-4/1-2
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 67 68 |
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class radiobutton extends JFrame implements ActionListener { JLabel jlab; public radiobutton() { this.setTitle("RadioButton Örneği"); this.setSize(300,150); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLayout(new FlowLayout()); JPanel jp_main = new JPanel(); jp_main.setPreferredSize(new Dimension(290, 140)); JPanel jpn1 = new JPanel(); JPanel jpn2 = new JPanel(); jpn1.setPreferredSize(new Dimension(280, 60)); jpn2.setPreferredSize(new Dimension(280, 65)); jp_main.add(jpn1); jp_main.add(jpn2); jpn1.setLayout(new GridLayout(1,3)); jpn2.setLayout(new FlowLayout()); jlab= new JLabel("Seçim Yapınız!"); JRadioButton jrb1= new JRadioButton("Seçim-1",true); JRadioButton jrb2= new JRadioButton("Seçim-2"); JRadioButton jrb3= new JRadioButton("Seçim-3"); jrb1.addActionListener(this); jrb2.addActionListener(this); jrb3.addActionListener(this); ButtonGroup bg = new ButtonGroup(); bg.add(jrb1); bg.add(jrb2); bg.add(jrb3); jpn1.add(jrb1); jpn1.add(jrb2); jpn1.add(jrb3); jpn2.add(jlab); this.add(jp_main); this.setVisible(true); } @Override public void actionPerformed(ActionEvent arg0) { JRadioButton jrb = (JRadioButton) arg0.getSource(); jlab.setText(jrb.getText()); //jrb.setText("deneme"); //jrb.setVisible(false); //this.setTitle(jrb.getText()); } public static void main(String[] args) { new radiobutton(); } } |