Java Web Hosting for Developers

Developing Applications with Java

public Jiflet() { this( “Generic Jiflet”, “Jiflet”, null,

Filed under: Java Web Hosting — webmaster @ 5:18 am

The second constructor defaults to a log level of I for informational. errorLog //**************************************************************************** //* errorLog &n bsp; * //**************************************************************************** public void errorLog( String logEntry ) This method allows you to create error log entries without specifying the Log.ERROR logging level each time. It is simply a convenience method. log //**************************************************************************** //* log & nbsp; * //**************************************************************************** public void log( char logLevel, String logEntry ) public void log( String logEntry ) This method creates a log entry that is written to the log file. If there is an error or the log file is not open, the output goes to the screen. The second constructor defaults to a log level of I for informational. handleEvent //**************************************************************************** //* handleEvent ; * //**************************************************************************** public boolean handleEvent( Event anEvent ) This overrides the default Frame.handleEvent() method. It listens for destruction events so that the jiflet can close itself down cleanly. action //**************************************************************************** //* action &nbs p; * //**************************************************************************** public boolean action( Event event, Object arg )

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Tomcat Web Hosting services

Developing Applications with Java

public Jiflet() { this( “Generic Jiflet”, “Jiflet”, null,

Filed under: Developing Intranet Applications with Java — webmaster @ 5:18 am

This method receives ACTION_EVENT events from the event system. It listens for menu events and passes them to Jiflet.handleMenuEvent(). handleMenuEvent //**************************************************************************** //* handleMenuEvent & nbsp; * //**************************************************************************** protected boolean handleMenuEvent( Event event, Object arg ) This is a placeholder for menu events. This does nothing in the Jiflet class. It must be overridden by derived classes to include any functionality. shutDown //**************************************************************************** //* shutDown &n bsp; * //**************************************************************************** public boolean shutDown( int level ) This method is the central point of exit for the jiflet. With the exception of a program crash, the jiflet always exits through this method. It is responsible for writing a log entry for the application ending, and it calls the Jiflet.destroy() method. The level argument is passed to the operating system as a return value for the calling program. suicide //**************************************************************************** //* suicide &nb sp; * //**************************************************************************** public void suicide( Exception e, String logLine, int level ) public void suicide( String logLine ) public void suicide( String logLine, int level ) public void suicide( Exception e ) public void suicide( Exception e, String logLine ) This method allows a jiflet to gracefully kill itself. Depending on the circumstances, you may or might not want a log entry written, and you may or may not have an Exception that caused your death.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Tomcat Web Hosting services

Developing Applications with Java

public Jiflet() { this( “Generic Jiflet”, “Jiflet”, null,

Filed under: Developing Intranet Applications with Java — webmaster @ 5:18 am

public Jiflet() { this( “Generic Jiflet”, “Jiflet”, null, false ); } public Jiflet( String title ) { this( title, “”, null, false ); } public Jiflet( String title, String name, String args[] ) { this( title, name, args, false ); } As you see, they all call the main constructor, setting some values to null or blanks. Methods There are many methods available in the Jiflet class. The following sections document their arguments and the purposes they serve. setVerboseMode public void setVerboseMode( boolean whichWay ) This method turns on or off verbose mode. If verbose mode is turned on, all log entries created with the Jiflet.verboseLog() method are actually passed to the log object. If verbose mode is turned off, all log entries created this way are ignored. Tip This, in conjunction with Jiflet.verboseLog(), offers an excellent debugging tool. Simply enable verbose mode when you need more detail, and in your code provide that detail with the Jiflet.verboseLog() method. verboseLog //**************************************************************************** //* verboseLog * //**************************************************************************** public void verboseLog( char logLevel, String logEntry ) public void verboseLog( String logEntry ) This method creates a log entry that is written to the log file only if the verbose mode flag is set to true.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Tomcat Web Hosting services

Developing Applications with Java

appName protected String appName; This string holds the name

Filed under: Java Web Hosting — webmaster @ 11:23 pm

else { appLogFile = new DiskLog( logPath, DiskLog.createLogFileName(), appName ); } } catch ( IOException e ) { // Write errors to the screen… errorLog( “Error opening log file for [” + appName + “] (” + e.toString() + “)” ); appLogFile = null; } // Turn on verbose mode… setVerboseMode( verbosity ); // Denote construction… log( “Application [” + appName + “] started at ” + ( new Date() ).toString() ); // Call my init! init(); // We are now active! activeFlag = true; // Call my run… run(); } Because the Jiflet class descends from Java’s Frame class, you need to call the superclass’s constructor with a title, which is what you do first. The following are done next: l The background color is set to light gray. l The jiflet is centered on the screen. l The status bar is created and enabled. l The default log is opened. l The configuration file is read into memory and combined with the program arguments. l The LogPath configuration option is retrieved from the configuration. l The actual disk log file is created. l Verbose mode is turned on or off depending on the value passed in. l A message is written to the log stating that the jiflet has started. l The user’s implemented init() method is called. The run() method is called. By default, the show() method of the Frame is called to display the jiflet on the screen. l The following are the other three constructors available for creating Jiflet objects:

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services

Developing Applications with Java

appName protected String appName; This string holds the name

Filed under: Java Web Hosting — webmaster @ 11:23 pm

appName protected String appName; This string holds the name of the application that is running. This is usually passed in at construction. appVerbosity protected boolean appVerbosity = false; If you choose, your jiflet can be configured to report more information about certain things. This verbosity level is turned on or off with this Boolean instance variable. It defaults to false and can be set with the Jiflet.setVerboseMode() method. configProperties protected ConfigProperties configProperties; This object holds the combined program arguments and the configuration parameters read from the application’s configuration file. Access to this variable is through the Jiflet.getParameter() methods. defaultLog protected ScreenLog defaultLog; This variable is a default log in case the real application log cannot be created. This log writes its entries to the standard out of the operating system. myConnector private DBConnector myConnector = null; This variable holds the DBConnector object that is associated with this jiflet. You can set and get this variable with the Jiflet.setConnector() and Jiflet.getConnector() methods. myStatusBar protected StatusBar myStatusBar = null; This variable holds the instance of the StatusBar object that is created for the jiflet. The status can be set or cleared with the Jiflet.showStatus() and Jiflet.clearStatus() methods. oldCursor private int oldCursor = -1; This private variable is used to store the value of the cursor while a “wait” cursor is displayed. This variable is used by the Jiflet.startWait() and Jiflet.endWait() methods. Constructors There are four ways to construct a jiflet. These are defined by four separate constructors. A constructor is the function that is called when an instance of your object is being created. Each of them are useful for different purposes. For the most part, most of your jiflets use the fourth incarnation. Let’s take a look at each constructor. Three of the constructors call the fourth constructor. This master constructor is where all the jiflet initialization takes place.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services

Developing Applications with Java

appName protected String appName; This string holds the name

Filed under: Developing Intranet Applications with Java — webmaster @ 11:23 pm

The following is the complete source code for this constructor: /** * Creates a Jiflet with a title, a name, arguments, and optionally * verbose. * * @param title The window title * @param name The name of the application * @param args The arguments passed in to the program * @param verbosity On/Off setting indicating verbosity of log entries * @see #setVerboseMode */ public Jiflet( String title, String name, String args[], boolean verbosity ) { // Call the superclass… super( title ); // Copy title to name… if ( name.equals( “” ) ) name = title; // Set the color… setBackground( Color.lightGray ); // Center and show our window! center(); // Add a status bar… enableStatusBar(); // Save my application name… appName = name; // Create a default log…. defaultLog = new ScreenLog( appName ); // Parse any passed in arguments… // Parse the configuration file if available… configProperties = new ConfigProperties( args, appName + “.cfg” ); // Reset the title… setTitle( getParameter( “Title”, title ) ); // Construct a log file name… String logPath = getParameter( “LogPath”, “” ); // Open the log file… try { if ( logPath.equals( “” ) ) { appLogFile = new DiskLog( appName ); }

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services

Developing Applications with Java

//* init * //**************************************************************************** public void init() {

Filed under: Java Web Hosting — webmaster @ 3:29 pm

//* init * //**************************************************************************** public void init() { add( new Label( “I’m a small applet” ) ); } //**************************************************************************** //* run & nbsp; * //**************************************************************************** public void run() { show(); } } As you can see, the init() method is used to implement the user interface for your applet. After the init() method is called by the applet framework, the applet framework then calls the run() method. In the preceding example, the run() method does nothing more than show the applet on the screen. Listing 12.2. The smallest applet’s HTML page. A small applet The applet framework provides several other useful facilities. One feature is the getParameter() method. This retrieves a parameter from the HTML file that launches the applet. For example, consider the HTML file shown in Listing 12.2. It contains two parameters, WIDTH and HEIGHT. Through the use of the getParameter() method, you can retrieve the value specified after the equal sign (=), like this: int myWidth = Integer.parseInt( getParameter( “WIDTH” ) ); This holds true for any property pair that appears in the HTML file. This is a convenient way to pass parameters to applets with an equally easy method of retrieving them. What if you make JIF as easy to use as an applet? What if you create intranet applications that implement the model application features as easily as creating applets? Let’s explore that possibility.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services

Developing Applications with Java

//* init * //**************************************************************************** public void init() {

Filed under: Java Web Hosting — webmaster @ 3:29 pm

Making JIF Easy to Use The first and most important thing you need to do is choose a name for your new bundle of joy. Let’s call it a jiflet. Because you basically take many of the applet ideas from Java and place them into your own new class, it seems rather appropriate. Now that you have that out of the way, you define what your jiflet does. The jiflet is a Java application that provides the features of your model intranet application in an easy-to-use wrapper. These features include your model features outlined earlier, plus many of the features in a standard Java applet. One such feature is an init() method that is called automatically by the framework. This is a centralized location to place all of the initialization code. Another feature is getting configuration parameters. You are able to retrieve parameters from the configuration file with a method such as the java.Applet.getParameter() method. In fact, the following methods are available in both applets and jiflets: l public void init() l public boolean isActive() l public void destroy() l public String getParameter( String name ) l public void resize(Dimension d) l public void resize(int width, int height) l public void showStatus(String msg) The only features really missing from jiflets that appear in applets are the multimedia methods. These methods provide a clean way for applets to load images and sound files off of a network. Because jiflets represent intranet applications, these features are not usually necessary. With the design goals laid out, let’s look into implementation of the classes. The JifApplication Interface To implement the jiflet, you employ the use of an interface. This interface defines the pattern or template to which all jiflets must adhere. There is a single method defined in JifApplication. In fact, Listing 12.3 shows the source code for JifApplication. Listing 12.3. The JifApplication interface. //**************************************************************************** //* JifApplication &n bsp; * //**************************************************************************** public interface JifApplication { //**************************************************************************** //* init * //**************************************************************************** public void init();

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services

Developing Applications with Java

//* init * //**************************************************************************** public void init() {

Filed under: Java Web Hosting — webmaster @ 3:29 pm

} This interface requires all jiflets to have an init() method. The rest of the methods that you’ve designed into the class exist in the Jiflet class. However, the init() method must be created by the user of the class. Using this interface allows you to declare your Jiflet class abstract. This means that you cannot instantiate the Jiflet class alone. You must always derive a class from it. The Jiflet Class The Jiflet class is the intranet application version of Java’s own Applet. It provides you with a framework to develop intranet applications quickly and easily. It brings together all of the usefulness of the other JIF packages into a single, easy-to-use, component. The Jiflet class implements the JifApplication interface as well as the Log interface (described in Chapter 9, “Logging Classes”). This allows it to have an init() method and adhere to the standard log interface. Let’s take a look at the Jiflet class in detail. You start with the instance variables. You then move to the constructors and then on to each of the methods. After finishing this chapter, you should have a good understanding of the Jiflet class and how to use it. Instance Variables The Jiflet class contains the following instance variables: protected boolean activeFlag = false; protected DiskLog appLogFile; protected String appName; protected boolean appVerbosity = false; protected ConfigProperties configProperties; protected ScreenLog defaultLog; private DBConnector myConnector = null; protected StatusBar myStatusBar = null; private int oldCursor = -1; The following sections look at each one and how it is used. activeFlag protected boolean activeFlag = false; The activeFlag is used to denote the activity of a jiflet. Its state can be queried by way of the Jiflet.isActive() method. It is set to true right before the run() method is called and set to false after the destroy() method is called. appLogFile protected DiskLog appLogFile; The appLogFile is the log file object for the jiflet. During construction, this object is created like so: appLogFile = new DiskLog( logPath, DiskLog.createLogFileName(), appName ); logPath is a configurable location in which to place all log files. The DiskLog.createLogFileName() method creates a standard log file name. Finally, appName is used on the standard log entry to identify the application that generates it.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services

Developing Applications with Java

But because Java doesn’t really have any object

Filed under: Java Web Hosting — webmaster @ 10:31 am

following package statement: package music_ui Placing your class into a package has a very important implication. Your class now has access to all public and non-public classes in its package. Your class also has access to all non-private methods and instance variables of each other class in the package. Caution When you define an instance variable and do not assign it an access modifier (for example, private, protected, public), it defaults to package. This is essentially private but all classes within the same package can see it. A similar arrangement exists in the C++ programming language. You can optionally declare a class to be a friend of another class. This allows it access to any non-private methods or instance variables in the target class. Think of packages as automatic friends. Introducing the Java Intranet Framework Chapter 7, “A Model Intranet Application,” defines the functionality that a typical intranet application has. To recap, here are the features: l Standard configuration file processing l Standard logging to screen or disk l Standard database connectivity l Standard look and feel In Chapters 8 through 10, you designed and created many classes that implement these features. For instance, the ConfigProperties class implements the configuration file processing. And the DiskLog class implements your standard logging. If you take a step back and look at what you’ve created, it’s really a framework for developing intranet applications with Java. It truly is a Java intranet framework! Therefore, you name this collection of classes the Java Intranet Framework. And like any good programming toolkit or library, it has a unique and pronounceable acronym: JIF. But now that you’ve created all of these classes, you need to organize them into a usable set of packages. This helps you to document, use, and later extend, JIF to its fullest potential. So how do you package the classes in JIF? Packaging the JIF Classes The best way to package JIF is in groups of functionality. As you recall, you have four functionality groups: utilities, logging, database, and user interface. These fit perfectly into four functionality packages. Naming your packages is quite simple. You use jif as your base package name and then add on the specifics. For example, the utilities package is called util, as in java.util. Table 12.2 shows the package names you have chosen and the class functionality that is contained within them. Table 12.2. The Java Intranet Framework packages. Package Description jif.awt Standard user interface classes and java.awt extensions jif.log Standard logging classes jif.sql Standard database connectivity classes and java.sql extensions jif.util Standard utility classes and java.util extensions

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services

Next Page »

Powered by Java Web Hosting