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

📄 categoryframe.java

📁 java在线商店的源代码。编写十分规范的哦
💻 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.orderentry;

import com.borland.dx.text.Alignment;

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import com.borland.dbswing.*;
import com.borland.dx.sql.dataset.*;
import com.borland.dx.dataset.*;

/**
 * CategoryFrame implements the Category Form that is used to maintain
 * Product Category records. This form allows users to view or update
 * existing categories, or enter new product categories.
 *
 * <P>
 * This class employs the Singleton pattern to ensure that the class has only
 * one instance. You can access the singleton instance by calling the
 * getCategoryFrame method.
 */
public class CategoryFrame extends JFrame {
  private static CategoryFrame myCategoryFrame;

  private static DataModule1 dataModule = DataModule1.getDataModule();

  JPanel contentPane;
  JPanel pnlToolbar = new JPanel();
  JPanel pnlMain = new JPanel();
  JdbStatusLabel jdbStatusLabel1 = new JdbStatusLabel();
  JScrollPane jScrollPane1 = new JScrollPane();
  JdbTable jdbTable1 = new JdbTable();
  JdbNavToolBar jdbNavToolBar1 = new JdbNavToolBar();
  BorderLayout borderLayout1 = new BorderLayout();
  BorderLayout borderLayout2 = new BorderLayout();
  BorderLayout borderLayout3 = new BorderLayout();
  JButton btnClose = new JButton();
  JPanel jPanel3 = new JPanel();
  JPanel jPanel4 = new JPanel();
  JButton btnNewProduct = new JButton();
  ResourceBundle res = Res.getBundle("com.borland.samples.orderentry.Res");
  JLabel imageLabel1 = new JLabel();
  GridBagLayout gridBagLayout1 = new GridBagLayout();

  /**
   * The constructor is public, but you should use the getCategoryFrame
   * method to get an instance of the class.
   */
  public CategoryFrame() {
    try {
      jbInit();   // initialize frame's controls (JBuilder designer)
    }
    catch (Exception e) {
      e.printStackTrace();
    };
  }

  /**
   * Method generated and maintained by JBuilder designer to initialize
   * control properties.
   * @throws Exception exception
   */
  private void jbInit() throws Exception{
    contentPane = (JPanel) this.getContentPane();
    contentPane.setLayout(borderLayout1);
    this.setSize(new Dimension(400, 350));
    this.setTitle(res.getString("CAF_Categories"));
    this.addWindowListener(new java.awt.event.WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        this_windowClosing(e);
      }
    });
    jdbStatusLabel1.setDataSet(dataModule.getCategoryDataSet());
    jdbTable1.setDataSet(dataModule.getCategoryDataSet());
    jdbNavToolBar1.setFloatable(false);
    jdbNavToolBar1.setButtonStateDitto(JdbNavToolBar.HIDDEN);
    jdbNavToolBar1.setButtonStateSave(JdbNavToolBar.HIDDEN);
    jdbNavToolBar1.setButtonStateRefresh(JdbNavToolBar.HIDDEN);
    jdbNavToolBar1.setDataSet(dataModule.getCategoryDataSet());
    pnlMain.setLayout(borderLayout2);
    pnlToolbar.setLayout(borderLayout3);
    btnClose.setText(res.getString("CAF_Close"));
    btnClose.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        btnClose_actionPerformed(e);
      }
    });
    btnNewProduct.setText(res.getString("CAF_New_Product"));
    imageLabel1.setHorizontalAlignment(SwingConstants.CENTER);
    imageLabel1.setIcon(new ImageIcon(this.getClass().getResource("images/categoryBanner.jpg")));
    btnNewProduct.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        btnNewProduct_actionPerformed(e);
      }
    });
    jPanel4.setLayout(gridBagLayout1);
    contentPane.add(pnlToolbar, BorderLayout.NORTH);
    pnlToolbar.add(imageLabel1, BorderLayout.CENTER);
    pnlToolbar.add(jPanel4, BorderLayout.SOUTH);
    contentPane.add(pnlMain, BorderLayout.CENTER);
    jScrollPane1.getViewport().add(jdbTable1);
    pnlMain.add(jScrollPane1, BorderLayout.CENTER);
    pnlMain.add(jPanel3, BorderLayout.SOUTH);
    jPanel3.add(btnNewProduct, null);
    jPanel4.add(jdbNavToolBar1, new GridBagConstraints(0, 0, 4, 1, 1.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPanel4.add(btnClose, new GridBagConstraints(4, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 5, 0, 5), 0, 0));
    contentPane.add(jdbStatusLabel1, BorderLayout.SOUTH);
  }


  /**
   * Class method to access the singleton instance of the class
   * @return CategoryFrame
   */
  public static CategoryFrame getCategoryFrame() {
    if (myCategoryFrame == null)
      myCategoryFrame = new CategoryFrame();

    return myCategoryFrame;
  }


  /**
   * Before closing the window, check for any pending changes,
   * and prompt user if there are changes pending.
   * Note that we need to both check if there is anything to Post,
   * and to check if there is anything to resolve.
   * @param e WindowEvent
   */
  void this_windowClosing(WindowEvent e) {
    try {
      QueryDataSet qdsCategory = dataModule.getCategoryDataSet();
      int status = qdsCategory.getStatus();
      if ( (qdsCategory.isEditing() || qdsCategory.isEditingNewRow()) ||
           ((status & (RowStatus.UPDATED|RowStatus.INSERTED|RowStatus.DELETED)) != 0)
         ) {
        int answer = JOptionPane.showConfirmDialog(this,
                                                   res.getString("CAF_Save_pending_changes?"),
                                                   res.getString("CAF_Save_Pending_Changes"),
                                                   JOptionPane.YES_NO_CANCEL_OPTION,
                                                   JOptionPane.QUESTION_MESSAGE);
        // Post changes and resolve them back to DB
        if (answer == JOptionPane.YES_OPTION) {
          qdsCategory.post();
          // if there are pending changes to be resolved,
          // save the changes via the Database.saveChanges()
          // method. Then refresh the dataset.
          status = qdsCategory.getStatus();
          if ( (status & (RowStatus.UPDATED|RowStatus.INSERTED|RowStatus.DELETED)) != 0) {
            qdsCategory.getDatabase().saveChanges(new DataSet[] {qdsCategory}, true);
            qdsCategory.refresh();
          }
        }
        // If user chooses no, then cancel any inserts or edits
        // and refresh the dataset.
        else if (answer == JOptionPane.NO_OPTION) {
          qdsCategory.cancel();
          qdsCategory.refresh();
        }
        // If user cancels, just return
        else //if (answer == JOptionPane.CANCEL_OPTION)
          return;
      }

      setVisible(false);
      dispose();

    }
    catch (Exception ex) {
      ex.printStackTrace();
      new DBExceptionDialog(this, res.getString("CAF_Error"), ex, true).show();
    }

  }

  /**
   * When Close button is clicked, call this frame's windowClosing
   * event handler to properly handle all dataset pending updates.
   * @param e ActionEvent
   */
  void btnClose_actionPerformed(ActionEvent e) {
    // close this Window
    this_windowClosing(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
  }


  /**
   * When New Product button is clicked, show the Product form
   * with a new product record inserted, default the category field to
   * the current category.
   * @param e ActionEvent
   */
  void btnNewProduct_actionPerformed(ActionEvent e) {
    try {
      // Get the ProductFrame and show centered in screen
      ProductFrame frame = ProductFrame.getProductFrame();
      CliffhangerApplication.showCenteredWindow(frame, false);

      // create a new Product, passing the Category String
      // to default the category of the new product
      // to this current category.
      frame.newProduct(dataModule.getCategoryDataSet().getString("Category"));
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
  }

}

⌨️ 快捷键说明

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