★ wanayoo — archive 1999 http://java.webdeveloper.com/articles/shoppingcart/page05.htmlNouvelle recherche | Portail wanayoo
Computer Digital Expo

The Event for Search Engine Marketing & Optimization


Find a Web Host With:
CGI Access
DB Support
NT Servers
UNIX Servers
Telnet Access

advanced search
Internet News
Internet Investing
IT
Windows Technology
Linux/Open Source
Developer
Interactive Marketing
xSP Resources
Small Business
Wireless Internet
Downloads
Internet Resources
Internet Lists
International
EarthWeb
Career Resources

Search internet.com
Advertise
Corporate Info
Newsletters
E-mail Offers
Be a Commerce Partner
Shop For Computers
Free Market Research
Promote Your Website
Remote PC Access
Top Selling Books
Remote PC Access
Submit Your Site
Web Hosting
Business Search
Best Deals on PDAs!
FlashKit
Gif.com
HierMenusCentral
JavaBoutique
JavaScript.com
JavaScriptSource
WebDev Jobs
JustSMIL
ScriptSearch
StreamingMediaWorld
Web Hosts
WebDevelopersJournal WDVL
WebDeveloper.com
WebReference.com
XMLFiles.com
CGI
HTML
Java
JavaScript
Web Design and Promotion
Web Site Development
E-mail Address:


Can you receive
HTML e-mail?

Yes   No

Zip Code:


JavaBoutique : Articles : Open Source Shopping Cart:

Contents
Introduction
Persistence: Method 1
Functionality
Persistence: Method 2
Illustration: Example 1: Applets
Illustration: Example 2: Active X
Illustration: Example 3: Pseudo-Constructor
The Code
Extended Examples
Shopping Cart and Database
Checkout
Multiple Merchants
Conclusion
Addendum: Mac Version and Back End Progress

An Illustration of These Techniques

The following code will place a frame on a web page, and then save its position as it is moved, so that it appears at the altered position when a new page is loaded. This demonstrates persistence.

An Applet Example

import java.awt.*;
import java.applet.*;

public class Applet1 extends Applet{
  public void init(){
    if(Constants.frame == null){
      Constants.frame = new Frame();
      Constants.frame.reshape((int)Constants.framex.intValue(),
      	(int)Constants.framey.intValue(),300,300);
    }
    Constants.frame.show();
  }

  public void stop(){
    Constants.framex = new Integer(Constants.frame.bounds().x);
    Constants.framey = new Integer(Constants.frame.bounds().y);
    Constants.frame.dispose();
    Constants.frame = null;
    }
}

abstract class Constants{
  static Frame frame;
  static Integer framex = new Integer(225);
  static Integer framey = new Integer(150);
}

Compiling this code will generate the two files Applet1.class and Constants.class.

Place the following code in HTML Page 1:

<HTML>
<HEAD>
</HEAD>
<BODY>
	<applet code=Applet1.class name=Applet1 width=1 height=1> </applet>
<A HREF="/old?u=http%3A%2F%2Fjava.webdeveloper.com%2Farticles%2Fshoppingcart%2FPage2.htm&y=1999">Page2.htm</A>
</BODY>
</HTML>

Place the following code in HTML Page 2:

<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
	<applet code=Applet1.class name=Applet1 width=1 height=1 id=Applet1> </applet>
<A HREF="/old?u=http%3A%2F%2Fjava.webdeveloper.com%2Farticles%2Fshoppingcart%2FPage1.htm&y=1999">Page1.htm</A>
</BODY>
</HTML>

When the applet is loaded, method init() is called. This creates a frame, and places it at the (x,y) position defined by variables framex and framey. A look at class Constants tells us that these are initialized at 225 and 150 respectively. Suppose that while Page1 is up, the user moves the frame. Method stop() is called automatically when Page1 is left by the user, and this determines the (x,y) position to which the frame was moved by the user, and remembers it by changing variables framex and framey. When the page is reloaded, method init() is called again. It seems obvious that the frame should be placed again at coordinates (225,150), as defined in class Constants, however, the values of variables framex and framey, when a reload occurs, are those set by method stop() when the previous page was left. The initialization in class Constants is ignored by a reload. Why? The program is not being restarted; it is simply being re-activated. That is the essence of persistence as generated by applet reloading.

There will be stability problems with the frame in some browsers, for it is constantly being destroyed and recreated again (our later examples remove this problem). This is associated with the Abstract Windows Toolkit, and is not linked to persistence. The said instability is present even when the applet is not being continually reloaded, and is caused by the fact that the applet must interact with a peer, which does the actual work of constructing the frame. The said instability is removed in three ways: the first is to adjust the order of frame operations so as to minimize pressure on the peer. The second is to follow every frame operation with a call to pack(). This appears to place a modal stop on further execution until the peer has completed its task. The third is to introduce delay loops at critical points. For instance, one might define the method pause(200), in which pause(time) is defined as follows:

void pause(int time){
  long startTime = System.currentTimeMillis();
  while(System.currentTimeMillis() < startTime + time){
    //infinite loop: time slicing creates a pause to give the peer an opportunity to finish
  }

Notice in the applet code that the frame name is defined in the abstract class Constants. This is absolutely essential for stability. Notice also that the class Constants is never instantiated. You can see already, in this example, that we have started to manipulate an abstract class.


NEXT ->


Applet Index
(sorted alphabetically)

A B C D E F G H I J K
L M N O P Q R S T U
V W X Y Z #s
The Java Source
(applets w/source code)

A B C D E F G H I J K
L M N O P Q R S T U
V W X Y Z

How to Add Java Applets to Your Site

New on the Java Boutique:

New Article:
A Barebones Guide to Usability Testing
At first glance, usability testing may seem like unnecessary, or additional work. In todays budget slashed world, it is not uncommon for projects not to have the luxury of this valuable phase. This is a dangerous path to tread. Let's look at how we can incorporate usability testing into our design process.
... [more articles]

New Tutorial:
Java Certification Path API
Certificate based security forms the basis for SSL (Secure socket layer) transactions? Every year billions of transactions involving trillions of dollars are done safely using the SSL protocol. This week we'll look at the role of the Java certification path API and see how it provides a mechanism to implement certification path functionality.
... [more Tutorials]

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

internet.com logo






Developer News

Will Users Buy a License from SCO to Run Linux?

Linux Community Doubts SCO Claims

Actional Updates Web Services Management Platform



Database Journal Launched!
Jupiter Media has announced the launch of Database Journal. DBJ offers SQL courses and other database related resources for beginner to expert developers.



DB Dude
DB Dude is a JDBC SQL query tool for real database developers who belive that it's still important to code their SQL statements by hand.
Download of the Week
DS PageFlipText
This applet displays a page-flip effect between texts. Over the animation you can also insert an image and a scroll-text.

JB User Poll
Which version of Java do you use the most?
The JavaBoutique Top 15:
1. ChompText
2. PulseText
3. DJPopMenu
4. NavBar
5. PingPong
6. RushHour
7. Chameleon
8. AScroll2
9. Encyclo
10. 3DMaze
11. AnimLetters_anim
12. Viewer
13. AdvPano
14. MatchIt
15. BMI
Want more? Check out our Top 100!

Refer-It
Affiliate Program and Referral Directory.
New on internet.com
Time Warner to Test Microsoft's iTV Software
Trial runs of the company's re-configured interactive guides are seen as a crucial test for Redmond's ambitions to break into television screens, once and for all.

Industry Responsible for Stopping Overseas Outsourcing?
A majority of Americans think the U.S. government and industry should be doing more to keep jobs at home and forgo overseas outsourcing, according to a new study. However, as fewer and fewer college students are studying computer science, the number of U.S. high-tech jobs going to foreign workers will continue to increase.

Big Changes Ahead for Red Hat
Massive changes are coming to a red fedora near you. Red Hat Linux is moving to a more open development model with less focus on boxed sets and more focus on community involvement.


Jupitermedia is publisher of the internet.com and EarthWeb.com networks.
Copyright 2003 Jupitermedia Corporation All Rights Reserved.

Legal Notices,  Licensing, Reprints, & Permissions,  Privacy Policy.
http://www.earthweb.com/
http://www.internet.com/