31 Aralık 2016 Cumartesi

Java Array

 /***
/* N- boyutlu bir dizi içerisinde herbir elemanın tekrarlanma sayısını bulan bir static Array.counterArray(int[]) fonksiyonu.
örneğin:
Array{1,1,1,4,6,4,4,5,6,1}
1 den>4 adet
4 ten>3 adet
5 ten>1 adet
6 dan>2adet gibi

*********************************************************************************






















public class Array {
    public static int search(int[] k, int val) {
        for (int i = 0; i < k.length; i++) {
            if (k[i] == val) {
                return i;
            }
        }
        return -((int)Math.random()*val);
    }
    public static TValue counterArray(int[] dizi) {
        TValue t = new TValue();
        for (int i = 0; i < dizi.length; i++) {
            int val = dizi[i];
            int pc = 0;
            if (Array.search(Array.toCastInt(t.value.toArray()), val) < 0) {
                for (int j = i; j < dizi.length; j++) {
                    if (val == dizi[j]) {
                        pc++;
                    }
                }
                t.value.add(val);
                t.key.add(pc);
            } else {
                continue;
            }
        }
        return t;
    }
    private static int[] toCastInt(Object[] toArray) {
        int[] val = new int[toArray.length];
        for (int i = 0; i < val.length; i++) {
            val[i] = Integer.parseInt(toArray[i].toString());
        }
        return val;
    }
    public static void main(String[] args) {
          int[] d = {3,1,1,1,1,1,3,7,3,3,2,1,1};
        System.out.println("Array:"+Arrays.toString(d));
        TValue tem = Array.counterArray(d);
        System.out.println(tem.dump());
        System.out.println("search 2>index:"+Array.search(d, 2));
}
}





27 Ekim 2016 Perşembe

Java Netbeans Array Example

*********************************************************************************
*Java da  bir diziye n adet max-min aralığında rastgele sayı ekleyen ve bu sayıların birbirinden faklı olmasını sağlayan java kodu aşağıda verilmiştir.
* örneğin N =10 olduğunda max-min>=10 olmalıdır.
*N=20 ise max=25 min=5 ;  N<=(max-min) olmalıdır.
*********************************************************************************
public class Array {

    private static int binarySearch(int[] array, int val) {
        for (int i = 0; i < array.length; i++) {
            if (array[i] == val) {
                return i;
            }
        }
        int c = (int) ((Math.random() * (-(array.length - 1))) - 1);

        return c;

    }

    public static int[] uniqueRand(int min, int max, int adet) {
        int[] array = new int[adet];
        int in;
        int value;
        for (int i = 0; i < adet; i++) {
            do {
                value = (int) ((Math.random() * (max - min)) + min);
                in = Array.binarySearch(array, value);
            } while (!(in < 0));
            array[i] = value;
        }
        return array;
    }

    public static String toString(int[] a) {
        return Arrays.toString(a);
    }

    public static void main(String args[]) {
        int[] arr = Array.uniqueRand(10, 20, 8);
        System.out.println(Array.toString(arr));

    }
}
*********************************************************************
Cıktı:

run:

Array Lenght=8
Max=20;
Min=10;
[10, 12, 13, 18, 16, 15, 11, 17]
BUILD SUCCESSFUL (total time: 0 seconds)

14 Temmuz 2016 Perşembe

Entity FrameWork C#

Uzun en sql komutları yazmak yerine EntityFramework kullanarak ekleme,silme ve güncelleme işlemi daha az kodla cözüme kavuşturuldu....

 MarketOtomasyonEntities db=new MarketOtomasyonEntities();//Veritabanımızın modelini oluşturduk

        private void urun_ekle_Click(object sender, EventArgs e)
        {
            Urunler urun = new Urunler();//Urunler tablosunun bir modeli oluşturduk.Ekleme işlemi için                gerekli kod aşağıda verilmiştir
            urun.u_ad = "Kek";
            urun.u_kod = "1234568";
            urun.u_reyon_id = 2;
            urun.u_resim = null;
            db.Urunler.Add(urun);
            db.SaveChanges();
        }

        private void urun_sil_Click(object sender, EventArgs e)
        {
            var silinecek = db.Urunler.Where(w => w.u_id == 1).FirstOrDefault();//silinecek veri alındı.
            db.Urunler.Remove(silinecek);//Remove komutu veri silindi
            db.SaveChanges();//Değişikliklerin kaydedilmesi için SaveChanges() metodunu çağırdık.
        }

        private void urun_guncelle_Click(object sender, EventArgs e)
        {
            var guncellenecek = db.Urunler.Where(w => w.u_id == 1).FirstOrDefault();//Değişiklik                       yapılacak veri alındı.
            guncellenecek.u_kod = "010101";//değiştirilecek veri
            db.SaveChanges();//Değişikliklerin kaydedilmesi için SaveChanges() metodunu çağırdık.
        }
    }
}

13 Temmuz 2016 Çarşamba

Game Ball























/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Game;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;

/**
 *
 * @author ozaytunctan13
 */
public class GameBall extends JFrame implements ActionListener, MouseMotionListener {

    private int ballxSpeed = 7;
    private int ballySpeed = 5;
    private int paddlex = 0;
    private JPanel screen;
    private int scren_w = 800;
    private int scren_h = 600;
    private Ball top;
    private RectCollision rect;
    private int Ball_x = 0;
    private int Ball_y = 0;
    private int Ball_w = 30;
    private int Ball_h = 30;
    private int Rect_x = scren_w / 2;
    private int Rect_y = scren_h - 30;
    private int Rect_w = 100;
    private int Rect_h = 20;
    private long ball_speed = 1000;
    private boolean gameOver = false;

    public void initialize() {
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setLayout(null);
        this.setTitle(GameBall.class.getName());
        this.setBounds(200, 30, 800, 650);
        this.setBackground(Color.blue);
        this.setVisible(true);
        screen = new JPanel();
        this.setResizable(false);
        screen.setSize(800, 600);
        screen.setBackground(Color.BLACK);
        this.add(screen);
        Ball_x = (int) (screen.getSize().width) / 2;
        this.addMouseMotionListener(this);
        this.setLocationRelativeTo(null);

    }

    public GameBall(String title) {
        this.setTitle(title);
        initialize();
    }

    @Override
    public void paint(Graphics g) {
        super.paint(g);

        top = new Ball(Ball_x, Ball_y, Ball_w, Ball_h);
        rect = new RectCollision(paddlex, Rect_y, Rect_w, Rect_h);
        Graphics fr = screen.getGraphics();
        top.onDraw(fr);
        Graphics fr2 = screen.getGraphics();
        rect.onDraw(fr2);
        //Collision();

    }

    public void update(Graphics gr) {

    }

    public void Collision() {

        Ball_x = Ball_x + ballxSpeed;

        Ball_y = Ball_y + ballySpeed;

        // Window yukarı
        if (Ball_x >= paddlex && Ball_x <= paddlex + 100 && Ball_y >= 475) {

            ballySpeed = -7;
            // score++;

        }

        if (Ball_y >= 800) {

            // score = 0;
            Ball_y = 30;
            gameOver = true;

        }

        // Window aşağı
        if (Ball_y <= 0) {

            ballySpeed = 7;

        }

        // Window sağ
        if (Ball_x >= 800) {

            ballxSpeed = -5;

        }

        // Window sol
        if (Ball_x <= 0) {

            ballxSpeed = 5;

        }

        repaint();
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        Collision();
    }

    @Override
    public void mouseDragged(MouseEvent e) {

    }

    @Override
    public void mouseMoved(MouseEvent e) {
        //Rect sadece x yönünde hareket etmektedir width.
        paddlex = e.getX() - 50;
        repaint();
    }

    public static void main(String[] args) {
        GameBall b = new GameBall("title");
        Timer t = new Timer(30, b);
        t.start();
    }
}
/////////////////////////// Rect Class////////////////////////////////
public class RectCollision extends Rectangle{
     private int Ball_x;
    private int Ball_y;
    private int Ball_w;
    private int Ball_h;

    public RectCollision(int x, int y, int width, int height) {
        super(x, y, width, height);
        Ball_x = x;
        Ball_y = y;
        Ball_w = width;
        Ball_h = height;
      
    }

    public void onDraw(Graphics g) {
        g.setColor(new Color(255,255,30));
        g.drawRect(x, y, width, height);
        g.fillRect(x, y, width, height);
    }
}
////////////////////////////////////////Ball Class/////////////////////////////////////

public class Ball extends Rectangle  {

    private int Ball_x;
    private int Ball_y;
    private int Ball_w;
    private int Ball_h;

    public Ball(int x, int y, int width, int height) {
        super(x, y, width, height);
        Ball_x = x;
        Ball_y = y;
        Ball_w = width;
        Ball_h = height;
      
    }

    public void onDraw(Graphics g) {
        g.setColor(new Color(255,255,30));
        g.drawOval(x, y, width, height);
        g.fillOval(x, y, width, height);
    }
    public static void main(String[] args) {
        JFrame f=new JFrame("Title");
        f.setSize(500,500);
        Ball b=new Ball(5,5,30,30);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
    }
}



30 Haziran 2016 Perşembe

>>AudioPlayer>>

package open.sound;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import open.message.MessageBox;
import open.process.IOImageProcess;
import open.util.FileChoser;
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;

public class Ses {
    AudioStream audio = null;
    InputStream inputStream = null;
    String path;
    public Ses() {
    }
    Ses(String path) {
        path = path;
    }

    Ses(InputStream inputSound) {
        this.inputStream = inputSound;
    }
    public void Cal(String path) {
        try {
            inputStream = new FileInputStream(path);

            if (inputStream.available() > 0) {
                audio = new AudioStream(inputStream);
                AudioPlayer.player.start(audio);

            } else {
                MessageBox.showMessage("Ses dosyası bulunamdı");
            }
        } catch (Exception e) {
        }

    }
    public void Cal(){
        String path=FileChoser.chose();
       Cal(path);
    }
    public void kapat() {
        try {
            if (audio != null) {
                AudioPlayer.player.stop(audio);
            } else {
                MessageBox.showMessage("Ses kapatılamadı");
            }
        } catch (Exception e) {
        }
    }
    public static void main(String[] args) throws InterruptedException {
        Ses ses = new Ses();
        ses.Cal("C:\\Users\\ozaytunctan13\\Downloads\\Compressed\\2_wav_files (online-audio-converter.com)\\Java Video Tutorial - YouTube.wav");
        Thread.sleep(4000);
        ses.kapat();
    }
}