GUI.java
package gui;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
public class GUI {
JTextField txt, id;
public GUI() {
JFrame f = new JFrame("Hancie e-Learning Studio");
f.setSize(720, 400);
f.setLocationRelativeTo(f);
f.setLayout(null);
id = new JTextField();
id.setBounds(10, 10, 200, 30);
f.add(id);
txt = new JTextField();
txt.setBounds(10, 50, 200, 30);
f.add(txt);
JButton btn = new JButton("Delete");
btn.setBounds(10, 100, 100, 30);
f.add(btn);
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Connection conn;
PreparedStatement pstat;
String sql = "DELETE FROM HANCIE WHERE ID=?;";
try {
Class.forName("org.sqlite.JDBC");
String URL = "jdbc:sqlite:C:/Users/Hanci/Desktop/database.db";
conn = DriverManager.getConnection(URL);
pstat = conn.prepareStatement(sql);
pstat.setString(1, id.getText());
pstat.execute();
conn.close();
JOptionPane.showMessageDialog(null, "Deleted");
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "Error55" + ex.getMessage());
}
}
});
f.setVisible(true);
}
public static void main(String[] args) {
new GUI();
}
}
Output