import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import java.text.*;
/**
* Gourmet Coffee System.
*
* @author iCarnegie
* @version 1.1.0
* @see Product
* @see Coffee
* @see CoffeeBrewer
* @see Catalog
* @see OrderItem
* @see Order
* @see Sales
* @see CatalogLoader
* @see FileCatalogLoader
* @see DataFormatException
* @see SalesFormatter
* @see PlainTextSalesFormatter
* @see HTMLSalesFormatter
* @see XMLSalesFormatter
* @see DataField
*/
public class GourmetCoffeeGUI extends JPanel {
/**
*
*/
private static final long serialVersionUID = 1L;
/* Standar error stream */
static private PrintWriter stdErr = new PrintWriter(System.err, true);
/* Window width in pixels */
static private int WIDTH = 620;
/* Window height in pixels */
static private int HEIGHT = 530;
/* Size of the catalog list cell in pixels */
static private int CATALOG_CELL_SIZE = 50;
/* Visible rows in catalog list */
static private int CATALOG_LIST_ROWS = 14;
/* Size of the order list cell in pixels */
static private int ORDER_CELL_SIZE = 100;
/* Visible rows in order list */
static private int ORDER_LIST_ROWS = 6;
/* Size quantity text field */
static private int QUANTITY__TEXTFIELD_SIZE = 5;
/* Size total text field */
static private int TOTAL__TEXTFIELD_SIZE = 8;
/* Rows in status text area rows */
static private int STATUS_ROWS = 10;
/* Rows in status text area cols */
static private int STATUS_COLS = 40;
private JList catalogList;
private JList orderList;
private JButton addModifyButton;
private JButton removeButton;
private JButton registerSaleButton;
private JButton displaySalesButton;
private JButton saveSalesButton;
private JPanel productPanel;
private JLabel quantityLabel;
private JLabel totalLabel;
private JTextField quantityTextField;
private JTextField totalTextField;
private JTextArea statusTextArea;
private JRadioButton plainRadioButton;
private JRadioButton HTMLRadioButton;
private JRadioButton XMLRadioButton;
private JFileChooser fileChooser;
private Catalog catalog;
private Order currentOrder;
private Sales sales;
private SalesFormatter salesFormatter;
private NumberFormat dollarFormatter;
/**
* Loads a product catalog and starts the application.
*
* @param args String arguments. Not used.
* @throws IOException if there are errors in the loading the catalog.
*/
public static void main(String[] args) throws IOException {
String filename = "";
if (args.length != 1) {
filename = "catalog.dat";
} else {
filename = args[0];
}
try {
Catalog catalog =
(new FileCatalogLoader()).loadCatalog(filename);
JFrame frame = new JFrame("Gourmet Coffee");
frame.setContentPane(new GourmetCoffeeGUI(catalog));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(WIDTH, HEIGHT);
frame.setResizable(true);
Dimension frameSize=frame.getSize();
Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((screenSize.width-frameSize.width)/2,
(screenSize.height-frameSize.height)/2);
frame.setVisible(true);
} catch (FileNotFoundException fnfe) {
stdErr.println("The file does not exist");
System.exit(1);
} catch (DataFormatException dfe) {
stdErr.println("The file contains malformed data: "
+ dfe.getMessage());
System.exit(1);
}
}
/**
* Instantiates the components and arranges them in a window.
*
* @param initialCatalog a product catalog.
*/
public GourmetCoffeeGUI(Catalog initialCatalog) {
// create the components
catalogList = new JList();
orderList = new JList();
catalogList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
catalogList.setVisibleRowCount(CATALOG_LIST_ROWS);
catalogList.setFixedCellWidth(CATALOG_CELL_SIZE);
orderList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
orderList.setVisibleRowCount(ORDER_LIST_ROWS);
orderList.setFixedCellWidth(ORDER_CELL_SIZE);
addModifyButton = new JButton("Add|Modify Order Item");
removeButton = new JButton("Remove Order Item");
registerSaleButton = new JButton("Register Sale of Current Order");
displaySalesButton = new JButton("Display Sales");
saveSalesButton = new JButton("Save Sales");
quantityLabel = new JLabel("Quantity:");
totalLabel = new JLabel("Total:");
quantityTextField = new JTextField("", QUANTITY__TEXTFIELD_SIZE);
totalTextField = new JTextField("$0.00", TOTAL__TEXTFIELD_SIZE);
totalTextField.setEditable(false);
statusTextArea = new JTextArea(STATUS_ROWS, STATUS_COLS);
statusTextArea.setEditable(false);
plainRadioButton = new JRadioButton("Plain", true);
HTMLRadioButton = new JRadioButton("HTML");
XMLRadioButton = new JRadioButton("XML");
ButtonGroup group = new ButtonGroup();
group.add(plainRadioButton);
group.add(HTMLRadioButton);
group.add(XMLRadioButton);
// Product Information panel
productPanel = new JPanel();
productPanel.setBorder(
BorderFactory.createTitledBorder("Product Information"));
// Catalog panel
JPanel catalogPanel = new JPanel();
catalogPanel.setBorder(BorderFactory.createTitledBorder("Catalog"));
catalogPanel.add (
new JScrollPane(catalogList,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER));
// "Add|Modify Product" panel
JPanel centralPanel = new JPanel(new BorderLayout());
JPanel addModifyPanel = new JPanel(new GridLayout(2, 1));
JPanel quantityPanel = new JPanel();
quantityPanel.add(quantityLabel);
quantityPanel.add(quantityTextField);
addModifyPanel.add(quantityPanel);
addModifyPanel.add(addModifyButton);
centralPanel.add(productPanel, BorderLayout.CENTER);
centralPanel.add(addModifyPanel, BorderLayout.SOUTH);
// Order panel
JPanel orderPanel = new JPanel(new BorderLayout());
orderPanel.setBorder(BorderFactory.createTitledBorder("Order"));
JPanel totalPanel = new JPanel();
totalPanel.add(totalLabel);
totalPanel.add(totalTextField);
JPanel buttonsPanel = new JPanel(new GridLayout(2, 1));
buttonsPanel.add(removeButton);
buttonsPanel.add(registerSaleButton);
orderPanel.add(totalPanel, BorderLayout.NORTH);
orderPanel.add(new JScrollPane(orderList,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER);
orderPanel.add(buttonsPanel, BorderLayout.SOUTH);
// Status panel
JPanel bottomPanel = new JPanel(new BorderLayout());
bottomPanel.setBorder(BorderFactory.createTitledBorder("Status"));
JPanel salesButtonsPanel = new JPanel(new GridLayout(1, 5));
salesButtonsPanel.add(plainRadioButton);
salesButtonsPanel.add(HTMLRadioButton);
salesButtonsPanel.add(XMLRadioButton);
salesButtonsPanel.add(displaySalesButton);
salesButtonsPanel.add(saveSalesButton);
bottomPanel.add (new JScrollPane(statusTextArea,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED), BorderLayout.CENTER);
bottomPanel.add(salesButtonsPanel, BorderLayout.SOUTH);
// arrange panels in window
setLayout(new BorderLayout());
add(catalogPanel, BorderLayout.WEST);
add(centralPanel, BorderLayout.CENTER);
add(orderPanel, BorderLayout.EAST);
add(bottomPanel, BorderLayout.SOUTH);
// start listening for list and buttons events
catalogList.addListSelectionListener(new DisplayProductListener());
addModifyButton.addActionListener(new AddModifyListener());
removeButton.addActionListener(new RemoveListener());
registerSaleButton.addActionListener(new RegisterSaleListener());
displaySalesButton.addActionListener(new DisplaySalesListener());
saveSalesButton.add
没有合适的资源?快使用搜索试试~ 我知道了~
SSD3实验参考答案
共102个文件
class:44个
java:34个
classpath:7个
4星 · 超过85%的资源 需积分: 10 131 下载量 110 浏览量
2008-12-23
12:25:34
上传
评论 1
收藏 123KB RAR 举报
温馨提示
我做的SSD3实验参考答案 除第二个没有外其余的都有 还算可以吧
资源推荐
资源详情
资源评论
收起资源包目录
SSD3实验参考答案 (102个子文件)
GourmetCoffee.class 11KB
GourmetCoffeeGUI.class 10KB
GourmetCoffee.class 7KB
TestOrder.class 6KB
GourmetCoffee.class 5KB
CatalogGUI.class 5KB
TestFileCatalogLoader.class 5KB
TestCatalog.class 4KB
ShoppingCartApplication.class 4KB
FileCatalogLoader.class 3KB
TestSales.class 3KB
TestProduct.class 3KB
TestCoffee.class 3KB
TestOrderItem.class 2KB
HTMLSalesFormatter.class 2KB
TestCoffeeBrewer.class 2KB
GourmetCoffeeGUI$AddModifyListener.class 2KB
XMLSalesFormatter.class 2KB
GourmetCoffeeGUI$DisplayProductListener.class 2KB
PlainTextSalesFormatter.class 2KB
Order.class 2KB
CatalogGUI$CatalogListListener.class 2KB
GourmetCoffeeGUI$RegisterSaleListener.class 2KB
GourmetCoffeeGUI$SaveSalesListener.class 2KB
Coffee.class 2KB
Coffee.class 2KB
Catalog.class 1KB
Product.class 1KB
Product.class 1KB
CoffeeBrewer.class 1KB
CoffeeBrewer.class 1KB
OrderItem.class 1KB
GourmetCoffeeGUI$DisplaySalesListener.class 1KB
OrderItem.class 1KB
GourmetCoffeeGUI$RemoveListener.class 1KB
Sales.class 898B
Product.class 824B
GourmetCoffeeGUI$PlainListener.class 818B
GourmetCoffeeGUI$HTMLListener.class 797B
GourmetCoffeeGUI$XMLListener.class 792B
ShoppingCart.class 589B
DataFormatException.class 494B
CatalogLoader.class 273B
SalesFormatter.class 161B
.classpath 315B
.classpath 315B
.classpath 315B
.classpath 315B
.classpath 232B
.classpath 232B
.classpath 232B
catalog.dat 2KB
catalog.dat 2KB
catalog.dat 2KB
empty.dat 379B
Jalien.dat 229B
GourmetCoffeeGUI.java 15KB
GourmetCoffee.java 14KB
GourmetCoffee.java 8KB
GourmetCoffee.java 6KB
TestFileCatalogLoader.java 5KB
CatalogGUI.java 5KB
TestOrder.java 4KB
FileCatalogLoader.java 3KB
ShoppingCartApplication.java 3KB
TestCatalog.java 3KB
TestSales.java 3KB
TestProduct.java 2KB
TestCoffee.java 2KB
TestOrderItem.java 2KB
TestCoffeeBrewer.java 2KB
HTMLSalesFormatter.java 2KB
XMLSalesFormatter.java 1KB
Coffee.java 1KB
Coffee.java 1KB
PlainTextSalesFormatter.java 1KB
Order.java 927B
CatalogLoader.java 868B
Product.java 805B
CoffeeBrewer.java 799B
CoffeeBrewer.java 799B
Product.java 791B
OrderItem.java 741B
OrderItem.java 739B
Product.java 647B
DataFormatException.java 631B
Catalog.java 617B
ShoppingCart.java 454B
Sales.java 353B
SalesFormatter.java 137B
org.eclipse.jdt.core.prefs 629B
.project 385B
.project 385B
.project 385B
.project 385B
.project 385B
.project 385B
.project 385B
Exercise8.zip 11KB
Exercise6.zip 8KB
共 102 条
- 1
- 2
资源评论
- ZMHLR2014-12-04答案很有用
- mandyrt2013-11-29答案挺好用的
- kianaung2014-11-29对我很有帮助,谢谢分享!
Jalien
- 粉丝: 26
- 资源: 29
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功