Cara Membuat Tulisan Bergerak Mengikuti Mouse di Netbeans


Kalau sebelumnya Coding agar Frame tampil di tengah, nah yang ini caranya biar tulisan mengikuti moyse teman…

ayo di simak:

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Toolkit;
import java.awt.event.MouseMotionListener;
import javax.swing.JFrame;

public class Hanif extends JFrame implements MouseMotionListener{

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

String c = “HANIF”;
int x,y;
int  a=0,  b=0;

public FrameTengah(){
this.setTitle(“Frame Tengah”);
this.setSize(500,500);

Dimension ukDimension = Toolkit.getDefaultToolkit().getScreenSize();
int lebar = ukDimension.width;
int tinggi = ukDimension.height;

int x = (lebar-this.getWidth())/2;
int y = (tinggi-this.getHeight())/2;

this.setLocation(x, y);
this.setVisible(true);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);

addMouseMotionListener(this);
}

public void paint(Graphics g) {
g.clearRect(0, 0, 500, 500);
g.drawString(c, a, b);
}
public void mouseDragged(MouseEvent e) {
i = e.getX ();
j = e.getY();
repaint();
}

public void mouseMoved(MouseEvent e) {
i = e.getX();
j = e.getY();
repaint();
}
}

Download Projek

Semoga bermanfaat ya….

Beli T-Shirt, Raglan dan Kids T-Shirt Original Ocean Seven

  1. T-Shirt, Raglan dan Kids T-Shirt Anime, Manga, Gamers dan Cartoon World (OceanSeven)
  2. T-Shirt, Raglan dan Kids T-Shirt Footbal Series (OceanSeven)
  3. T-Shirt, Raglan dan Kids T-Shirt Music Series (OceanSeven)
  4. T-Shirt, Raglan dan Kids T-Shirt OceanSeven – Custom dan Basic Tees (OceanSeven)
  5. T-Shirt, Raglan dan Kids T-Shirt OceanSeven -Kids Collections (OceanSeven)
  6. T-Shirt, Raglan dan Kids T-Shirt OceanSeven -Signature Serues (OceanSeven)
  7. T-Shirt, Raglan dan Kids T-Shirt  Social Media dan Photography (OceanSeven)
  8. T-Shirt, Raglan dan Kids T-Shirt Sport, Automotive dan Adventure (OceanSeven)
  9. T-Shirt, Raglan dan Kids T-Shirt Superheroes dan Movies (OceanSeven)

3 pemikiran pada “Cara Membuat Tulisan Bergerak Mengikuti Mouse di Netbeans

  1. Ping balik: Menampilkan Frame Di Tengah Pada Netbeans « R92M

  2. banyak errornya bang…
    ini dah q benerin…
    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package SplasScreen;

    /**
    *
    * @author Oxz
    */
    import java.awt.Dimension;
    import java.awt.Frame;
    import java.awt.Graphics;
    import java.awt.Toolkit;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionListener;
    import javax.swing.JFrame;

    public class MouseGenit extends JFrame implements MouseMotionListener{

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

    String c = “HANIF”;
    int x,y, i,j;
    int a=0, b=0;

    public MouseGenit(){
    this.setTitle(“Frame Tengah”);
    this.setSize(500,500);

    Dimension ukDimension = Toolkit.getDefaultToolkit().getScreenSize();
    int lebar = ukDimension.width;
    int tinggi = ukDimension.height;

    int x = (lebar-this.getWidth())/2;
    int y = (tinggi-this.getHeight())/2;

    this.setLocation(x, y);
    this.setVisible(true);
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);

    addMouseMotionListener(this);
    }

    public void paint(Graphics g) {
    g.clearRect(0, 0, 500, 500);
    g.drawString(c, a, b);
    }
    public void mouseDragged(MouseEvent e) {
    i = e.getX ();
    j = e.getY();
    repaint();
    }

    public void mouseMoved(MouseEvent e) {
    i = e.getX();
    j = e.getY();
    repaint();
    }
    }

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s