Nesne Tabanlı Programlama-2 (Bahar-2016) Hafta-4/1-2

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();
	}
}

 

Share