Ask a question


Thursday, 20 August 2009 10:26

Layout managers in Java Swing

Layout Managers Layout managers are used in Java Swing applications to arrange objects when they are added to a Container object. The setLayout() method is used to override default layout managers appropriated to JPanel (FlowLayout) and JFrame (BorderLayout) containers. This section of the chapter discusses eight important layout managers: ❑ BorderLayout ❑ BoxLayout ❑ CardLayout ❑ FlowLayout ❑ GridbagLayout ❑ GridLayout ❑ SpringLayout ❑ GroupLayout BorderLayout The BorderLayout manager is the default layout for a frame. A BorderLayout uses five regions in its display space. Those regions are generally referred to as NORTH, SOUTH, WEST, EAST, and CENTER. Those regions generally refer to the same attributes that a map would use. The NORTH and SOUTH regions extend to the top and bottom areas of the Container, while the EAST and WEST regions extend from the bottom of the NORTH and top of the SOUTH regions and to the left and right sides of the Container, respectively. The CENTER region occupies all of the residual space that remains in the center of the Container. The BorderLayout manager is typically generated by instantiating a new BorderLayout class with a constructor that has no parameters or with a constructor that specifies two integer…
Wednesday, 19 August 2009 13:05

Exploiting Patterns in Java

Why Patterns Are Important A pattern is a proven solution to a software problem enabling reuse of software at the design level. The purpose of a pattern is to conceptually pair a problem with its design solution and then apply the solution to similar problems. Code-level reuse of software is desirable, but design-level reuse is far more flexible. Patterns are one of the greatest resources you will have in the design of object-oriented software. They will definitely help you to master the Java programming language, be more productive, and develop effective Java solutions. Building Patterns with Design Principles At the core of any pattern is a collection of design principles. This section looks at a simple and unconventional approach to building patterns from the ground up. The approach is to start with a simple design and gradually make changes so the design is more flexible. Each step uses the object-oriented tools available to you in Java, as well as one or more of the design principles discussed in the previous section. Each design change becomes a step in building more complex design patterns. By following the exercises in this section, it will be clear how applying design principles makes software…
Wednesday, 19 August 2009 11:24

Key Java Language Features and Libraries

  Language Features Added in Java 5   Several useful syntactic elements were introduced in Java 5. All these features are supported by an updated compiler, and all translate to already defined Java bytecode, meaning that virtual machines can execute these features with no need for an update: ❑ Generics: A way to make classes type-safe that are written to work on any arbitrary object type, such as narrowing an instance of a collection to hold a specific object type and eliminating the need to cast objects when taking an object out of the collection. ❑ Enhanced for loop: Acleaner and less error-prone version of the for loop for use with iterators. ❑ Variable arguments: Support for passing an arbitrary number of parameters to a method. ❑ Boxing/unboxing: Direct language support for automatic conversion between primitive types and their reference types (such as int and Integer). ❑ Type-safe enumerations: Clean syntax for defining and using enumerations, supported at the language level. ❑ Static import: Ability to access static members from a class without need to qualify them with a class name. ❑ Metadata: Coupled with new tools developed by third-party companies, saves developers the effort of writing boilerplate code by…
Saturday, 12 September 2009 12:21

Agile Java Development - Runtime Technologies

Runtime Technologies  This section provides a brief description of the runtime technologies. Runtime technologies are used to run the application after it is deployed, versus development tools, which are used to develop the application. Figure 1.1 provides a visual representation of how these technologies fit together to provide a complete runtime solution.   Java Platform, Standard Edition (Java SE) Development Kit (JDK) We will use the latest version of the JDK (for example, 1.5) available from the java.sun.com website. Note that as long as we have JDK 1.4 or later, the technologies covered in this book (Hibernate and Spring, for example) will work just fine. The Spring Framework (springframework.org) The Spring Framework contains a large number of classes and packages, but it is designed as a modular framework that can be phased gradually into a project by using only the features needed (for example, web framework). Spring complements Java/JEE by providing an Inversion of Control (IoC) container (explained later in book), a web framework, a transaction management abstraction layer, JDBC helper classes, job scheduling APIs, email capabilities, and more. Spring has been around since 2002 and has gained considerable momentum and support from the community, including commercial vendors such as…
Page 4 of 4