我正在尝试打开一个窗口并让它显示文件中的文本。但是,当我运行它时,我只是得到一个空白窗口。这是窗口的代码 - 我完全没有从 eclipse 中得到任何错误。
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;
}