Professional Documents
Culture Documents
Question 1: Create a Frame that holds three panels with Red, Orange and Yellow Colors. A fourth panel is to be added with a Blue color for the background
The following code is to be used for panels creation: JPanel gui = new JPanel(new BorderLayout(3,3)); gui.setBackground(Color.BLUE);
Question 2: Part A Create 2 tables Employee and Department where each employee works in one department and the department includes many employees. Table Employee contains the following attributes: ID, Name, DNO, ContractDate ContractDate of type TIMESTAMP and holds the current system date Insert 2 records in each table.
Question 2: Part B Create a java application that retrieves the Employees information in JTable
The following code will be used for the connection between the application side and the database created: Connection Ex1Con = null; Statement Ex1Stmt= null; ResultSet Ex1rs= null; try{ Ex1Con = DriverManager.getConnection( "jdbc:derby://localhost:1527/Database", "Username", "Password"); Ex1Stmt = Ex1Con.createStatement(); Ex1rs = Ex1Stmt.executeQuery( " Write your Select Statement ");
int li_row = 0; while (Ex1rs.next()) { jTable1.setValueAt(Ex1rs.getString(1),li_row,0); Write the appropriate code to fill the Table } Ex1Con.close(); } catch(Exception e) { System.err.println("Exception: "+e.getMessage()); }
Question 2: Part C Modify the program in part B to display an error message in a dialogue box in case a problem occurred in the database connection.
Question 3: A) Modify the program in Question 2 to allow user to retrieve the Employees Information in a jList B) Add a Delete From List Button to delete a certain Record from the List C) Add a Delete From Database Button to delete a certain Record from the Database based on the ID added in the text field D) Add a Delete Button to delete a certain Record from the Database directly from the List
The following code to help in populating the List: DefaultListModel model = new DefaultListModel(); //create a new list model model model try { while (Ex1rs.next()) {
String ItemList1 = Ex1rs.getString("ID"); String ItemList5= ItemList1+ "--- " +ItemList2+ "--- " +ItemList3+ "--- " +ItemList4; model.addElement(ItemList5); } jList1.setModel(model); Ex1Con.close(); } catch(Exception e) { System.err.println("Exception: "+e.getMessage()); }
The following code to help in Deleting from the List: if (selectedIndex != -1) { model.remove(selectedIndex); }