新手 Java作业求解

寒潮_C 2017-05-17 12:19:08
错误: 找不到或无法加载主类 Experiment5.CatalogGUI
导入class 文件没法用·datalog can not be solve of type

/**
* This class displays the catalog of the gourmet coffee system.
*
* @author author name
* @version 1.1.0
* @see Product
* @see Coffee
* @see CoffeeBrewer
* @see Catalog
* @see CatalogLoader
* @see FileCatalogLoader
* @see DataFormatException
* @see DataField
*/
public class CatalogGUI extends JPanel {

/* Standar error stream */
static private PrintWriter stdErr = new PrintWriter(System.err, true);

/* Window width in pixels */
static private int WIDTH = 420;

/* Window height in pixels */
static private int HEIGHT = 320;

/* Size of the list cell in pixels */
static private int CELL_SIZE = 50;

/* Visible rows in list */
static private int LIST_ROWS = 10;

/* Rows in status text area */
static private int STATUS_ROWS = 5;

/* Rows in status text area */
static private int STATUS_COLS = 40;

private JList catalogList;
private JPanel productPanel;
private JTextArea statusTextArea;

private Catalog catalog;

/**
* 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("Catalog Gourmet Coffee");

frame.setContentPane(new CatalogGUI(catalog));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(WIDTH, HEIGHT);
frame.setResizable(true);
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 CatalogGUI(Catalog initialCatalog) {

catalog = initialCatalog;

// create the components
catalogList = new JList(catalog.getCodes());
catalogList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
catalogList.setVisibleRowCount(LIST_ROWS);
catalogList.setFixedCellWidth(CELL_SIZE);
statusTextArea = new JTextArea(STATUS_ROWS, STATUS_COLS);
statusTextArea.setEditable(false);

// create product information panel
productPanel = new JPanel();
productPanel.setBorder(
BorderFactory.createTitledBorder("Product Information"));

// create panel to hold list and Display button
JPanel catalogPanel = new JPanel();
catalogPanel.setBorder(BorderFactory.createTitledBorder("Catalog"));
catalogPanel.add (
new JScrollPane(catalogList,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER));

setLayout(new BorderLayout());
add(catalogPanel, BorderLayout.WEST);
add(productPanel, BorderLayout.CENTER);
add(statusTextArea, BorderLayout.SOUTH);

// start listening for list events
catalogList.addListSelectionListener(new CatalogListListener());
}

/*
* Obtains a {@link JPanel} object with the information of a product.
*
* @param dataFields an {@link ArrayList} of {@link DataField}
* with the product information.
* @return a {@link JPanel} with the product information.
*/
private JPanel getDataFieldsPanel(ArrayList<DataField> dataFields) {


/* PLACE YOUR CODE HERE */
JPanel panel = new JPanel(new BorderLayout());
int size = dataFields.size();
JPanel panelWest = new JPanel(new GridLayout(size, 1));
JPanel panelEast = new JPanel(new GridLayout(size, 1));
for(DataField data: dataFields){
panelWest.add(new JLabel(data.getName() + ":"));
panel.add(panelWest, BorderLayout.WEST);
}
for(DataField data: dataFields){
panelEast.add(new JTextField(data.getValue()));
panel.add(panelEast, BorderLayout.EAST);
}
return new JPanel(); // REMOVE; USED SO THIS FILE COMPILES

}

/**
* This inner class handles list-selection events.
*/
class CatalogListListener implements ListSelectionListener {

/**
* Displays the information of the selected product.
*
* @param event the event object.
*/
public void valueChanged(ListSelectionEvent event) {

String code = (String) catalogList.getSelectedValue();
Product product = catalog.getProduct(code);

productPanel.removeAll();
productPanel.setVisible(false); // Use this
productPanel.add( // to update
getDataFieldsPanel(product.getDataFields())); // the panel
productPanel.setVisible(true); // correctly

statusTextArea.setText("Product " + code + " has been displayed");
}
}
}
...全文
442 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
wldtk123456 2017-05-20
  • 打赏
  • 举报
回复
放到eclipse中全是错误,改都没法改
  • 打赏
  • 举报
回复
错误: 找不到或无法加载主类 Experiment5.CatalogGUI 光这句话什么意思,Experiment5是什么东东
我爱娃哈哈 2017-05-17
  • 打赏
  • 举报
回复
看到swing就烦

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧