Home » Archives for Ilias Tsagklis » Page 9

Author Archives: Ilias Tsagklis

Avatar photo
Ilias is a software developer turned online entrepreneur. He is co-founder and Executive Editor at Java Code Geeks.

GetFocusTraversalKeys example

In this example we are going to see how to get the focus traversal keys of an input device in a Java Desktop Application. This is quite simple and to do it you have to follows these steps Create an input device like an JButton. Create a new HashSet to hold AWTKeyStroke objects. Use the JButton.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS) call to get the ...

Read More »

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 »

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 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 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 »

Drag and Drop example

In this tutorial we are going to see how to build a simple application that performs drag and drop operations in a Java Desktop Application. As you know the drag and drop operation is very important in an Application that has to deal with graphical objects. In short, in order to add drag and drop functionality to your application you ...

Read More »

Focus listener example

Bipartite Graph

This is an example that discusses how to use FocusListener in Java. This is a very handy feature when you have several components and you want to monitor and handle the event when on of them gains or looses focus. In short, all you have to do in order to work with a FocusListener is: Create a new FocusListener Override the methods that correspond to ...

Read More »

Prevent an Application Window or Component from gaining focus

Bipartite Graph

With example we are going to see how to prevent a window and a graphical object from gaining focus in a Java Desktop Application. This is very simple, as the only thing you have to do is: Call setFocusable(false) to prevent a component from gaining focus. Call setFocusableWindowState(false) to prevent a window from gaining focus. Call getCurrentKeyboardFocusManager().clearGlobalFocusOwner() to remove the ...

Read More »

Exit application when Frame is closed example

Bipartite Graph

With this tutorial we shall show you how to exit from your application when a frame is closed. This is a very common use for most GUI applications. This is very easy to do, all you have to do is: Create a new WindowAdapter instance. Override windowClosing method to customize the handling of that specific event. Now every time a ...

Read More »

Set a clipping area from a Shape example

Bipartite Graph

In this example we shall show you how to set a clipping area from a component, in this case an image. This is a very basic operations that you will need when you are working in Java desktop applications that have rich graphcis. Basically all you have to do in order to set a clipping aread from a shape is: ...

Read More »