In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Today, I will talk to you about how to use Jbuilder 2005 to develop Java Applet applications. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.
I. New features of JBuilder 2005
JBuilder 2005 accelerates enterprise JavaBeans,WEB server, XML, mobile product and database application development, two-way visual design tools and quick invocation of J2EE application servers, including BEA WebLogic,IBM WebSphere,Sybase EAServer, JBoss and integrated Borland Enterprise Server. It has innovative and powerful JavaServer Faces,Struts and Web service design tools, supporting J2SE 5.0, UML code visualization, distributed factorization, code review, enterprise unit testing, multilingual control system, etc.
II. Illustrating JBuilder 2005 to develop Applet programs
Starting with a simple Applet program, we appreciate the power of JBuilder 2005 step by step. In order to improve the reader's perceptual awareness, I have provided clear graphics in each step.
Test the Applet program in JBuilder 2005
Borland has two Applet testing tools built into JBuilder 2005: AppletTestBed and Applet Viewer.
This article only introduces the convenience of JBuilder2005 in developing Applet programs, but this is only the tip of the iceberg of JBuilder2005's excellent performance. I just hope that readers can have a preliminary understanding of JBuilder2005 through this article. I will continue to introduce the application of JBuilder2005 in the development of EJB, Web services and integration with UML in future articles.
I. New features of JBuilder 2005
JBuilder 2005 accelerates enterprise JavaBeans,WEB server, XML, mobile product and database application development, two-way visual design tools and quick invocation of J2EE application servers, including BEA WebLogic,IBM WebSphere,Sybase EAServer, JBoss and integrated Borland Enterprise Server. It has innovative and powerful JavaServer Faces,Struts and Web service design tools that support J2SE 5.0, UML code visualization, distributed factorization, code review, enterprise unit testing, and support for multilingual control systems.
New features of JBuilder 2005 include:
1. Support the latest standards and quickly develop various types of Java applications
Borland JBuilder 2005 Enterprise supports all types of Java application development, including JSF, JavaServer Page (JSP), Servlets, Enterprise JavaBean (EJB), Web Services, Struts, XML, Swing, database applications, mobile device applications, etc. JBuilder helps developers understand the new features of the latest J2SE 5.0 (JDK 1.5) language and provides code refactoring (Refactoring) and debugging capabilities for J2SE 5.0 JBuilder 2005 also has a built-in Tomcat 2005 Web server that conforms to the Tomcat 1.4 specification.
2. Develop enterprise J2EE platform applications and deploy them to major application servers
By using the bi-directional visual EJB design tool, the Enterprise JavaBean that can be reused can be established quickly. A visual two-way deployment description editor (Deployment Descriptor Editor) to help you manage deployment structure (structure), transaction (transaction), policy (policies), permission roles (security role) and other attributes and information needed to combine and deploy EJB, and covers standard deployment description (Deployment Descriptor) and server-specific deployment description. JBuilder closely integrates multiple industry-leading J2EE application servers, including Borland Enterprise Server, BEA WebLogic Server, JBoss, IBM WebSphere and Sybase EAServer.
3. Simplify the development of JavaServer Faces and Struts applications
Using many tools and sprites provided by JBuilder, it becomes easier to develop dynamic Web applications by using JSF, Struts, Servlets, JavaServer Page and JSP expression language (Expression Language). Using process design tools, existing Web applications can be combined to form full-function applications. Struts design tools combine the tools needed to develop Struts-based applications. In addition, the TagInsight wizard can automatically prompt tags (Tag) for JSP, HTML and XML files, and can mark JSP expression language (Expression Language) keywords in different colors to improve the speed of program code writing and reduce the chance of errors.
4. Deliver high-quality and high-performance applications
JBuilder 2005 Enterprise is the only Java integrated development environment on the market that fully integrates performance tuning tools, including a built-in profiling tool (profiler), an executive debugger (thread debugger) and a program code coverage analysis tool (Code Coverage) to help developers identify issues related to correcting performance. The J2EE performance profiling tool Borland Optimizeit Request Analyzer has been added to JBuilder 2005 Enterprise to help you analyze the execution efficiency of program code across different levels (tiers) in the J2EE architecture.
In addition, the program code audit (code audit) tool built into JBuilder 2005 can automatically detect common errors in coding, thus helping the development team to build high-quality and high-performance application systems.
Second, develop Applet applications with JBuilder 2005
To assist us in developing, testing, and deploying Applet applications, JBuilder2005 provides the following tools:
Applet Wizard: you can quickly establish the basic structure of Applet and the corresponding HTML files.
AppletTestBed:JBuilder provides Applet execution and testing tools, which we can use to view the results of Applet execution.
Applet execution and testing tool provided by Applet Viewer:Sun Microsystems company.
(I) use Applet Wizard
The Applet Wizard provided by JBuilder 2005 can help us to establish the basic program code of Applet. Start Applet Wizard in the following way:
● selects File | New to open the "Object Gallery" dialog box.
● in the Web pane, select the Applet icon and press the [OK] button. (figure 1 below)
Figure 1 (Click to enlarge)
Here are the steps for Applet Wizard:
In step 1, we will enter the HelloApplet,directory column in the name column to change the path to c: jbprojectHelloApplet, and check the [Generate standard method) option. Press the [Next] button to proceed to step 2. (figure 2 below)
Figure 2 (Click to enlarge)
In step 2, there are JDK version, Output path, Backup path, working directory, and selected default path and test path. Here we all choose the default values and press the [Next] button to proceed to step 3. (figure 3 below)
Figure 3 (Click to enlarge)
In step 3, we modify the values of the Title, Description, Copyright, Company, author, and version fields in class Javadoc fields, and press the [Finish] button to use the default values for other items. (figure 4 below)
Figure 4 (Click to enlarge)
Next, start the following four steps of Applet Wizard: (figure 5 below)
Figure 5 (Click to enlarge)
● Package field: the name of the suite to which Applet belongs. The default is the name of the current project.
● Class name field: the name of the Applet class.
● Base class field: the basic class inherited by Applet, which is divided into java.applet.Applet and javax.swing.JApplet; the former is the AWT suite, and the latter uses the Swing suite.
This step also includes the following three options:
● Generate header comments: add header annotation information to the Applet class file (set in the General pane of the Project Properties dialog box).
● Can run standalone: add a main () method to the Applet class (the main purpose is to facilitate testing) so that we don't need to write a separate HTML file to test Applet.
● Generate standard methods: establish standard Applet methods, such as start (), stop (), destroy (), getAppletlnfo (), and getParameterlnfo () methods.
Select the [Next] button to proceed to the next step: (figure 6 below)
Figure 6 (Click to enlarge)
Now we can set the parameters that we want to pass in Applet. Applet Wizard generates a < param > tag within the < applet > tag of the HTML file and adds the necessary program code to the Applet class file. Clicking the [Add Parameter] button will generate a new piece of data, and its Name field value defaults to param0.
Select the [Next] button to proceed to the next step: (figure 7 below)
Figure 7 (Click to enlarge)
In this step, if we check the [Generate HTML Page) option, Applet Wizard will create a HTML file that contains the < applet > tag needed to call Applet. In addition, we can set the properties of the < applet > tag through the Name, Codebase, Width, Height, and other fields.
Select the [Next] button to proceed to the next step: (figure 8 below)
Figure 8 (Click to enlarge)
In this step, we can define the "run-time configuration" (runtime configuration) of Applet. If there is no "runtime configuration" defined in our project, [Create a runtime configuration) will be checked by default, please specify the name of "runtime configuration" in the Name field. Press the [Finish] button to leave Applet Wizard. Going back to the Project Pane, we will find that Applet Wizard produces two files: HelloApplet.java and HelloApplet.html.
(2) compile and execute HelloApplet
Although HelloApplet doesn't have any functionality yet, it's already an out-and-out Applet, so let's take a look at its implementation results. Select Run | Run Proiect from the AppBrowser main menu, and the execution result is shown in figure 9.
Figure 9 (Click to enlarge)
When we press the [Exit] button to leave, the next step is to design the Applet user interface.
(3) Design Applet user interface
In this step, we will use the design tools of JBuilder 2005 to add a rich user interface to HelloApplet, as follows.
1. In the Project Pane, double-click the HelloApplet.java file with the left mouse button to open it in the JBuilder editor.
2. Select the Design tab below the editor.
3. As shown in figure 10, first select the this node in the component tree of the structure pane, and then change the Layout property of the this node to BorderLayout (originally < defaultlayout >) in the viewer.
Figure 10 (Click to enlarge)
4. Add two Panel container objects to the Applet according to the following steps
Click the AWT tab of the component tray, select the java.awt.Panel component in the AWT tab, and then click the this node of the structure pane with the left mouse button. The new Panel object will appear under the this node, named panel1. Set the Constraints property of panel1 to North in the viewer. Add the second Panel object, following the previous step, and set its Constraints property to Center.
5. Change the name and properties of the Panel object
Right-click on panel1, select [Rename], and change its name to UpperPanel. Then change the background property to Light Gray in the viewer.
Right-click on panel2, select [Rename], and change its name to LowerPanel. Then change the background property to White in the viewer (we can also set the background color as we like).
6. Add two Panel objects to LowerPanel
Set the layout property of LowerPanel to CardLayout, select the java.awt.Panel component of the AWT tab in the component tray, and then click the LowerPanel node of the structure pane. this action adds a Panel object. The newly added Panel object appears below the LowerPanel node (named panel1). Add a second Panel object (named panel2) according to this point.
Set the Layout property of panel1 and panel2 to BorderLayout, and the background property of panel1 and panel2 to White and Pink, respectively.
After completing all the above steps, please save our project first. Now that we have completed the basic prototype of the Applet user interface, we are going to add some UI components.
(4) designing UpperPanel container objects
Follow these steps to add two UI components (Label and Choice) to UpperPanel:
1. Select java.awt.Choice component in the AWT tab of the component tray, and then click the UpperPanel node of the structure pane. The new Choice component will appear below the UpperPanel node.
2. Select the java.awt.Label component in the AWT tab of the "component tray", and then click the UpperPanel node of the "structure pane". This action will add a new Label component. The new Label component will appear below the UpperPanel node.
3. Change the properties of the lable1 object:
Click the label1 object in the structure pane and change the Text property to Select a language:. Click the button on the font property to open the Font dialog box and enter 20 in the Size field. Set the foreground property to Blue, and the "Select a Language:" string will be displayed in blue.
4. Add a Label component to the panel1 and panel2 objects respectively. First select the java.awt.Label component of the AWT tab in the component tray, and then click the panel1 node under the LowerPanel node. The newly added Label object will appear below the panel1 node (named label2). According to this point, add another Label component (named label3) to the panel2.
5. Set the properties of label2 in the following ways
Set the text property to Good Movning!, the constraints property to Center, and the alignment property to CENTER. Click the button on the font property and set Size to 24 in the Font dialog box.
6. Set the properties of label3 in the following ways
Set the text property to "good morning" and the constraints property to the Center,alignment property to CENTER. Click the button on the font property and set Size to 24 in the Font dialog box.
After completing the above steps, you will see the following figure 11:
Figure 11 (Click to enlarge)
(5) designing Choice objects
In this step, we will add two options to the Choice object and add the necessary program code.
1. Click the Source tab at the bottom of the editor to switch to the source code editing screen.
2. Click the init () method of the structure pane, and JBuilder 2005 will automatically move the cursor to the declaration position of the init () method.
3. Add the following two lines of program code to the init () method, identified in blue (above the try/catch block): (figure 12 below)
Figure 12 (Click to enlarge)
Choice1.addItem ("English")
Choice1.addItem ("Chinese")
Description: the additem () method adds an option to the Choice object.
4. Click the Design tab to return to the UI design tool.
5. Click the choice1 node in the structure pane, and then select the Event tab of the Viewer.
6. Double-click the itemStateChaoged event with the left mouse button, and JBuilder will add a choice1_itemStateChanged () method to the HelloApplet.java and move the cursor to the location of the method.
7. Refer to the following example to write the content of the choice1_itemstateChanged () method, identified in blue (shown in figure 13 below).
Public void choice1_itemStateChanged (ItemEvent e) {
If ("English" .equals (choice1.getSelectedItem () {
CardLayout1.show (LowerPanel, "panel1")
}
Else if ("Chinese" .equals (choice1.getSelectedItem () {
CardLayout1.show (LowerPanel, "panel2")
}
}
-
Figure 13
When HellloApplet is executed, if the Choice option is "English", "Good Movning!" is displayed in the LowerPanel object. String (contained in the panel1 container); if the Choice option is "Chinese", the "good morning" string is displayed in the LowerPanel object (contained in the panel2 container).
8. Save the JBuilder project, compile and execute HelloApplet, and the execution result is shown in figure 14.
Figure 14
9. Switch the drop-down menu (Choice object) next to [Select a language] to "Chinese", and we will change the message below to "good morning". As shown in figure 15.
Figure 15
The Applet1.java source code is as follows:
Package helloapplet
Import java.awt.*
Import java.awt.event.*
Import java.applet.*
/ * *
* < p > Title: Study < / p >
*
* < p > Description: This is a Stendent < / p >
*
* < p > Copyright: Copyright (c) 2004 < / p >
*
* < p > Company: < / p >
*
* @ author ghq
* @ version 1.0
, /
Public class Applet1 extends Applet {
Boolean isStandalone = false
BorderLayout borderLayout1 = new BorderLayout ()
BorderLayout borderLayout2 = new BorderLayout ()
Panel UpperPanel = new Panel ()
Panel LowerPanel = new Panel ()
CardLayout cardLayout1 = new CardLayout ()
Panel panel1 = new Panel ()
BorderLayout borderLayout3 = new BorderLayout ()
Panel panel2 = new Panel ()
BorderLayout borderLayout4 = new BorderLayout ()
Choice choice1 = new Choice ()
Label label1 = new Label ()
Label label2 = new Label ()
Label label3 = new Label ()
/ / Get a parameter value
Public String getParameter (String key, String def) {
Return isStandalone? System.getProperty (key, def):
(getParameter (key)! = null? GetParameter (key): def)
}
/ / Construct the applet
Public Applet1 () {}
/ / Initialize the applet
Public void init () {
Choice1.addItem ("English")
Choice1.addItem ("Chinese")
Try {
JbInit ()
} catch (Exception e) {
E.printStackTrace ()
}
}
/ / Component initialization
Private void jbInit () throws Exception {
This.setLayout (borderLayout2)
UpperPanel.setForeground (Color.lightGray)
LowerPanel.setForeground (Color.white)
LowerPanel.setLayout (cardLayout1)
Panel1.setLayout (borderLayout3)
Panel2.setForeground (Color.pink)
Panel2.setLayout (borderLayout4)
Panel1.setForeground (Color.white)
Label1.setFont (new java.awt.Font ("Dialog", Font.PLAIN, 20))
Label1.setForeground (Color.blue)
Label1.setText ("" Select a Language: "")
Label2.setAlignment (Label.CENTER)
Label2.setFont (new java.awt.Font ("Dialog", Font.PLAIN, 24))
Label2.setText ("" Good Movning! "")
Label3.setAlignment (Label.CENTER)
Label3.setFont (new java.awt.Font ("Dialog", Font.PLAIN, 24))
Label3.setText ("good morning")
Choice1.addItemListener (new Applet1_choice1_itemAdapter (this))
This.add (UpperPanel, java.awt.BorderLayout.NORTH)
UpperPanel.add (label1)
UpperPanel.add (choice1)
This.add (LowerPanel, java.awt.BorderLayout.CENTER)
LowerPanel.add (panel1, "panel1")
LowerPanel.add (panel2, "panel2")
Panel1.add (label2, java.awt.BorderLayout.CENTER)
Panel2.add (label3, java.awt.BorderLayout.CENTER)
}
/ / Get Applet information
Public String getAppletInfo () {
Return "Applet Information"
}
/ / Get parameter info
Public String [] getParameterInfo () {
Return null
}
Public void choice1_itemStateChanged (ItemEvent e) {
If ("English" .equals (choice1.getSelectedItem () {
CardLayout1.show (LowerPanel, "panel1")
}
Else if ("Chinese" .equals (choice1.getSelectedItem () {
CardLayout1.show (LowerPanel, "panel2")
}
}
}
Class Applet1_choice1_itemAdapter implements ItemListener {
Private Applet1 adaptee
Applet1_choice1_itemAdapter (Applet1 adaptee) {
This.adaptee = adaptee
}
Public void itemStateChanged (ItemEvent e) {
Adaptee.choice1_itemStateChanged (e)
}
}
Test the Applet program in JBuilder 2005
When the Applet is developed, we can directly test whether the execution result of Applet is correct in JBuilder 2005 in the following two ways:
● leverages AppletTestBed of JBuilder 2005.
● leverages Sun Microsystems's Applet Viewer.
1. Use AppletTestBed of JBuilder 2005
AppletTestBed is the Applet execution environment provided by JBuilder 2005. When we select Run | Run Project, we will start AppletTestBed and execute the "main class" of the JBuilder project. We can set Applet as the "main class" of the project in the following ways:
1) Select Project | Project Properties and open the "Project Properties" dialog box.
2) switch to the Run pane and press the [New] button to create a new "runtime configuration", or press the [Edit] button to edit the existing "runtime configuration".
3) after opening the "New Runtime Configuration" dialog box, we can define what the "main class" is in the Main class field.
The result of executing Applet with AppletTestBed contains four buttons at the top:
Info: display the parameters of Applet; Start: execute Applet; Stop: stop Applet; Exit: leave AppletTestBed.
2. Applet Viewer using Sun Microsystems
When you want to use Applet Viewer to execute Applet in JBuilder 2005, you must pass a HTML file that contains the < applet > tag. Just right-click on the HTML file and select (Run using "Runtime configuration name") to start Applet Viewer.
3. Matters needing attention when developing Applet
The main execution environment of Applet is Web browser. In order for Applet to execute correctly in the client browser, make sure that the client browser provides JDK support. In addition, the JDK version should also be consistent with Applet, otherwise the Applet execution result may be different than expected.
In the process of developing Applet, we may have encountered some problems. It is clear that Applet can be compiled smoothly, but it cannot be displayed correctly on the HTML page. The problem usually occurs because the attribute definition of the < applet > tag is incorrect, for example:
1) ignore the Java language must be case-sensitive
When you define the code or archive attribute of the < applet > tag, its name and case must be exactly the same as the file name on the server, otherwise the Applet class file cannot be loaded.
2) the code attribute does not specify the full class name
The Applet class file defined by the code attribute must contain the package (and subsuite) name.
3) incorrect setting of codebase attribute
If the Applet references another class file or JAR file, its path must be defined in the codebase property.
4) missing archive attribute
A common way to deploy Applet is to wrap related files as JAR or ZIP files, in which case we must define the archive attribute within the < applet > tag.
If we use the Applet Wizard of JBuilder 2005 to develop Applet, we can choose whether this type of HTML file is automatically generated by JBuilder.
Here are two points we must consider when developing Applet:
1. The version of JDK supported by the browser
With the evolution of Java technology, JDK alone is divided into several versions. Some developers prefer to develop programs with newer JDK, but they often overlook one thing: in general, users don't usually update the version of the browser themselves.
As a result, there is often a dilemma in which some people can perform Applet normally, but others cannot. In response to the above problems, we should start from two aspects:
1) the Web browser that requires or assists all employees in the company must be updated.
2) if the Applet application is accessible through Intemet, add a warning message to the page, such as "for best execution, please make sure our browser version is above XXX".
If we encounter problems with different versions of the browser JDK, we can refer to the following solutions:
1) use the Java plug-in (plug-in):
Most of the JDK incompatibility problems can be solved by "Java plug-in". For example, if our Applet uses the Swing library, but the JDK version of the client browser is too old to support Swing.
We can ask the client to update the browser version, or go to http://java.sun.com/products/plugin/ to find the appropriate plug-in.
2) the version of JDK used during development is as consistent as possible with the client.
3) use Java Web Start.
Java Web Start is a new technology developed by Sun Microsystem Company. Users can click on a link within a web page to launch Applet or other applications. This technology can effectively solve the problem of different versions of JDK. As long as the client browser installs the Java Web Start plug-in program in advance, the Applet can be executed correctly.
2. Security issues
Sending applications over the network to the client for execution-this is the most criticized aspect of Applet. Because the network is an open environment, anything transmitted on the network may be intercepted, stolen or even changed. Therefore, special attention must be paid to the security of the application when developing Applet. We must also be aware that some operations can be performed in a normal Java application, but are not allowed in Applet.
In order to prevent Applet execution from destroying or stealing client computer data for unknown reasons (possibly the program code has been tampered with), all Applet will be executed in a secure environment, which we call Sandbox. This security mechanism ensures that users' computers will not be affected by dangerous programs. At present, Applet can be safely transmitted and used on the network, and the Sandbox mechanism plays an important role! Under the protection of this mechanism, Applet cannot delete or change file names within the host, create files, or check file and directory names. The Java interpreter also strictly checks whether Applet performs any illegal operations and interrupts program execution as soon as it occurs. In addition, Applet can only exchange data with the original Web server and cannot transfer the data to other computers. These features must be paid special attention to when developing Applet. With these strict protection measures, the security problems that users may face can be reduced to a minimum.
Here are some development tips related to Applet security:
1) tagging Applet
This approach ensures the integrity of Applet in the transmission process, but it has some disadvantages. At this stage, there is no standard for making markup for Applet. If we want further information, please go to http://www.suitable.com/docs/signing.html.
2) consider using other technologies to overcome the security limitations of Applet
Some security restrictions in Applet may prevent certain actions from being performed, which can be done in conjunction with other Java technologies. For example, if we want to write data back to the Web server, we might as well use Servlet to do so (because Servlet is an application executed on the server side, unlike Applet, which needs to be passed to the client to execute, there is no doubt that the program code will be tampered with).
After reading the above, do you have any further understanding of how to develop Java Applet applications with Jbuilder 2005? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.