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

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

import javax.swing.*;


public class buttonornek implements ActionListener {

	int sayac;
	JLabel jlab;
	public buttonornek() {
		JFrame jfrm = new JFrame("Button Ornek");
		jfrm.setSize(200,200);
		jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jfrm.setLayout(new FlowLayout());
		
		jlab= new JLabel("Butona Tıklayınız");
		JButton jbtn = new JButton("Tıkla!");
		jbtn.addActionListener(this);
		jfrm.add(jlab);
		jfrm.add(jbtn);
		jfrm.setVisible(true);
	}

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

	@Override
	public void actionPerformed(ActionEvent arg0) {
		jlab.setText("Sayac:"+(++sayac));
	}

}

 

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

class buttonislem implements ActionListener
{
	int sayac;
	public void actionPerformed(ActionEvent ae)
	{
		JOptionPane.showMessageDialog(null, "Butona Tıklandı!"+(++sayac));
	}
}

public class buttonornek1 {

	int sayac;
	JLabel jlab;
	public buttonornek1() {
		JFrame jfrm = new JFrame("Button Ornek-1");
		jfrm.setSize(200,200);
		jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jfrm.setLayout(new FlowLayout());
		
		jlab= new JLabel("Butona Tıklayınız");
		JButton jbtn = new JButton("Tıkla!");
		jbtn.addActionListener(new buttonislem());
		jfrm.add(jlab);
		jfrm.add(jbtn);
		jfrm.setVisible(true);
	}

	public static void main(String[] args) {
		new buttonornek1();
	}
}
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class buttonornek2 {

	int sayac;
	JLabel jlab;
	public buttonornek2() {
		JFrame jfrm = new JFrame("Button Ornek-1");
		jfrm.setSize(200,200);
		jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jfrm.setLayout(new FlowLayout());
		
		
		
		
		jlab= new JLabel("Butona Tıklayınız");
		JButton jbtn = new JButton("Tıkla!");
		jbtn.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				JOptionPane.showMessageDialog(null, "Deneme");
				
			}
		});
		jfrm.add(jlab);
		jfrm.add(jbtn);
		jfrm.setVisible(true);
	}

	public static void main(String[] args) {
		new buttonornek2();
	}
}

 

Share