📄 ordertrackerapplet.java
字号:
/**
* Copyright (c) 1996-2004 Borland Software Corporation. All Rights Reserved.
*
* This SOURCE CODE FILE, which has been provided by Borland Software as part
* of a Borland Software product for use ONLY by licensed users of the product,
* includes CONFIDENTIAL and PROPRIETARY information of Borland Software.
*
* USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS
* OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
* THE PRODUCT.
*
* IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD BORLAND SOFTWARE, ITS
* RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY
* CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR
* DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES
* ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR
* DISTRIBUTION OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR
* DERIVED FROM THIS SOURCE CODE FILE.
*/
//------------------------------------------------------------------------------
// Copyright (c) 1996-2004 Borland Software Corporation. All Rights Reserved.
//------------------------------------------------------------------------------
package com.borland.samples.ordertracker;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.util.*;
import javax.swing.*;
import com.borland.dbswing.*;
import com.borland.dx.sql.dataset.*;
import com.borland.dx.dataset.*;
/**
* OrderTrackApplet defines the Applet subclass and user interface. Customers
* would use this applet in a web-browser to find information about a recent
* order they had placed. Given an order tracking number, they can find out
* status information, order and shipping dates, and the amount paid on the
* order.
* Note that this file also contains a frame wrapper that allows this Applet
* to be run as a standalone application. Because an Applet is a subclass of
* panel, it can simply be wrapped in a frame as shown below so that it can
* be run as either Applet in a browser or standalone application.
*/
public class OrderTrackerApplet extends JApplet {
boolean isStandalone = false;
private QueryDataSet qdsPOrders;
private ParameterRow pRow;
JPanel contentPane;
// Instantiate panels
JPanel getStatusPanel = new JPanel();
JPanel orderItemsPanel = new JPanel();
// Instantiate field controls components
JdbTextField orderNumberField = new JdbTextField();
JLabel orderNumberLabel = new JLabel();
JButton statusButton = new JButton();
JdbTextField orderStatusField = new JdbTextField();
JLabel orderStatusLabel = new JLabel();
JdbTextField orderDateField = new JdbTextField();
JLabel orderDateLabel = new JLabel();
JLabel shipDateLabel = new JLabel();
JdbTextField shipDateField = new JdbTextField();
JdbTextField amountField = new JdbTextField();
JLabel amountLabel = new JLabel();
ResourceBundle res = Res.getBundle("com.borland.samples.ordertracker.Res");
BorderLayout borderLayout1 = new BorderLayout();
GridBagLayout gridBagLayout1 = new GridBagLayout();
JLabel titleGraphic = new JLabel();
JLabel statusBar = new JLabel();
/**
* Get a parameter value
* @param key String
* @param def String
* @return String
*/
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}
/**
* Construct the applet
*/
public OrderTrackerApplet() {
}
/**
* Initialize the applet
*/
public void init() {
try {
// Initialize form objects
jbInit();
// Initialize data objects
initData();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* @throws Exception exception
*/
private void jbInit() throws Exception{
contentPane = (JPanel) this.getContentPane();
this.setSize(new Dimension(414, 176));
orderStatusField.setColumnName("Status");
orderStatusField.setEditable(false);
orderStatusField.setColumns(10);
orderStatusLabel.setPreferredSize(new Dimension(76, 21));
orderStatusLabel.setHorizontalAlignment(SwingConstants.RIGHT);
orderStatusLabel.setText(res.getString("Order_Status"));
orderDateField.setColumnName("orderDate");
orderDateField.setEditable(false);
orderDateField.setColumns(10);
orderDateLabel.setPreferredSize(new Dimension(65, 21));
orderDateLabel.setHorizontalAlignment(SwingConstants.RIGHT);
orderDateLabel.setText(res.getString("Order_Date"));
shipDateLabel.setPreferredSize(new Dimension(57, 21));
shipDateLabel.setHorizontalAlignment(SwingConstants.RIGHT);
shipDateLabel.setHorizontalTextPosition(SwingConstants.RIGHT);
shipDateLabel.setText(res.getString("Ship_Date"));
shipDateField.setEditable(false);
shipDateField.setColumns(10);
shipDateField.setColumnName("shipDate");
orderNumberLabel.setHorizontalAlignment(SwingConstants.LEFT);
orderNumberLabel.setText(res.getString("Tracking_Number"));
statusBar.setText(" ");
statusButton.setText(res.getString("Show_Status"));
statusButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
statusButton_actionPerformed(e);
}
});
contentPane.setLayout(borderLayout1);
getStatusPanel.setLayout(gridBagLayout1);
titleGraphic.setHorizontalAlignment(SwingConstants.CENTER);
titleGraphic.setIcon(new ImageIcon(this.getClass().getResource("images/status.gif")));
amountField.setColumns(10);
contentPane.add(getStatusPanel, BorderLayout.NORTH);
getStatusPanel.add(orderNumberLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
getStatusPanel.add(orderNumberField, new GridBagConstraints(1, 1, 3, 1, 1.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0));
getStatusPanel.add(statusButton, new GridBagConstraints(4, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
getStatusPanel.add(titleGraphic, new GridBagConstraints(0, 0, 5, 1, 1.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
contentPane.add(orderItemsPanel, BorderLayout.CENTER);
orderItemsPanel.add(orderStatusLabel, null);
orderItemsPanel.add(orderStatusField, null);
orderItemsPanel.add(orderDateLabel, null);
orderItemsPanel.add(orderDateField, null);
orderItemsPanel.add(amountLabel, null);
orderItemsPanel.add(amountField, null);
orderItemsPanel.add(shipDateLabel, null);
orderItemsPanel.add(shipDateField, null);
contentPane.add(statusBar, BorderLayout.SOUTH);
amountLabel.setHorizontalAlignment(SwingConstants.RIGHT);
amountLabel.setText(res.getString("Amount_Paid"));
amountField.setColumnName("amtPaid");
amountField.setEditable(false);
}
/**
* Start the applet
*/
public void start() {
}
/**
* Stop the applet
*/
public void stop() {
}
/**
* Destroy the applet
*/
public void destroy() {
}
/**
* Get Applet information
* @return String
*/
public String getAppletInfo() {
return "Applet Information";
}
/**
* Get parameter info
* @return String[][]
*/
public String[][] getParameterInfo() {
return null;
}
/**
* Main method
* @param args String[]
*/
static public void main(String[] args) {
OrderTrackerApplet applet = new OrderTrackerApplet();
// Running as an application
applet.isStandalone = true;
// Setup the container frame
JFrame frame = new JFrame();
frame.getContentPane().add(applet, BorderLayout.CENTER);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
System.exit(0);
};
});
// Setup the applet
applet.init();
applet.start();
// Pack the frame
frame.pack();
//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height)
frameSize.height = screenSize.height;
if (frameSize.width > screenSize.width)
frameSize.width = screenSize.width;
frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
// Show the frame containing the applet.
frame.setVisible(true);
}
private void initData() {
// Connect to the database and retrieve data set from DataModule
try {
OrderTrackerDataModule dataModule = OrderTrackerDataModule.getDataModule();
dataModule.dbConnect(); // Makes a connection to the database
qdsPOrders = dataModule.getOrdersDataSet();
pRow = dataModule.getOrderNumParameterRow();
}
catch (DataSetException ex) {
ex.printStackTrace();
}
}
void statusButton_actionPerformed(ActionEvent e) {
try {
if (orderNumberField.getText().equals("")) {
statusBar.setText(res.getString("Please_enter"));
orderStatusField.setDataSet(null);
orderStatusField.setText("");
orderDateField.setDataSet(null);
orderDateField.setText("");
shipDateField.setDataSet(null);
shipDateField.setText("");
amountField.setDataSet(null);
amountField.setText("");
return;
}
statusBar.setText(" ");
// Set the ORDERTRACKNUM parameter to the value entered in the field
pRow.setString("ORDERTRACKNUM", orderNumberField.getText());
// Get the data for that record
qdsPOrders.executeQuery();
// Associate each result field with the dataset
orderStatusField.setDataSet(qdsPOrders);
orderDateField.setDataSet(qdsPOrders);
shipDateField.setDataSet(qdsPOrders);
amountField.setDataSet(qdsPOrders);
}
catch (Exception ex) {
ex.printStackTrace();
}
}
} // END class OrderTrackApplet
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -