CST8221 – JAP (Solution)

$ 20.99
Category:

Description

Lab 2 – Application Title (Splash) Screen with Borders Objectives

The purpose of the lab is to give you a hand-on experience of how to create an application splash (title) screen and how to create a border for a GUI component. Splash screens are an intrinsic part of any modern GUI application. Their primary purpose is to inform the user that the application is starting up while at the same time it is loading all necessary resources.

The Nature of Things Swing
Class JWindow

Component Borders
You can place a border around any Swing component that extends JComponent. There are eight border styles: Bevel, Soft Bevel, Empty, Etched, Line, Matte, Titled, and Compound. The MatteBorder border area can be filled with a solid color or an icon. The JComponent class contains a border property that is inherited by all Swing components. (Top-level containers that do not inherit from JComponent, like JFrame, JWindow, and JDialog, cannot have borders.) By default, the border property is null (no border), but you can access and modify it using the getBorder() and setBorder() methods. Once you have set a component’s border, the component always paints itself using that border, and the insets of the border replace the component’s default insets.
Borders are grouped into a separate package within the Swing hierarchy: javax.swing.border. All Swing borders directly or indirectly extend the AbstractBorder class, which in turn implements the more fundamental Border interface. Swing allows you to mix any number of border styles into a single border object. This gives Swing borders a useful compositional feature not often found in other windowing toolkits. See code examples for details: SwingBordersDemo.java.

Useful link: http://www.java2s.com/Code/Java/Swing-JFC/BorderDemo.htm

JavaFX
JavaFX does not have a container similar to JWindow but the Stage class serves the same purpose (Stage actually extends Window in JavaFX). See code examples for details:
SplashScreenDemoFX.java.
In Java FX you can set border in two different ways. You can use CSS to style the borders around a node; or you can use the Border class introduced in Java 8. See code examples for details: BordersDemoFX.java.
CST8221 – JAP, Lab 2, MMXVII Page 1 of 2
Tasks

Download the CST8221_Lab2_code.zip file from Blackboard. Extract the contents. Four different code examples are provided for you. Two are Swing examples and the other two are similar FX examples. Compile and run the examples one by one and examine carefully the code. Consult the Java documentation to find out what the different classes and methods are implementing.
Once you understand how the code works modify SplashScreenDemo.java so that when run it displays a splash screen with an image of your liking and your name at the bottom of the splash window.

Note: To launch the program from the command line you must find the folder containing your class files (or jar file) and copy the image there. Then you can launch the program.

Another Note: Since Java 6 there it is possible to display a simple a splash screen without writing any line of code. You can ask the virtual machine to display an image before even starting to load the application classes. There are also other ways to create splash sceens with Swing.
For more details how to do that visit the following link: http://docs.oracle.com/javase/tutorial/uiswing/misc/splashscreen.html

JavaFX has introduced a special Preloader class which can be used to create complex splash screens. Visit the link below for more details.
http://docs.oracle.com/javafx/2/deployment/preloaders.htm

Before the lab Enjoy Java.
During the lab
Ask questions and modify the splash window program. Before leaving the lab Demonstrate your work.
Sign the attendance sheet.
After the lab
Remember what you have learned. You will need it later.
Submission
No submission is required for this lab but you have to demonstrate your work before the end of the lab period if you want to earn some marks.

Marks: 1% of your course mark
The lab exercise will be marked according to the following marking method:

public int markLab2(boolean demonstration, boolean program){ int mark = 0;
if(demonstration & program) mark = 1; return mark;
}
The purpose of borders:
“Good fences make good neighbors” but also “Fences restrict the view”
CST8221 – JAP, Lab 2, MMXVII Page 2 of 2

Reviews

There are no reviews yet.

Be the first to review “CST8221 – JAP (Solution)”

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