Profile
Profile
*;
import java.awt.*;
import java.sql.*;
Profile(String username) {
Font f = new Font("Futura", Font.BOLD, 35);
Font f2 = new Font("Calibri", Font.PLAIN, 20);
l1.setFont(f2);
box.setFont(f2);
l2.setFont(f2);
t1.setFont(f2);
b1.setFont(f2);
b2.setFont(f2);
Container c = getContentPane();
c.setLayout(null);
c.add(title);
c.add(l1);
c.add(box);
c.add(l2);
c.add(t1);
c.add(b1);
c.add(b2);
b2.addActionListener
(
a->
{
new Home(username);
dispose();
}
);
b1.addActionListener(
a->
{
String s1 = box.getSelectedItem().toString().toLowerCase();
String s2 = t1.getText();
if(s2.isEmpty())
{
JOptionPane.showMessageDialog(null,"enter value");
return;
}
//DATABASE
String url= "jdbc:mysql://localhost:3306/batch2";
try (Connection con = DriverManager.getConnection(url, "root",
"W7301@jqir#"))
{
String sql ="update users set "+s1+" =? where username=?";
try(PreparedStatement pst = con.prepareStatement(sql))
{
pst.setString(1,s2);
pst.setString(2,username);
pst.executeUpdate();
JOptionPane.showMessageDialog(null,"successfully
updated ");
t1.setText("");
}
if (s1.equals("username"))
{
dispose();
new Profile(s2);
}
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null,e.getMessage());
}
}
);
setVisible(true);
setSize(800, 550);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setTitle("Profile Settings");
}