Java-2(2015) 5. Hafta Swing Uygulamaları

java2_2015_hafta5_ornek1

java2_2015_hafta5_ornek2

java2_2015_hafta5_ornek3

 

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

class combo implements ActionListener{
JLabel jlab;

combo()
{

JFrame jfrm = new JFrame("ComboBox ornegi");
jfrm.setSize(200,300);
jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jfrm.setLayout(new GridLayout(2,1,10,10));

JPanel jpn = new JPanel();

String[] icerik={"Peynir","Yumurta","Sucuk","Sut"};
JComboBox jcb = new JComboBox(icerik);
jcb.addActionListener(this);

jlab= new JLabel("Seçim Yapınız..");
jpn.add(jcb);
jfrm.add(jpn);
jfrm.add(jlab);

jfrm.setVisible(true);
}

public void actionPerformed(ActionEvent ae)
{
	JComboBox cb =(JComboBox) ae.getSource();
	jlab.setText(cb.getSelectedItem().toString());	

}

public static void main(String[] asdad)
{
new combo();
}

}

 

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

class combo2 {
JLabel jlab;
JTextField jtf;
JComboBox jcb;
JFrame jfrm;
combo2()
{

JFrame jfrm = new JFrame("ComboBox ornegi");
jfrm.setSize(200,300);
jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jfrm.setLayout(new GridLayout(3,1,10,10));

JPanel jpn1 = new JPanel();
JPanel jpn2 = new JPanel();
JPanel jpn3 = new JPanel();

String[] icerik={"Peynir","Yumurta","Sucuk","Sut"};
jcb = new JComboBox(icerik);
jcb.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent ae)
{
	JComboBox cb =(JComboBox) ae.getSource();
	jlab.setText(cb.getSelectedItem().toString());	

}


});
jpn1.add(jcb);

jtf = new JTextField(10);
JButton jbtn = new JButton("Ekle");
jbtn.addActionListener( new ActionListener(){

public void actionPerformed(ActionEvent ae)
{
	String veri=jtf.getText();
	if(veri.length()>0)	
		jcb.addItem(veri);
	else
		JOptionPane.showMessageDialog(null,"Boş veri girilemez","Hata",JOptionPane.ERROR_MESSAGE);		
}	


}

);
jpn2.add(jtf);
jpn2.add(jbtn);
jlab= new JLabel("Seçim Yapınız..");
jpn3.add(jlab);
jfrm.add(jpn1);
jfrm.add(jpn2);
jfrm.add(jpn3);

jfrm.setVisible(true);
}

public static void main(String[] asdad)
{
new combo2();
}

}

 

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

class jlistornek {
JTextField jtf;
DefaultListModel lm;

jlistornek()
{
JFrame jfrm = new JFrame("JList ornegi");
jfrm.setSize(200,400);
jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jfrm.setLayout(new GridLayout(3,1,10,10));

JPanel jpn1= new JPanel();
JPanel jpn2= new JPanel();
JPanel jpn3= new JPanel();

//String [] veriler={"abc","xyz"};
lm = new DefaultListModel();

JList jls= new JList(lm);
JScrollPane jscp =new JScrollPane(jls);
jscp.setPreferredSize(new Dimension(120,90));

jtf= new JTextField(10);

JButton jbtn = new JButton("Ekle");
jbtn.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent ae)
{
	String veri =jtf.getText();
	if(veri.length()>0)
	{
		lm.addElement(veri);
		jtf.setText("");
	}

}
});

jpn1.add(jscp);
jpn2.add(jtf); 
jpn3.add(jbtn); 

jfrm.add(jpn1);
jfrm.add(jpn2);
jfrm.add(jpn3);


jfrm.setVisible(true);
}
public static void main(String[] aasdad)
{
new jlistornek();
}


}

 

Share