Belajar JAVA? bisa kaleeee….

Sebagian besar para penggila JAVA,pasti tahu lah apa itu GUI? Yakni salah satu tampilan model interaksi tampilan grafis yang mengandung alat-alat untuk melakukan pekerjaan interaktif dimana tujuannya tidak lain agar user dapat dengan mudah mengoperasikan sebuah OS(User Friendly)
Nah berikut ini adalah salah satu bentuk event dari java, yakni MouseEventHandling. Event itu sendiri ialah segala peristiwa yang terjadi pada GUI.Nah,daripada penasaran dan jantung dag-dig-dug…mending langsung saja cekidot…
Listing:

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

public class MouseEventHandling extends JFrame
implements MouseListener, MouseMotionListener {

private JLabel statusBar;

public MouseEventHandling () {
super (“Mencoba Beberapa Mouse Event Handling”);

statusBar = new JLabel();
getContentPane().add(statusBar,BorderLayout.SOUTH);

addMouseListener (this);
addMouseMotionListener (this);

setSize (300,100);
setLocationRelativeTo(null);
setVisible(true);
}

//MouseListener event handler
public void mouseClicked (MouseEvent e) {
statusBar.setText(“Clicked at [“+ e.getX() + “,” + e.getY() + “]”);
}

public void mousePressed (MouseEvent e) {
statusBar.setText(“Pressed at [“+ e.getX() + “,” + e.getY() + “]”);
}

public void mouseReleased (MouseEvent e) {
statusBar.setText(“Released at [“+ e.getX() + “,” + e.getY() + “]”);
}

public void mouseEntered (MouseEvent e) {
statusBar.setText(“Entered at [“+ e.getX() + “,” + e.getY() + “]”);
getContentPane().setBackground(Color.GREEN);
}

public void mouseExited (MouseEvent e) {
statusBar.setText(“Mouse outside window”);
getContentPane().setBackground(Color.WHITE);
}

//MouseMotionListener event handler
public void mouseDragged (MouseEvent e) {
statusBar.setText(“Dragged at [“+ e.getX() + “,” + e.getY() + “]”);
}

public void mouseMoved (MouseEvent e) {
statusBar.setText(“Moved at [“+ e.getX() + “,” + e.getY() + “]”);
}

public static void main (String args[]) {
MouseEventHandling test = new MouseEventHandling();
test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

About halojack

i'm a simple guy

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: