ウィンドウを開いて、ファイルのテキストを表示させようとしています。ただし、実行すると、空白のウィンドウが表示されます。これがウィンドウのコードです-日食からのエラーはまったくありません。
package presentation;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import domain.Items;
import services.exceptions.ItemNotFoundException;
import services.itemservice.*;
public class ShowAllInventory extends JFrame {
/**
*
*/
private static final long serialVersionUID = -4498395613773129897L;
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ShowAllInventory frame = new ShowAllInventory();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the window frame.
*/
public ShowAllInventory() throws ItemNotFoundException {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
/**
* Load the inventory
*/
IItemsService service = new ItemsServiceImpl();
try {
Items items = service.getItems();
} catch (ItemNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println ("Items Not Found");
}
}
}
コードが呼び出しているインターフェースのコードは次のとおりです-
public Items getItems () throws ItemNotFoundException;
}
そして、ここに実装があります...
/**
* Getting Items from the database
* @return
* @throws ItemNotFoundException
*/
@Override
public Items getItems() throws ItemNotFoundException {
Items items = (Items) null;
try {
ObjectInputStream input = new
ObjectInputStream (new FileInputStream("itemdatabase"));
items = (Items)input.readObject();
input.close();
} catch (IOException ioe) {
System.out.println ("IOException");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return items;
}