I have 3 classes called boundary, controller and entity. I am not allowed to access the boundary class straight from the entity class. I have to use the controller class to communicate with the boundary and entity class. The entity class consist of all my methods and getters/setters. The controller will check to see if the table is available. if return true, it will send the class over to the GUI.
What I am trying to do is: I am trying to display the excel sheet in my entity class and then pass it to my controller then from there I parse the data to the GUI which consist the main method to display the table.
I have tried to look up the internet but the examples are mostly all from the main method itself.
It will be of great help if you can refer me to a link that I can refer to or advice me on what I can do! Thank you! :)
This is what I had done so far if someone says that I hadn't tried before asking :)
The method from my entity class trying to call for the excel sheet.
public boolean getAllBugs1(ListBugReportEntity ListBugReportEntity) throws IOException
{
Vector headers = new Vector();
Vector data = new Vector();
File file = new File("src/BugReportDB.xls");
try {
Workbook workbook = Workbook.getWorkbook(file);
Sheet sheet = workbook.getSheet(0);
headers.clear();
for (int i = 0; i < sheet.getColumns(); i++) {
Cell cell1 = sheet.getCell(i, 0);
headers.add(cell1.getContents());
}
data.clear();
for (int j = 1; j < sheet.getRows(); j++) {
Vector d = new Vector();
for (int i = 0; i < sheet.getColumns(); i++) {
Cell cell = sheet.getCell(i, j);
d.add(cell.getContents());
}
d.add("\n");
data.add(d);
}
}
catch (Exception e) {
e.printStackTrace();
}
return true;
}
The controller to check if there is such class or excel sheet
import java.io.IOException;
public class ListBugController {
ListBugReportEntity ListBugReportEntity = new ListBugReportEntity();
public boolean getAll(ListBugReportEntity ListBugReportEntity) throws IOException
{
if(ListBugReportEntity.getAllBugs1(ListBugReportEntity))
{
return true;
}
return false;
}
}
The boundary class that I am trying to call the method in my entity class to display the excel sheet into a JTable.
import java.awt.*;
import java.io.IOException;
import java.util.Vector;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
public class ListBugReportUI extends JFrame{
private JLabel sBug;
private JTextField sBugF;
private JLabel sAssignee;
private JTextField sAssigneeF;
private JButton searchB;
private JTextField searchF;
private JLabel search;
private JPanel panel1;
private boolean help;
private boolean what;
private JPanel panel2;
private Container c;
ListBugReportEntity ListBugReportEntity = new ListBugReportEntity();
public ListBugReportUI() throws IOException
{
setTitle("View All Bugs");
c = getContentPane();
c.setLayout(null);
sBug = new JLabel("List of Bugs");
sBug.setFont(new Font("Arial", Font.PLAIN, 30));
sBug.setSize(300, 30);
sBug.setLocation(225, 30);
c.add(sBug);
search = new JLabel("Search By");
search.setFont(new Font("Arial", Font.PLAIN, 20));
search.setSize(100, 20);
search.setLocation(100, 100);
c.add(search);
searchF = new JTextField();
searchF.setFont(new Font("Arial", Font.PLAIN, 15));
searchF.setSize(190, 20);
searchF.setLocation(300, 100);
c.add(searchF);
//table
ListBugController ui = new ListBugController();
ListBugReportEntity ui2 = new ListBugReportEntity();
help = ui.getAll(ListBugReportEntity);
Vector headers = new Vector();
Vector data = new Vector();
JTable table = new JTable();
DefaultTableModel model = new DefaultTableModel(data,headers);
table.setModel(model);
table.setAutoCreateRowSorter(true);
model = new DefaultTableModel(data, headers);
table.setModel(model);
JScrollPane scroll = new JScrollPane(table);
c.add(scroll);
//end table
}
public static void main (String[] args) throws IOException
{
ListBugReportUI ui = new ListBugReportUI();
ui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ui.setSize(700,600);
ui.setVisible(true);
}
}