Home » Desktop Java » awt » event (page 7)

event

Arrow sketch on JFrame example

package com.javacodegeeks.snippets.desktop; import java.awt.Container; import java.awt.Graphics; import java.awt.Point; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JFrame; import javax.swing.JPanel; public class KeyFrame extends JPanel implements KeyListener { private Point start = new Point(0, 0); private Point end = new Point(0, 0); public static void main(String[] args) { JFrame jFrame = new JFrame(); jFrame.setTitle("ArrowSketch"); jFrame.setSize(300, 300); jFrame.addWindowListener(new WindowAdapter() { @Override ...

Read More »

KeyListener example

In this example we are going to see how you can use a KeyListener in Java, in order to monitor key events that take place in your applications. This is particularly useful when you want to add some key functionality to your app and it’s very important you want to monitor that has a very intensive keyboard activity. Basically, to use a KeyListener in ...

Read More »

Mouse motion listener example

With this tutorial we shall show you how to work with the MouseMotionListener interface in Java. It is a very useful feature when you want to have full control over mouse events and mouse input that the users give. It also particularly useful when you want to make your application behaves according to the mouse events that occur. This is very ...

Read More »

Handle mouse clicks example

In this short tutorial we are going to see how to monitor a very basic GUI event in Java Desktop Applications, which is mouse clicks. What we want to see is what button mouse the user pressed (left, middle or right click) and then we want to know the exact location, in coordinates, in our Frame that this event occurred. ...

Read More »

Handle key presses example

With this simple tutorial we are going to see how to implement a simple key listener for your Java Desktop Application. This is a very nice tool if your application offers rich keyboard activity to the user. In short, in order to implement a simple key listener in Java, one should perform these steps: Create a new KeyAdapter instance. Override the keyPressed method to ...

Read More »

Handle focus changes example

In this tutorial we are going to see how to handle focus changed in a Java Desktop Application. You might find this particularly useful if you have an application that contains many objects and you want to monitor the focus changes over these objects, if you always want to know the object that the user interacts with. You can use ...

Read More »

Handle action events example

In this tutorial we are going to see how ActionListener works in Java. This is one of the most important components you have to work with when you’re developing a GUI Application. The ActionListener is able to monitor a number of important events that occur in GUI Apps. In short, all you have to do to work with an ActionListener in Java is: Create an ActionListener instance. Override ...

Read More »

Determine click count example

With this tutorial we are going to see how can you determine the number of clicks that a user performed over an object in a Java Desktop application. This is very useful when you want the user to have rich interaction with your application using his mouse. You can also add extra functionality according to how many clicks the user did ...

Read More »