• Complain

Sharan - Beginning Java 8 APIs, extensions, and libraries Swing, JavaFX, JavaScript, JDBC and network programming APIs: [third in a series of three: continue your learning, with focus on Java APIs, extensions

Here you can read online Sharan - Beginning Java 8 APIs, extensions, and libraries Swing, JavaFX, JavaScript, JDBC and network programming APIs: [third in a series of three: continue your learning, with focus on Java APIs, extensions full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. City: Berkeley;CA;New York, year: 2014, publisher: Apress;Springer, genre: Computer. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

Sharan Beginning Java 8 APIs, extensions, and libraries Swing, JavaFX, JavaScript, JDBC and network programming APIs: [third in a series of three: continue your learning, with focus on Java APIs, extensions
  • Book:
    Beginning Java 8 APIs, extensions, and libraries Swing, JavaFX, JavaScript, JDBC and network programming APIs: [third in a series of three: continue your learning, with focus on Java APIs, extensions
  • Author:
  • Publisher:
    Apress;Springer
  • Genre:
  • Year:
    2014
  • City:
    Berkeley;CA;New York
  • Rating:
    5 / 5
  • Favourites:
    Add to favourites
  • Your mark:
    • 100
    • 1
    • 2
    • 3
    • 4
    • 5

Beginning Java 8 APIs, extensions, and libraries Swing, JavaFX, JavaScript, JDBC and network programming APIs: [third in a series of three: continue your learning, with focus on Java APIs, extensions: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Beginning Java 8 APIs, extensions, and libraries Swing, JavaFX, JavaScript, JDBC and network programming APIs: [third in a series of three: continue your learning, with focus on Java APIs, extensions" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

Sharan: author's other books


Who wrote Beginning Java 8 APIs, extensions, and libraries Swing, JavaFX, JavaScript, JDBC and network programming APIs: [third in a series of three: continue your learning, with focus on Java APIs, extensions? Find out the surname, the name of the author of the book and a list of all author's works by series.

Beginning Java 8 APIs, extensions, and libraries Swing, JavaFX, JavaScript, JDBC and network programming APIs: [third in a series of three: continue your learning, with focus on Java APIs, extensions — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Beginning Java 8 APIs, extensions, and libraries Swing, JavaFX, JavaScript, JDBC and network programming APIs: [third in a series of three: continue your learning, with focus on Java APIs, extensions" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Kishori Sharan 2014
Kishori Sharan Beginning Java 8 APIs, Extensions and Libraries 10.1007/978-1-4302-6662-4_1
1. Introduction to Swing
Kishori Sharan 1
(1)
AL, US
In this chapter, you will learn
  • What Swing is
  • The difference between a character-based interface and a graphical user interface
  • How to develop the simplest Swing program
  • What a JFrame is and how it is made up of different components
  • How to add components to a JFrame
  • What a layout manager is and different types of layout managers in Swing
  • How to create reusable frames
  • How to handle events
  • How to handle mouse events and how to use the adapter class to handle mouse events
What Is Swing?
Swing provides graphical user interface (GUI) components to develop Java applications with a rich set of graphics such as windows, buttons, checkboxes, etc. What is a GUI? Before I define a GUI, let me first define a user interface (UI). A program does three things:
  • Accepts inputs from the user
  • Processes the inputs, and
  • Produces outputs
A user interface provides a means to exchange information between a user and a program, in terms of inputs and outputs. In other words, a user interface defines the way the interaction between the user and a program takes place. Typing text using a keyboard, selecting a menu item using a mouse, or clicking a button can provide input to a program. The output from a program can be displayed on a computer monitor in the form of character-based text, a graph such as a bar chart, a picture, etc.
You have written many Java programs. You have seen programs where users had to provide inputs to the program in the form of text entered on the console, and the program would print the output on the console. A user interface where the users input and the programs output are in text form is known as a character-based user interface . A GUI lets users interact with a program using graphical elements called controls or widgets , using a keyboard, a mouse, and other devices.
Figure shows a program that lets users enter a persons name and date of birth (DOB), and save the information by using the keyboard. It is an example of a character-based user interface.
Figure 1-1 An example of a program with a character-based user interface - photo 1
Figure 1-1.
An example of a program with a character-based user interface
Figure lets the user perform the same actions, but using a graphical user interface. It displays six graphical elements in a window. It uses two labels ( Name: and DOB: ), two text fields where the user will enter the Name and DOB values, and two buttons ( Save and Close ). A graphical user interface, compared to a character-based user interface, makes the users interaction with a program easier. Can you guess what kind of application you are going to develop in this chapter? It will be all about GUI. GUI development is interesting and a little more complex than character-based program development. Once you understand the elements involved in GUI development, it will be fun to work with it.
Figure 1-2 An example of a program with a graphical user interface This - photo 2
Figure 1-2.
An example of a program with a graphical user interface
This chapter attempts to cover the basics of GUI development using Swings components and top-level containers. Care has been taken to explain GUI-related details for those programmers who might not have used any programming languages/tools (e.g. Visual C++, Visual Basic, VB.NET, or PowerBuilder) to develop a GUI before. If you have already used a GUI development language/tool, it will be easier for you to understand the materials covered in this chapter. Swing is a vast topic and it is not possible to cover every detail of it. It deserves a book by itself. In fact, there are a few books in the market dedicated to only Swing.
A container is a component that can hold other components inside it. A container at the highest level is called a top-level container . A JFrame , a JDialog , a JWindow , and a JApplet are examples of top-level containers. A JPanel is an example of a simple container. A JButton , a JTextField , etc. are examples of components. In a Swing application, every component must be contained within a container. The container is known as the components parent and the component is known as containers child. This parent-child relationship (or container-contained relationship) is known as containment hierarchy . To display a component on the screen, a top-level container must be at the root of the containment hierarchy. Every Swing application must have at least one top-level container. Figure shows the containment hierarchy of a Swing application. A top-level container contains a container called Container 1, which in turn contains a component called Component 1 and a container called Container 2, which in turn contains two components called Component 2 and Component 3.
Figure 1-3 Containment hierarchy in a Swing application The Simplest - photo 3
Figure 1-3.
Containment hierarchy in a Swing application
The Simplest Swing Program
Lets start with the simplest Swing program. You will display a JFrame , which is a top-level container with no components in it. To create and display a JFrame , you need to do the following:
  • Create a JFrame object.
  • Make it visible.
To create a JFrame object, you can use one of the constructors of the JFrame class. One of the constructors takes a string, which will be displayed as the title for the JFrame . Classes representing Swing components are in the javax.swing package, so is the JFrame class. The following snippet of code creates a JFrame object with its title set to Simplest Swing:
// Create a JFrame object
JFrame frame = new JFrame("Simplest Swing");
When you create a JFrame object, by default, it is not visible. You need to call its setVisible (boolean visible) method to make it visible. If you pass true to this method, the JFrame is made visible, and if you pass false , it is made invisible.
// Make the JFrame visible on the screen
frame.setVisible(true);
That is all you have to do to develop your first Swing application! In fact, you can wrap the two statements, to create and display a JFrame , into one statement, like so:
new JFrame("Simplest Swing").setVisible(true);
Tip
Creating a JFrame and making it visible from the main thread is not the correct way to start up a Swing application. However, it does not do any harm in the trivial programs that you will use here, so I will continue using this approach to keep the code simple to learn, so you can focus on the topic you are learning. It also takes an understanding of event-handling and threading mechanisms in Swing to understand why you need to start a Swing application the other way. explains how to start up a Swing application in detail. The correct way of creating and showing a JFrame is to wrap the GUI creation and make it visible in a Runnable and pass the Runnable to the invokeLater() method of the javax.swing.SwingUtilities or java.awt.EventQueue class as shown:
Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Beginning Java 8 APIs, extensions, and libraries Swing, JavaFX, JavaScript, JDBC and network programming APIs: [third in a series of three: continue your learning, with focus on Java APIs, extensions»

Look at similar books to Beginning Java 8 APIs, extensions, and libraries Swing, JavaFX, JavaScript, JDBC and network programming APIs: [third in a series of three: continue your learning, with focus on Java APIs, extensions. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Beginning Java 8 APIs, extensions, and libraries Swing, JavaFX, JavaScript, JDBC and network programming APIs: [third in a series of three: continue your learning, with focus on Java APIs, extensions»

Discussion, reviews of the book Beginning Java 8 APIs, extensions, and libraries Swing, JavaFX, JavaScript, JDBC and network programming APIs: [third in a series of three: continue your learning, with focus on Java APIs, extensions and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.