القائمة الرئيسية

الصفحات


السلام عليكم ورحمة الله وبركاته اليوم سوف أقدم لكم أكواد جافا جاهزة وهي أكواد لأحداث الماوس ماعليكم سوا أن تقوموا بنسخ الكود ولصقة ومن ثم التحكم بأحداث الماوس بكل أريحية تامة

_________
_____________________________________________________________ /*


/*
* 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 mousespyapplet.pkgextends.applet;
//50
/**
*
* @author a
*/
import java.awt.*;
import java.applet.*;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
public class MouseSpyAppletExtendsApplet {
public MouseSpyApplet()
{
MouseSpy listener = new MouseSpy();
addMouseListener(listener);
}
}
class MouseSpy implements MouseListener
{ public void mouseClicked (MouseEvent event)
{ System.out.println("Mouse cliked.x= " +event.getX()+

"Y="+event.getY());
}
public void mouseEntered (MouseEvent event)
{
System.out.println("Mouse entered.x="+event.getX() +
"Y="+event.getY());
}
public void mouseExited (MouseEvent event)
{
System.out.println("Mouse exited.x="+event.getX() +
"Y="+event.getY());
}
public void mousePressed (MouseEvent event)
{
System.out.println("Mouse pressed. x="+event.getX() +
"Y="+event.getY());
}
public void mouseReleased(MouseEvent event)
{
System.out.println("Mouse released.x="+event.getX()+
"Y="+event.getY());
}
}


______________________________________________________******

/*
* 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 eggapplet.pkgextends.applet;
//56
/**
*
* @author a
*/
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.awt.geom.*;
public class EggApplet extends Applet {
public EggApplet()
{
egg = new Ellipse2D.Double(0,0,EGG_WIDTH, EGG_HIGHT);

MouseClickListener listener = new MouseClickListener();
addMouseListener(listener); }
public void paint(Graphics g)
{
Graphics2D g2 = (Graphics2D)g;
g2.draw(egg);
}
private Ellipse2D.Double egg;
private static final double EGG_WIDTH = 30;
private static final double EGG_HIGHT = 50;
private class MouseClickListener extends MouseAdapter

{
public void mouseClicked(MouseEvent event)
{
int mouseX=event.getX();
int mouseY=event.getY();

egg.setFrame(mouseX-EGG_WIDTH/2, mouseY-EGG_HIGHT/2,
EGG_WIDTH, EGG_HIGHT);
repaint();
}
}
}


______________________________________________________******

/*
* 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 frametest2;
//60 ,61
/**
*
* @author a
*/
import javax.swing.JFrame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class FrameTest2 {
public static void main(String[] args)
{EmptyFrame frame = new EmptyFrame();
frame.setTitle("Close me!");
frame.show();
} }
class EmptyFrame extends JFrame
{public EmptyFrame()
{ final int DEFAULT_FRAME_WIDTH=300;
final int DEFAULT_FRAME_HIGHT=300;
setSize(DEFAULT_FRAME_WIDTH, DEFAULT_FRAME_HIGHT);
WindowCloser listener = new WindowCloser();

addWindowListener(listener);
private class WindowCloser extends WindowAdapter
public void windowClosing(WindowEvent event)
System.exit(0);
// TODO code application logic here
}
}
}


______________________________________________________******

/* * To change this template, choose Tools | Templates
* and open the template in the editor.
*/ package mouse56;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

import java.awt.geom.*;

/**

*
* @author a
*/
public class Mouse56 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
public class EggApplet extends Applet
{
public EggApplet()
{

egg=new Ellipse2D.Double(0,0,EGG_WIDTH,EGG_HIGHT);
MouseClickListener listener=new MouseClickListener();
addMouseSpyListener(listener);
public void paint(Graphics g)
Graphics2D g2=(Graphics2D)g;
g2.draw(egg);
privatet Ellipse2D.Double egg;
privatet static double EGG_WIDTH=30;
privatet static double EGG_HIGHT=50;
privatet class MouseClickListener extends Adapter
public void mouseClicked(MouseEvent event)
int mouseX=event.getX();
int mouseY=event.getY();
egg.setFrame(mouseX-EGG_WIDTH/2,mouseY-EGG-HIGHT/2,
EGG_WIDTH,EGG_HIGHT);
repaint();

}
}
// TODO code application logic hereApplet
}
}



______________________________________________________******

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package mouse52;

/**
*
* @author a
*/
public class Mouse52 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
class MouseClickListener implements MouseListener
{
public void mouseClicked(MouseEvent event)
{
// mouse click action here
}
public void mouseEntered(MouseEvent event)
{
// do nothing
}
public void mouseExited(MouseEvent event)
{
// do nothing
}
public void mousePressed(MouseEvent event)
{
// do nothing
}
public void mouseReleased(MouseEvent event)
{
// do nothing
}
}
}

______________________________________________________******


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package mouse5;
import java.awt.*;
import java.applet.*;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
/**
*
* @author a
*/
public class Mouse5 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
public class MouseSpyApplet extends Applet
public MouseSpyApplet()
MouseSpy listener=new MouseSpy()
addMouseSpyListener(listener);
class MouseSpyimplements MouseListener
public void mouseClicked(MouseEvent event)
System.out.println("Mouse clicked.x="+event.getX()+"Y="+event.getY);
public void mouseEntered(MouseEvent event)
System.out.println("Mouse entered.x="+event.getX()+"Y="+event.getY);
public void mouseExited(MouseEvent event)
System.out.println("Mouse exited.x="+event.getX()+"Y="+event.getY);
public void mousePressed(MouseEvent event)
System.out.println("Mouse pressed.x="+event.getX()+"Y="+event.getY);
public void mouseReleased(MouseEvent event)
System.out.println("Mouse released.x="+event.getX()+"Y="+event.getY);


// TODO code application logic here
}
}


شكراً لكم لدخولكم مدونتنا على النت نتمنى أن تزورونا قريباً وسيتم تنزيل الأكواد البرمجية والشروحات التقنية دائماً بفضل الله وبدعمكم لنا مع السلامة أصدقائي المبرمجين

تعليقات