Java Swing ActionListener KeyListener Primer Tutorial

Java Swing ActionListioner KeyListener Primer Tutorial

Java Swing ActionListener KeyListener Primer Tutorial (try twirling round bottom of image for a synopsis ... 'do the twirl now')

Here is a tutorial that uses Swing functionality in Java to create a GUI (Graphical User Interface) desktop program on a Mac laptop (but same code may well work, compiled on a Windows laptop (the same way)) that tests your typing speed skills. As you can imagine, in order to measure your performance we’ll need to code for Keyboard events, via KeyListener and Mouse events, via ActionListener.

Some of the points of interest, and you may want to see our previous relevant Java Swing OptionPane Primer Tutorial as shown below, as well, are:

  • Is a desktop Java application that uses a Java Swing JFrame GUI framework
  • It implements Keyboard event functionality via KeyListener
  • It implements Mouse event functionality via ActionListener
  • Is a desktop Java application that uses a Java Swing JPanel and JButton and JTextArea (one with a JFrame parent and one with a JPanel parent) and JLabel (with a JFrame parent) GUI objects
  • Use of Java class BigDecimal for the purposes of presenting a String representation of a double rounded to one decimal place

Download programming source code and rename to TypingSpeed.java that has the very simple command line compilation procedure:

        javac TypingSpeed.java

        java TypingSpeed

Here is some information from Wikipedia regarding the Java Swing functionality, and here are some practitionerschortle … chortle.


Previous relevant Java Swing OptionPane Primer Tutorial is shown below.

Java Swing OptionPane Primer Tutorial

Java Swing OptionPane Primer Tutorial (try twirling round bottom of image for a synopsis ... 'do the twirl now')

Here is a tutorial that uses Swing functionality in Java to create a GUI (Graphical User Interface) program on a Mac laptop that displays calculator program performing +-*/^! Below is some information from Wikipedia regarding the Java Swing functionality:

Swing is the primary Java GUI widget toolkit. It is part of Oracle’s Java Foundation Classes (JFC) β€” an API for providing a graphical user interface (GUI) for Java programs.

Swing was developed to provide a more sophisticated set of GUI components than the earlier Abstract Window Toolkit (AWT). Swing provides a native look and feel that emulates the look and feel of several platforms, and also supports a pluggable look and feel that allows applications to have a look and feel unrelated to the underlying platform. It has more powerful and flexible components than AWT. In addition to familiar components such as buttons, check boxes and labels, Swing provides several advanced components such as tabbed panel, scroll panes, trees, tables, and lists.

Unlike AWT components, Swing components are not implemented by platform-specific code. Instead they are written entirely in Java and therefore are platform-independent. The term “lightweight” is used to describe such an element.[citation needed]

This program works a rudimentary calculator for +-*/^! functionality.

Let’s see some Java Swing code for this, and how it works …

Download programming source code and rename to Calculator.java

But of course regarding all the information above It Don’t Mean A Thing (if it ain’t got that swing).

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

This entry was posted in eLearning, Event-Driven Programming, Games, GUI, Operating System, Tutorials and tagged , , , , , , , , , , , . Bookmark the permalink.

3 Responses to Java Swing ActionListener KeyListener Primer Tutorial

  1. homepage says:

    Thank you for any other informative website.
    The place else may I am getting that type of information written in such a perfect manner?
    I have a venture that I am simply now operating on, and
    I’ve been at the glance out for such info.

  2. I blog frequently and I genuinely thank you
    for your content. Your article has truly peaked my interest.
    I’m going to take a note of your blog and keep
    checking for new information about once a week.

    I opted in for your Feed as well.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>