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

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

public class yerlesim extends JFrame implements ActionListener{

	public yerlesim() {
		// this anahtar kelimesi kullanilmasa da olur 
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setSize(330,370);
		this.setLayout(new FlowLayout());
		
		JPanel jpn0 = new JPanel();
		JPanel jpn1 = new JPanel();
		JPanel jpn2 = new JPanel();
		
		jpn0.setPreferredSize(new Dimension(100, 370));
		jpn1.setPreferredSize(new Dimension(100, 370));
		jpn2.setPreferredSize(new Dimension(100, 370));
		
		for(int i=1;i<31;i++)
		{
			JButton jbtn = new JButton("Buton-"+i);
			jbtn.setPreferredSize(new Dimension(100,30));
			jbtn.setActionCommand(i+"");
			jbtn.addActionListener(this);
			
			if(i%3==0)
				jpn2.add(jbtn);
			if(i%3==1)
				jpn0.add(jbtn);
			if(i%3==2)
				jpn1.add(jbtn);
			
			
		}
		
		this.add(jpn0);
		this.add(jpn1);
		this.add(jpn2);
		
		this.setVisible(true);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		JOptionPane.showMessageDialog(null,  e.getActionCommand());
		
	}
	public static void main(String[] args) {
		new yerlesim();

	}

}

 

Share