import [Link].
*;
//import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
public class DeleteAccount extends JFrame implements ActionListener
{
/**
*
*/
private static final long serialVersionUID = 1L;
JLabel lbl_ano, lbl_fname, lbl_lname, lbl_uname, lbl_pword;
JTextField txt_ano, txt_fname, txt_lname, txt_uname, txt_pword;
JFrame frame;
JButton btn_delete, btn_search, btn_exit;
Icon delete, search, back;
Container con;
Connection cn;
Statement st;
ResultSet rs;
public DeleteAccount(JFrame fr3, Statement st3)
{
super("Delete Account");
frame = fr3;
[Link] = st3;
con = getContentPane();
[Link](null);
lbl_ano = new JLabel ("Account Id");
lbl_fname = new JLabel ("First Name");
lbl_lname = new JLabel ("Last Name");
lbl_uname = new JLabel ("Username");
lbl_pword = new JLabel ("Password");
txt_ano = new JTextField(10);
txt_fname = new JTextField(50);
txt_lname = new JTextField(50);
txt_uname = new JTextField(50);
txt_pword = new JTextField(100);
delete = new ImageIcon ("[Link]");
search = new ImageIcon ("[Link]");
back = new ImageIcon ("[Link]");
btn_search = new JButton ("Find", search);
btn_delete = new JButton ("Delete", delete);
btn_exit = new JButton ("Exit", back);
lbl_ano.setBounds(10,5,100,25);
[Link](lbl_ano);
txt_ano.setBounds(130,5,75,25);
[Link](txt_ano);
txt_ano.setEditable(false);
lbl_fname.setBounds(10,35,100,25);
[Link](lbl_fname);
txt_fname.setBounds(130,35,150,25);
[Link](txt_fname);
txt_fname.setEditable(false);
lbl_lname.setBounds(10,65,100,25);
[Link](lbl_lname);
txt_lname.setBounds(130,65,150,25);
[Link](txt_lname);
txt_lname.setEditable(false);
lbl_uname.setBounds(10,95,100,25);
[Link](lbl_uname);
txt_uname.setBounds(130,95,150,25);
[Link](txt_uname);
txt_uname.setEditable(false);
lbl_pword.setBounds(10,125,100,25);
[Link](lbl_pword);
txt_pword.setBounds(130,125,300,25);
[Link](txt_pword);
txt_pword.setEditable(false);
btn_search.setBounds(10,175,110,50);
[Link](btn_search);
btn_delete.setBounds(130,175,110,50);
[Link](btn_delete);
btn_exit.setBounds(250,175,110,50);
[Link](btn_exit);
btn_search.addActionListener(this);
btn_delete.addActionListener(this);
btn_exit.addActionListener(this);
btn_delete.setEnabled(false);
pack();
setSize(500,300);
setResizable(false);
setLocationRelativeTo(null);
setVisible(true);
}
public void actionPerformed(ActionEvent evt)
{
if([Link]() == btn_search)
{
try
{
dbOpen();
String str = [Link](null, "Enter Username:
","Message",JOptionPane.QUESTION_MESSAGE);
rs=[Link]("SELECT * FROM accounts_tbl WHERE username =
'"+str+"'");
if([Link]()==false)
{
[Link](null, "Username Does not Exist",
"Error", JOptionPane.ERROR_MESSAGE);
[Link]();
}
else
{
setText();
}
btn_delete.setEnabled(true);
btn_search.setEnabled(false);
}
catch(Exception e)
{
[Link](null,[Link](),"Message",
JOptionPane.ERROR_MESSAGE);
}
}
if([Link]()==btn_delete)
{
try
{
dbOpen();
String c = txt_ano.getText();
if([Link](null, "Are you sure you want to delete the
record?","Confirm",JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION)
{
[Link]("DELETE FROM accounts_tbl WHERE (accnt_id =
'"+c+"')");
[Link](null,"Account
Deleted","Message",JOptionPane.INFORMATION_MESSAGE);
btn_delete.setEnabled(false);
btn_search.setEnabled(true);
txt_ano.setText("");
txt_fname.setText("");
txt_lname.setText("");
txt_uname.setText("");
txt_pword.setText("");
dbClose();
}
}
catch(Exception e)
{
[Link](null,[Link](),"Message",
JOptionPane.ERROR_MESSAGE);
}
}
if ([Link]() == btn_exit)
{
[Link]();
}
}
public void dbOpen()
{
try
{
String url="jdbc:mysql://localhost:3306/javaee_db";
String user="root";
String password="";
cn=[Link](url,user,password);
st=[Link]();
rs = [Link]("select * from accounts_tbl");
}
catch (Exception e)
{
[Link](null, [Link](), "Error",
JOptionPane.ERROR_MESSAGE);
}
}
public void dbClose()
{
try
{
[Link]();
[Link]();
[Link]();
}
catch(Exception e)
{
[Link](null,[Link](),"Message",
JOptionPane.ERROR_MESSAGE);
}
}
public void setText()
{
try
{
txt_ano.setText([Link](1));
txt_fname.setText([Link](2));
txt_lname.setText([Link](3));
txt_uname.setText([Link](4));
txt_pword.setText([Link](5));
}
catch(Exception e)
{
[Link](null,[Link](),"Message",
JOptionPane.ERROR_MESSAGE);
}
}
}