Create a Code that will add an Add Edi and Delete button to

Create a Code that will add an Add, Edi, and Delete button to the GUI like bellow.

public class Student {

   private String studentID;
   private String studentEmail;
   private String studentFirstName;
   private String studentLastName;

   /**
   * @param studentID
   * @param studentEmail
   * @param studentFirstName
   * @param studentLastName
   */
   public Student(String studentID, String studentEmail, String studentFirstName,
           String studentLastName) {
       this.studentID = studentID;
       this.studentEmail = studentEmail;
       this.studentFirstName = studentFirstName;
       this.studentLastName = studentLastName;
   }

   /**
   * @return the studentID
   */
   public String getStudentID() {
       return studentID;
   }

   /**
   * @param studentID
   * the studentID to set
   */
   public void setStudentID(String studentID) {
       this.studentID = studentID;
   }

   /**
   * @return the studentEmail
   */
   public String getStudentEmail() {
       return studentEmail;
   }

   /**
   * @param studentEmail
   * the studentEmail to set
   */
   public void setStudentEmail(String studentEmail) {
       this.studentEmail = studentEmail;
   }

   /**
   * @return the studentFirstName
   */
   public String getStudentFirstName() {
       return studentFirstName;
   }

   /**
   * @param studentFirstName
   * the studentFirstName to set
   */
   public void setStudentFirstName(String studentFirstName) {
       this.studentFirstName = studentFirstName;
   }

   /**
   * @return the studentLastName
   */
   public String getStudentLastName() {
       return studentLastName;
   }

   /**
   * @param studentLastName
   * the studentLastName to set
   */
   public void setStudentLastName(String studentLastName) {
       this.studentLastName = studentLastName;
   }

}

------------------------------------------------------------------------------------------------------

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;

public class JTableExample extends JFrame {
   public JTableExample() {
       // headers for the table
       String[] columns = new String[] { \"Email\", \"First Name\", \"Last Name\" };

       Student[] students = {
               new Student(\"S123\", \"sri3(AT).com\", \"Srinu\", \"Vasu\"),
               new Student(\"S124\", \"sri4(AT).com\", \"Rajesh\", \"Kumar\"),
               new Student(\"S125\", \"sri5(AT).com\", \"Kumar\", \"Suresh\"),
               new Student(\"S126\", \"sri6(AT).com\", \"Balaji\", \"kumar\") };

       // actual data for the table in a 2d array
       Object[][] data = new Object[students.length][3];
       for (int i = 0; i < data.length; i++) {

           data[i][0] = students[i].getStudentEmail();
           data[i][1] = students[i].getStudentFirstName();
           data[i][2] = students[i].getStudentLastName();
       }

       // create table with data
       JTable table = new JTable(data, columns);

       // add the table to the frame
       this.add(new JScrollPane(table));

       this.setTitle(\"Student Manager\");
       this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       this.pack();
       this.setVisible(true);
   }

   public static void main(String[] args) {
       SwingUtilities.invokeLater(new Runnable() {
           @Override
           public void run() {
               new JTableExample();
           }
       });
   }
}

Student Manager Email sri3@gmail.com sri4@gmail.com sri5@gmail.com sri6@gmail com Last Name First Name Srinu Vasu Rajesh Kumar Suresh Kumar Balaji kumar Add Edit Delete

Solution

program import Database.DatabaseOperations;
import javax.swing.*;
import javax.swing.border.BevelBorder;
import javax.swing.table.DefaultTableModel;
import javax.xml.crypto.Data;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.sql.*;
import java.util.Vector;
import static java.awt.Color.*;
public class K_EditUserPanel extends JFrame{
private JPanel pOuter;
private CustTable table;
{
Vector<Object> columnNames = new Vector<Object>();
Vector<Object> data = new Vector<Object>();
try
{
String driver = \"sun.jdbc.odbc.JdbcOdbcDriver\";
String url = \"jdbc:oracle:thin:HR/pmagee@localhost:1521:XE\";
String userid = \"system\";
String password = \"db08Sep95\";
Class.forName( driver );
Connection connection = DriverManager.getConnection(url, userid, password);
String sql = \"Select * from Customer\";
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery( sql );
ResultSetMetaData md = rs.getMetaData();
int columns = md.getColumnCount();
for (int i = 1; i <= columns; i++)
{
columnNames.addElement( md.getColumnName(i) );
}
while (rs.next())
{
Vector<Object> row = new Vector<Object>(columns);
for (int i = 1; i <= columns; i++)
{
row.addElement( rs.getObject(i) );
}
data.addElement( row );
}
rs.close();
stmt.close();
connection.close();
}
catch(Exception e)
{
System.out.println( e );
}
DefaultTableModel model = new DefaultTableModel(data, columnNames)
{
public Class getColumnClass(int column)
{
for (int row = 0; row < getRowCount(); row++)
{
Object o = getValueAt(row, column);

if (o != null)
{
return o.getClass();
}
}
return Object.class;
}
};
JTable table = new JTable( model );
JScrollPane scrollPane = new JScrollPane( table );
getContentPane().add(scrollPane);
JPanel buttonPanel = new JPanel();
getContentPane().add( buttonPanel, BorderLayout.SOUTH );
}
public static void main(String[] args)
{
TableFromDatabase frame = new TableFromDatabase();
frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
frame.pack();
frame.setVisible(true);
}
public K_EditUserPanel()
{
pOuter = new JPanel();
pOuter.setPreferredSize(new Dimension(575, 498));
pOuter.setOpaque(true);
pOuter.setBackground(darkGray);
pOuter.setLayout(new GridBagLayout());
}
public JPanel getUserPanel()
{
pOuter.removeAll();
try
{
pOuter = updateUserPanel(pOuter);
}
catch(SQLException e)
{
System.out.println();
}
pOuter.revalidate();
pOuter.repaint();
return pOuter;
}


public JPanel updateUserPanel(JPanel jPanel) throws SQLException {


jPanel.removeAll();
JPanel inner = new JPanel();

inner.setPreferredSize(new Dimension(575, 498));
inner.setOpaque(true);
inner.setBackground(darkGray);
inner.setLayout(new GridBagLayout());
jPanel.add(inner);
inner.setSize(300,300);
inner.add(new JScrollPane());
inner.setVisible(true);
inner.revalidate();
inner.repaint();


setSize(450,500);
setVisible(true);

return inner;
}



}

Create a Code that will add an Add, Edi, and Delete button to the GUI like bellow. public class Student { private String studentID; private String studentEmail;
Create a Code that will add an Add, Edi, and Delete button to the GUI like bellow. public class Student { private String studentID; private String studentEmail;
Create a Code that will add an Add, Edi, and Delete button to the GUI like bellow. public class Student { private String studentID; private String studentEmail;
Create a Code that will add an Add, Edi, and Delete button to the GUI like bellow. public class Student { private String studentID; private String studentEmail;
Create a Code that will add an Add, Edi, and Delete button to the GUI like bellow. public class Student { private String studentID; private String studentEmail;

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site