⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 petstoreadminclient.java

📁 sun公司的petstore,一个J2ee的示例应用程序.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistributions of source code must retain the above copyright *   notice, this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright *   notice, this list of conditions and the following disclaimer in *   the documentation and/or other materials provided with the *   distribution. * * Neither the name of Sun Microsystems, Inc. or the names of * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * This software is provided "AS IS," without a warranty of any * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR * DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN * OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that Software is not designed, licensed or intended * for use in the design, construction, operation or maintenance of * any nuclear facility. */package com.sun.j2ee.blueprints.admin.client;import java.awt.*;import java.awt.event.*;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import javax.swing.*;import java.util.*;/** * Administration client that allows users to modify order information and also * view sales information.  Data is transferred using a client-server model. * TODO: If no network connection is currently available the data will be * cached locally until a network connection is available. * * @author Joshua Outwater */public class PetStoreAdminClient extends JFrame        implements PropertyChangeListener {    private static ResourceBundle bundle;    private DataSource dataSource;    private JTabbedPane ordersTabbedPane;    private JTabbedPane salesTabbedPane;    private JToggleButton ordersToggleButton;    private JToggleButton salesToggleButton;    private MouseHandler mouseHandler = new MouseHandler();    private About aboutDialog = null;    private static final String[] developerNames = {        "Joshua Outwater", "Hans Muller", "Vijay Ramachandran",        "Shannon Hickey", "Jeff Dinkins", "Mark Davidson", "Rene Schmidt",        "Norbert Lindenberg"};    /* Actions used for the menu bar and toolbar. */    private AbstractAction exitAction = new ExitAction();    private AbstractItemAction ordersAction = new OrdersAction();    private AbstractItemAction salesAction = new SalesAction();    private AbstractAction aboutAction = new AboutAction();    private DataSource.RefreshAction refreshAction;    /**     * Create a new administration client with the specified server     * information.     *     * @param hostname Hostname     * @param port Port on the host where the j2ee server is running.     * @param sessionID Unique ID for this session.     */    public PetStoreAdminClient(String petStoreProxyClassName, String hostname, String port, String endpoint) {        super(getString("PetStore.title"));        setSize(640, 480);        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        // Set up the data connection.        dataSource = new DataSource(this, petStoreProxyClassName, hostname, port, endpoint);        createUI();        setVisible(true);        // Force a refresh so we get some initial data.        refreshAction.actionPerformed(null);    }    private void about() {        if (aboutDialog == null) {            aboutDialog = new About(getString("About.title"),                getString("About.message"), developerNames, this, true);        }        aboutDialog.setLocationRelativeTo(this);        aboutDialog.setVisible(true);    }    private void createUI() {        getContentPane().setLayout(new BorderLayout());        // Create the sales orders pane.        OrdersViewPanel ordersViewPanel = new OrdersViewPanel(            dataSource.getOrdersViewTableModel());        OrdersApprovePanel ordersApprovePanel = new OrdersApprovePanel(            dataSource.getOrdersApproveTableModel());        ordersTabbedPane = new JTabbedPane();        ordersTabbedPane.add(getString("OrdersViewPanel.title"),            ordersViewPanel);        ordersTabbedPane.add(getString("OrdersApprovePanel.title"),            ordersApprovePanel);        // Create the sales tabbed pane.        PieChartPanel pieChartPanel =            new PieChartPanel(dataSource.getPieChartModel());        BarChartPanel barChartPanel =            new BarChartPanel(dataSource.getBarChartModel());        salesTabbedPane = new JTabbedPane();        salesTabbedPane.add(getString("PieChart.title"), pieChartPanel);        salesTabbedPane.add(getString("BarChart.title"), barChartPanel);        setJMenuBar(createMenuBar());        getContentPane().add(createToolBar(), BorderLayout.NORTH);        getContentPane().add(ordersTabbedPane, BorderLayout.CENTER);        getContentPane().add(StatusBar.getInstance(), BorderLayout.SOUTH);        // Install listeners for the events this class is interested in.        dataSource.addPropertyChangeListener(DataSource.ENABLE_ACTIONS, this);        dataSource.addPropertyChangeListener(DataSource.DISABLE_ACTIONS, this);        // Install listeners for the orders view panel.        dataSource.addPropertyChangeListener(DataSource.ORDER_DATA_CHANGED,            ordersViewPanel);        // Install listeners for the orders approve panel.        dataSource.addPropertyChangeListener(DataSource.ORDER_DATA_CHANGED,            ordersApprovePanel);        dataSource.addPropertyChangeListener(DataSource.ENABLE_ACTIONS,            ordersApprovePanel);        dataSource.addPropertyChangeListener(DataSource.DISABLE_ACTIONS,            ordersApprovePanel);        // Install the listeners for the pie chart panel.        dataSource.addPropertyChangeListener(DataSource.PIE_CHART_DATA_CHANGED,            pieChartPanel);        dataSource.addPropertyChangeListener(DataSource.ENABLE_ACTIONS,            pieChartPanel);        dataSource.addPropertyChangeListener(DataSource.DISABLE_ACTIONS,            pieChartPanel);        // Install the listeners for the bar chart panel.        dataSource.addPropertyChangeListener(DataSource.BAR_CHART_DATA_CHANGED,            barChartPanel);        dataSource.addPropertyChangeListener(DataSource.ENABLE_ACTIONS,            barChartPanel);        dataSource.addPropertyChangeListener(DataSource.DISABLE_ACTIONS,            barChartPanel);    }    private JMenuBar createMenuBar() {        JMenuBar menuBar = new JMenuBar();        JMenu menu = new JMenu(getString("FileAction.name"));        menu.setMnemonic(getMnemonic("FileAction.mnemonic"));        JMenuItem menuItem = new JMenuItem(exitAction);        menuItem.setMnemonic(getMnemonic("ExitAction.mnemonic"));        menuItem.addMouseListener(mouseHandler);        menu.add(menuItem);        menuBar.add(menu);        menu = new JMenu(getString("ViewAction.name"));        menu.setMnemonic(getMnemonic("ViewAction.mnemonic"));        ButtonGroup bg = new ButtonGroup();        menuItem = new JRadioButtonMenuItem(ordersAction);        menuItem.setMnemonic(getMnemonic("OrdersAction.mnemonic"));        menuItem.setToolTipText(            (String)ordersAction.getValue(Action.SHORT_DESCRIPTION));        menuItem.addMouseListener(mouseHandler);        menuItem.addItemListener(ordersAction);        ordersAction.addPropertyChangeListener(            new ToggleActionPropertyChangeListener(menuItem));        menuItem.setSelected(true);        bg.add(menuItem);        menu.add(menuItem);        menuItem = new JRadioButtonMenuItem(salesAction);        menuItem.setMnemonic(getMnemonic("SalesAction.mnemonic"));        menuItem.addMouseListener(mouseHandler);        menuItem.addItemListener(salesAction);        salesAction.addPropertyChangeListener(            new ToggleActionPropertyChangeListener(menuItem));        menu.add(menuItem);        bg.add(menuItem);        menuBar.add(menu);        return menuBar;    }    private JToolBar createToolBar() {        refreshAction = dataSource.getRefreshAction();        JToolBar toolBar = new JToolBar();        ordersToggleButton = new JToggleButton(ordersAction);        ordersToggleButton.setToolTipText(            (String)ordersAction.getValue(Action.SHORT_DESCRIPTION));        ordersToggleButton.setText(null);        ordersToggleButton.addMouseListener(mouseHandler);        ordersToggleButton.addItemListener(ordersAction);        ordersAction.addPropertyChangeListener(            new ToggleActionPropertyChangeListener(ordersToggleButton));        toolBar.add(ordersToggleButton);        salesToggleButton = new JToggleButton(salesAction);        salesToggleButton.setToolTipText(            (String)salesAction.getValue(Action.SHORT_DESCRIPTION));        salesToggleButton.setText(null);        salesToggleButton.addMouseListener(mouseHandler);        salesToggleButton.addItemListener(salesAction);        salesAction.addPropertyChangeListener(            new ToggleActionPropertyChangeListener(salesToggleButton));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -