Java-2 2016 Hafta-6 Örnek-2

java2_2016_hafta6_ornek2

 

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


public class formuyg implements ActionListener {

	JTextField jtf_adsoyad, jtf_tel;
	JRadioButton jrb_m,jrb_f;
	JComboBox jcb;
	public formuyg() {

		JFrame jfrm = new JFrame();
		jfrm.setLayout(new GridLayout(5,2));
		jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JPanel[] jpn = new JPanel[10];
		
		jpn[0]=new JPanel();
		JLabel jlab1= new JLabel("Ad Soyad:");
		jpn[0].add(jlab1);
		
		jpn[1]=new JPanel();
		jtf_adsoyad = new JTextField(10);
		jpn[1].add(jtf_adsoyad);
		
		jpn[2]=new JPanel();
		jlab1= new JLabel("Tel No:");
		jpn[2].add(jlab1);
		
		jpn[3]=new JPanel();
		jtf_tel = new JTextField(10);
		jpn[3].add(jtf_tel);
		
		jpn[4]=new JPanel();
		jlab1= new JLabel("Cinsiyet:");
		jpn[4].add(jlab1);
		
		jpn[5]=new JPanel();
		jrb_m= new JRadioButton("Bay",true);
		jrb_f= new JRadioButton("Bayan");
		ButtonGroup bg = new ButtonGroup(); // grup elemanlarindan sadece biri secilebilsin
		bg.add(jrb_m);
		bg.add(jrb_f);
		jpn[5].add(jrb_m);
		jpn[5].add(jrb_f);
		
		jpn[6]=new JPanel();
		jlab1= new JLabel("Eğitim Durumu:");
		jpn[6].add(jlab1);
		
		String[] icerik={"Yok","İlköğretim","Ortaöğretim","Yüksek.."};
		jcb =new JComboBox(icerik);
		jpn[7]=new JPanel();
		jpn[7].add(jcb);
		
		jpn[8]=new JPanel();
		JButton jbtn1= new JButton("Göster");
		jbtn1.addActionListener(this);
		jbtn1.setActionCommand("goster");
		jpn[8].add(jbtn1);
		
		jpn[9]=new JPanel();
		JButton jbtn2= new JButton("Sıfırla");
		jbtn2.addActionListener(new deneme());
		
		jpn[9].add(jbtn2);
			
	
		for(int i =0; i<jpn.length;i++)
		{
			
			if(i%2==0 && i<7) // 0,2,4,6 nolu bilesenler Label
				jpn[i].setLayout(new FlowLayout(FlowLayout.RIGHT)); // Labellari saga yasladik
			
			
			jfrm.add(jpn[i]);
		}
		
		jfrm.pack(); // frame boyutunu otomatik olarak sigdir
		jfrm.setVisible(true);
		
	}

	@Override
	public void actionPerformed(ActionEvent ae) {

		if(ae.getActionCommand().equals("goster"))
		{
			String sonuc="";
			
			sonuc="Ad Soyad: "+jtf_adsoyad.getText()+" Tel No: "+	jtf_tel.getText();
			
			if(jrb_m.isSelected())
				sonuc+=" Cinsiyet: "+jrb_m.getText();
			else
				sonuc+=" Cinsiyet: "+jrb_f.getText();
			
			sonuc+="Eğitim Durumu: "+jcb.getSelectedItem();
			
			
			JOptionPane.showMessageDialog(null, sonuc,"Özet",JOptionPane.INFORMATION_MESSAGE);
			
			
		}
		else
		{
			jtf_adsoyad.setText("");
			jtf_tel.setText("");
			jrb_m.setSelected(true);
			jcb.setSelectedIndex(0);	
		}
		
		

	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new formuyg();

	}

}


class deneme implements ActionListener
{
	
	public void actionPerformed(ActionEvent ae)
	{
		JOptionPane.showMessageDialog(null, "deneme123");
		
	}
	
}

 

Share