わかりました-次のコードがあります-スター付きの部分でエラーが発生します。ItemManagerクラスでは、()にItemsを入力する必要があります。ただし、そうすると、Itemsを変数に解決できないというエラーが表示され、それを修正する方法がわかりません。
package presentation;
import javax.swing.*;
import business.ItemManager;
import java.awt.*;
import java.awt.event.*;
import business.*;
public class CreateInventoryUI extends JFrame {
private static final long serialVersionUID = -3940805393905465307L;
private JButton addBtn = new JButton ("Add Item to Inventory");
private JButton showBtn = new JButton ("Display Inventory");
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
CreateInventoryUI frame = new CreateInventoryUI("Inventory");
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
System.out.println("Exception - Sorry");
}
}
});
}
public CreateInventoryUI(String name) { // title bar name
super(name);
// layout here
Container container = getContentPane();
FlowLayout layout = new FlowLayout();
container.setLayout(layout);
layout.setAlignment(FlowLayout.CENTER);
container.add(new JButton("Display inventory"));
container.add(new JButton("Add Item to Inventory"));
addBtn.addActionListener (new ActionListener() {
public void actionPerformed (ActionEvent event) {
// controller code
***ItemManager mngr = new ItemManager();
mngr.store(Items);***
}
});
showBtn.addActionListener (new ActionListener() {
public void actionPerformed (ActionEvent event) {
// controller code
ItemManager mngr = new ItemManager();
mngr.get(Items);
}
});
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
setVisible(true);
}
/**
* Constructs a <code>String</code> with all attributes
* in name = value format.
*
* @return a <code>String</code> representation
* of this object.
*/
public String toString()
{
final String TAB = " ";
String retValue = "";
retValue = "CreateInventoryUI ( "
+ super.toString() + TAB
+ "addBtn = " + this.addBtn + TAB
+ "showBtn = " + this.showBtn + TAB
+ " )";
return retValue;
}
}