Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- hw4
- import java.awt.BorderLayout;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import net.proteanit.sql.DbUtils;
- import java.awt.Color;
- import javax.swing.JLabel;
- import javax.swing.JTable;
- import javax.swing.JButton;
- import java.awt.event.ActionListener;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.awt.event.ActionEvent;
- import javax.swing.JScrollPane;
- public class FJL extends JFrame {
- private JPanel contentPane;
- private JTable table;
- Connection a = null;
- PreparedStatement ps = null;
- ResultSet rs = null;
- private JScrollPane scrollPane;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- FJL frame = new FJL();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the frame.
- */
- public FJL() {
- design();
- a = Cn.DB();
- }
- private void login() {
- try {
- String x = "SELECT * FROM id1";
- ps = a.prepareStatement(x);
- rs = ps.executeQuery();
- table.setModel(DbUtils.resultSetToTableModel(rs));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- private void design() {
- setBackground(Color.BLACK);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 450, 300);
- contentPane = new JPanel();
- contentPane.setBackground(Color.BLACK);
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- scrollPane = new JScrollPane();
- scrollPane.setBounds(10, 11, 414, 166);
- contentPane.add(scrollPane);
- table = new JTable();
- scrollPane.setViewportView(table);
- JButton B = new JButton("B");
- B.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- login(); }
- });
- B.setBounds(172, 209, 89, 23);
- contentPane.add(B);
- }
- }
- //CLASS NAME:Cn
- import java.sql.Connection;
- import java.sql.DriverManager;
- import javax.swing.JOptionPane;
- public class Cn {
- static Connection a;
- public static Connection DB() {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- a = DriverManager.getConnection("jdbc:mysql://localhost:3306/sms", "root", "");
- //JOptionPane.showMessageDialog(null, "Connected");
- return a;
- } catch (Exception e) {
- JOptionPane.showMessageDialog(null, "Connection Error");
- return null;
- }
- }
- }
- ................................................................//CLASS NAME:FJL
- import java.awt.BorderLayout;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.JButton;
- import java.awt.Font;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.text.SimpleDateFormat;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.GregorianCalendar;
- import javax.swing.JTextField;
- import javax.swing.JTextArea;
- import javax.swing.JTextPane;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import java.awt.SystemColor;
- import javax.swing.JPasswordField;
- import javax.swing.JTable;
- import javax.swing.JLabel;
- import java.awt.Color;
- import javax.swing.SwingConstants;
- public class FJL extends JFrame {
- private JPanel contentPane;
- private JTextField tfn;
- private JTextField cmnt;
- public static String name1="";
- Connection a = null;
- PreparedStatement ps = null;
- ResultSet rs = null;
- private JPasswordField tfp;
- private JLabel lblClock;
- private JLabel lblTime;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- FJL frame = new FJL();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the frame.
- */
- public FJL() {
- design();
- a = Cn.DB();
- clock();
- }
- private void login() {
- try {
- String x = "SELECT * FROM id WHERE name=? and pass=?";
- ps = a.prepareStatement(x);
- ps.setString(1, tfn.getText());
- ps.setString(2, tfp.getText());
- rs = ps.executeQuery();
- if (rs.next()) {
- name1=rs.getString("Name");
- FJL2 f = new FJL2();
- dispose();
- f.setVisible(true);
- ps.close();
- rs.close();
- // cmnt.setText("Succesful");
- } else {
- cmnt.setText(" Please Sign Up");
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- private void clock() {
- Thread clock =new Thread() {
- public void run() {
- try {
- for(;;) {
- Calendar cal = new GregorianCalendar();
- SimpleDateFormat formatter=new SimpleDateFormat("dd-MM-yyyy");
- SimpleDateFormat formatt=new SimpleDateFormat("hh:mm:ss a");
- Date date=cal.getTime();
- Date time=cal.getTime();
- String timestring=formatter.format(date);
- String timestringg=formatt.format(date);
- lblClock.setText(timestring);
- lblTime.setText(timestringg);
- sleep(1000);
- }
- }catch(Exception e) {
- e.printStackTrace();
- }
- }
- };
- clock.start();
- }
- private void design() {
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 450, 300);
- contentPane = new JPanel();
- contentPane.setBackground(Color.BLACK);
- contentPane.setBorder(null);
- setContentPane(contentPane);
- contentPane.setLayout(null);
- JButton li = new JButton("Log In");
- li.setForeground(Color.CYAN);
- li.setBackground(Color.BLACK);
- li.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- if(tfn.getText().equals("")) {
- cmnt.setText(" Enter Name");
- }
- else if(tfp.getText().equals("")) {
- cmnt.setText(" Enter Password");
- }
- else {
- login();
- }
- }
- });
- li.setFont(new Font("Tahoma", Font.BOLD, 14));
- li.setBounds(273, 168, 118, 28);
- contentPane.add(li);
- JButton su = new JButton("Sign Up");
- su.setBackground(Color.BLACK);
- su.setForeground(Color.CYAN);
- su.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- FJL3 f = new FJL3();
- f.setVisible(true);
- dispose();
- }
- });
- su.setFont(new Font("Tahoma", Font.BOLD, 14));
- su.setBounds(273, 207, 118, 28);
- contentPane.add(su);
- tfn = new JTextField();
- tfn.setBounds(10, 45, 137, 28);
- contentPane.add(tfn);
- tfn.setColumns(10);
- cmnt = new JTextField();
- cmnt.setForeground(Color.BLACK);
- cmnt.setBackground(SystemColor.control);
- cmnt.setFont(new Font("Tahoma", Font.BOLD, 15));
- cmnt.setBounds(10, 183, 137, 28);
- contentPane.add(cmnt);
- cmnt.setColumns(10);
- tfp = new JPasswordField();
- tfp.setBounds(10, 117, 137, 28);
- contentPane.add(tfp);
- JLabel lblName = new JLabel("Name:");
- lblName.setForeground(Color.CYAN);
- lblName.setFont(new Font("Tahoma", Font.PLAIN, 13));
- lblName.setBackground(SystemColor.control);
- lblName.setBounds(10, 11, 70, 22);
- contentPane.add(lblName);
- JLabel lblPassword = new JLabel("Password:");
- lblPassword.setForeground(Color.CYAN);
- lblPassword.setFont(new Font("Tahoma", Font.PLAIN, 13));
- lblPassword.setBackground(SystemColor.control);
- lblPassword.setBounds(10, 84, 80, 22);
- contentPane.add(lblPassword);
- lblClock = new JLabel("CLOCK");
- lblClock.setFont(new Font("Tahoma", Font.PLAIN, 25));
- lblClock.setHorizontalAlignment(SwingConstants.CENTER);
- lblClock.setForeground(Color.CYAN);
- lblClock.setBounds(236, 84, 188, 58);
- contentPane.add(lblClock);
- lblTime = new JLabel("TIME");
- lblTime.setHorizontalAlignment(SwingConstants.CENTER);
- lblTime.setForeground(Color.CYAN);
- lblTime.setFont(new Font("Tahoma", Font.PLAIN, 25));
- lblTime.setBounds(236, 27, 188, 52);
- contentPane.add(lblTime);
- }
- }
- ................................................................//CLASS NAME:FJL2
- import java.awt.BorderLayout; //line308
- import java.awt.EventQueue;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import net.proteanit.sql.DbUtils;
- import javax.swing.JTextArea;
- import javax.swing.JTable;
- import javax.swing.JRadioButton;
- import javax.swing.JComboBox;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import java.awt.Font;
- import javax.swing.DefaultComboBoxModel;
- import javax.swing.DefaultListModel;
- import javax.swing.JButton;
- import javax.swing.JCheckBox;
- import javax.swing.JTextField;
- import java.awt.SystemColor;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import javax.swing.JScrollPane;
- import javax.swing.ButtonGroup;
- import java.awt.Color;
- import java.awt.event.KeyAdapter;
- import java.awt.event.KeyEvent;
- import javax.swing.SwingConstants;
- import javax.swing.JList;
- public class FJL2 extends JFrame {
- private JPanel contentPane;
- Connection a = null;
- PreparedStatement ps = null;
- ResultSet rs = null;
- private JTextArea name;
- private JTextArea age;
- private JTextArea pn;
- private JTextArea pass;
- private JRadioButton m, f;
- private JComboBox region;
- private JButton add, delete, update;
- private String p = "";
- private String combo = "";
- private int Id = 0;
- private JTable table;
- private JScrollPane scrollPane;
- private final ButtonGroup buttonGroup = new ButtonGroup();
- private JComboBox cb;
- private JTextField tf;
- private JButton btnLogOut;
- private JComboBox cb1;
- private JList adrslist;
- private JScrollPane scrollPane_1;
- private JLabel ta;
- private JLabel ta2;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- FJL2 frame = new FJL2();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the frame.
- */
- public FJL2() {
- design();
- a = Cn.DB();
- ta.setText(" Welcome " + FJL.name1);
- ta2.setText("----------------------------------------");
- FJL2();
- sbn();
- sba();
- }
- private void FJL2() {
- try {
- String s = "Select Id,Name,Age,Gender,Contact,Region FROM id ";// Name,Age,Gender,Contact,Region
- ps = a.prepareStatement(s);
- rs = ps.executeQuery();
- table.setModel(DbUtils.resultSetToTableModel(rs));
- ps.close();
- rs.close();
- } catch (Exception e) {
- e.getStackTrace();
- }
- }
- private void addd() {
- try {
- String z = "INSERT INTO id(Name,Pass,Age,Gender,Contact,Region) VALUES (?,?,?,?,?,?)";
- ps = a.prepareStatement(z);
- ps.setString(1, name.getText());
- ps.setString(2, pass.getText());
- ps.setString(3, age.getText());
- if (m.isSelected()) {
- p = m.getText().toString();
- } else {
- p = f.getText().toString();
- }
- ps.setString(4, String.valueOf(p));
- // System.out.println(String.valueOf(p));
- ps.setString(5, pn.getText());
- ps.setString(6, region.getSelectedItem().toString());
- ps.execute();
- ps.close();
- reset();
- } catch (Exception e) {
- e.getStackTrace();
- }
- }
- private void table() {
- try {
- int row = table.getSelectedRow();
- String A = (table.getModel().getValueAt(row, 0)).toString();
- String B = "Select * FROM id WHERE Id='" + A + "'";
- ps = a.prepareStatement(B);
- rs = ps.executeQuery();
- while (rs.next()) {
- Id = rs.getInt("Id");
- name.setText(rs.getString("Name"));
- // System.out.println(name);
- pass.setText(rs.getString("Pass"));
- age.setText(rs.getString("Age"));
- p = rs.getString("Gender");
- if (p.equals("Male")) {
- m.setSelected(true);
- f.setSelected(false);
- }
- else if (p.equals("Female")) {
- f.setSelected(true);
- m.setSelected(false);
- }
- pn.setText(rs.getString("Contact"));
- combo = rs.getString("Region");
- if (combo.equals("Dhaka")) {
- region.setSelectedItem("Dhaka");
- }
- else if (combo.equals("Shylet")) {
- region.setSelectedItem("Shylet");
- } else if (combo.equals("Khulna")) {
- region.setSelectedItem("Khulna");
- } else {
- region.setSelectedItem("Barishal");
- }
- }
- ps.close();
- rs.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- private void update() {
- // ctrl+shift+f=format
- try {
- String s = "Update id SET Name='" + name.getText() + "',Pass='" + pass.getText() + "',Age='" + age.getText()
- + "',Gender='" + p + "',Contact='" + pn.getText() + "',Region='"
- + region.getSelectedItem().toString() + "' Where Id='" + Id + "' ";
- ps = a.prepareStatement(s);
- ps.execute();
- ps.close();
- reset();
- sba();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- private void delete() {
- try {
- int x = JOptionPane.showConfirmDialog(null, "Are you sure?", "Delete", JOptionPane.YES_NO_CANCEL_OPTION);
- if (x == 0) {
- String s = "Delete From Id Where Id='" + Id + "' ";
- ps = a.prepareStatement(s);
- ps.execute();
- ps.close();
- reset();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- private void sbo() {
- try {
- String s = (String) cb.getSelectedItem();
- String i = "SELECT Name,Pass,Age,Gender,Contact,Region FROM id WHERE " + s + " LIKE '" + tf.getText()
- + "%'";
- ps = a.prepareStatement(i);
- // ps.setString(1, tf.getText());
- rs = ps.executeQuery();
- table.setModel(DbUtils.resultSetToTableModel(rs));
- ps.close();
- rs.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- private void reset() {
- name.setText(null);
- pass.setText(null);
- pn.setText(null);
- tf.setText(null);
- //buttonGroup.clearSelection();
- region.setSelectedItem("-");
- cb.setSelectedItem("-");
- cb1.setSelectedItem("-");
- age.setText(null);
- sba();
- FJL2();
- }
- private void sbn() {
- try {
- String i = "SELECT Name FROM id";
- ps = a.prepareStatement(i);
- rs = ps.executeQuery();
- while (rs.next()) {
- cb1.addItem(rs.getString("Name"));
- }
- ps.close();
- rs.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- private void sbnt() {// search by name table
- try {
- String B = "Select * FROM id WHERE Name= ?";
- ps = a.prepareStatement(B);
- ps.setString(1, (String) cb1.getSelectedItem());
- rs = ps.executeQuery();
- while (rs.next()) {
- Id = rs.getInt("Id");
- name.setText(rs.getString("Name"));
- // System.out.println(name);
- pass.setText(rs.getString("Pass"));
- age.setText(rs.getString("Age"));
- p = rs.getString("Gender");
- if (p.equals("Male")) {
- m.setSelected(true);
- f.setSelected(false);
- }
- else if (p.equals("Female")) {
- f.setSelected(true);
- m.setSelected(false);
- }
- pn.setText(rs.getString("Contact"));
- combo = rs.getString("Region");
- if (combo.equals("Dhaka")) {
- region.setSelectedItem("Dhaka");
- }
- else if (combo.equals("Shylet")) {
- region.setSelectedItem("Shylet");
- } else if (combo.equals("Khulna")) {
- region.setSelectedItem("Khulna");
- } else {
- region.setSelectedItem("Barishal");
- }
- }
- ps.close();
- rs.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- private void sba() {// a=address
- try {
- DefaultListModel dlm = new DefaultListModel();
- String i = "SELECT DISTINCT Region FROM id";
- ps = a.prepareStatement(i);
- rs = ps.executeQuery();
- while (rs.next()) {
- dlm.addElement(rs.getString("Region"));
- }
- adrslist.setModel(dlm);
- ps.close();
- rs.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- private void sbat() {// search by adress table
- try {
- String B = "Select * FROM id WHERE Region= ?";
- ps = a.prepareStatement(B);
- ps.setString(1, (String) adrslist.getSelectedValue());
- rs = ps.executeQuery();
- table.setModel(DbUtils.resultSetToTableModel(rs));
- /*
- * while (rs.next()) { Id = rs.getInt("Id"); name.setText(rs.getString("Name"));
- * // System.out.println(name); pass.setText(rs.getString("Pass"));
- * age.setText(rs.getString("Age"));
- *
- * p = rs.getString("Gender");
- *
- * if (p.equals("Male")) { m.setSelected(true); f.setSelected(false); }
- *
- * else if(p.equals("Female")) { f.setSelected(true); m.setSelected(false); }
- * pn.setText(rs.getString("Contact"));
- *
- * combo = rs.getString("Region");
- *
- * if (combo.equals("Dhaka")) { region.setSelectedItem("Dhaka"); }
- *
- * else if (combo.equals("Shylet")) { region.setSelectedItem("Shylet"); } else
- * if(combo.equals("Khulna")){ region.setSelectedItem("Khulna"); } else {
- * region.setSelectedItem("Barishal"); } }
- */
- ps.close();
- rs.close();
- } catch (
- Exception e) {
- e.printStackTrace();
- }
- }
- private void design() {
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 671, 501);
- contentPane = new JPanel();
- contentPane.setBackground(Color.BLACK);
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- scrollPane = new JScrollPane();
- scrollPane.setBounds(0, 105, 655, 111);
- contentPane.add(scrollPane);
- ta = new JLabel("New label");
- ta.setForeground(Color.CYAN);
- ta.setFont(new Font("Tahoma", Font.BOLD, 18));
- ta.setBounds(223, 11, 209, 33);
- contentPane.add(ta);
- table = new JTable();
- table.setBackground(Color.BLACK);
- table.setForeground(Color.CYAN);
- table.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- table();
- }
- });
- scrollPane.setViewportView(table);
- f = new JRadioButton("Female");
- f.setBounds(287, 374, 109, 23);
- f.setBackground(Color.BLACK);
- f.setForeground(Color.CYAN);
- buttonGroup.add(f);
- contentPane.add(f);
- JLabel label = new JLabel("Region :");
- label.setBounds(125, 404, 87, 26);
- label.setForeground(Color.CYAN);
- label.setFont(new Font("Tahoma", Font.PLAIN, 15));
- contentPane.add(label);
- ta2 = new JLabel("");
- ta2.setForeground(Color.CYAN);
- ta2.setBackground(Color.BLACK);
- ta2.setBounds(218, 30, 191, 23);
- contentPane.add(ta2);
- JLabel lblName = new JLabel("Name :");
- lblName.setBounds(125, 239, 75, 26);
- lblName.setForeground(Color.CYAN);
- lblName.setFont(new Font("Tahoma", Font.PLAIN, 15));
- contentPane.add(lblName);
- name = new JTextArea();
- name.setBounds(210, 244, 203, 23);
- name.setForeground(Color.CYAN);
- name.setFont(new Font("Tahoma", Font.PLAIN, 15));
- name.setBackground(Color.BLACK);
- contentPane.add(name);
- pass = new JTextArea();
- pass.setBounds(210, 278, 203, 23);
- pass.setBackground(Color.BLACK);
- pass.setFont(new Font("Tahoma", Font.PLAIN, 15));
- pass.setForeground(Color.CYAN);
- contentPane.add(pass);
- age = new JTextArea();
- age.setBounds(210, 312, 203, 23);
- age.setFont(new Font("Tahoma", Font.PLAIN, 15));
- age.setForeground(Color.CYAN);
- age.setBackground(Color.BLACK);
- contentPane.add(age);
- pn = new JTextArea();
- pn.setBounds(210, 346, 203, 23);
- pn.setBackground(Color.BLACK);
- pn.setForeground(Color.CYAN);
- pn.setFont(new Font("Tahoma", Font.PLAIN, 15));
- contentPane.add(pn);
- m = new JRadioButton("Male");
- m.setBounds(210, 374, 75, 23);
- m.setForeground(Color.CYAN);
- m.setBackground(Color.BLACK);
- buttonGroup.add(m);
- contentPane.add(m);
- region = new JComboBox();
- region.setBounds(210, 407, 155, 20);
- region.setFont(new Font("Tahoma", Font.PLAIN, 15));
- region.setBackground(Color.BLACK);
- region.setForeground(Color.CYAN);
- region.setModel(new DefaultComboBoxModel(new String[] { "-", "Dhaka", "Barishal", "Shylet", "Khulna" }));
- contentPane.add(region);
- JLabel label_2 = new JLabel("Password :");
- label_2.setBounds(125, 273, 75, 26);
- label_2.setForeground(Color.CYAN);
- label_2.setFont(new Font("Tahoma", Font.PLAIN, 15));
- contentPane.add(label_2);
- JLabel lblAge = new JLabel("Age :");
- lblAge.setBounds(125, 307, 75, 26);
- lblAge.setForeground(Color.CYAN);
- lblAge.setFont(new Font("Tahoma", Font.PLAIN, 15));
- contentPane.add(lblAge);
- JLabel lblContact = new JLabel("Contact :");
- lblContact.setBounds(125, 341, 75, 26);
- lblContact.setForeground(Color.CYAN);
- lblContact.setFont(new Font("Tahoma", Font.PLAIN, 15));
- contentPane.add(lblContact);
- JLabel lblGender = new JLabel("Gender :");
- lblGender.setBounds(125, 370, 75, 26);
- lblGender.setForeground(Color.CYAN);
- lblGender.setFont(new Font("Tahoma", Font.PLAIN, 15));
- contentPane.add(lblGender);
- add = new JButton("Add");
- add.setBounds(538, 239, 99, 30);
- add.setBackground(Color.BLACK);
- add.setForeground(Color.CYAN);
- add.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- addd();
- }
- });
- contentPane.add(add);
- update = new JButton("Update");
- update.setBounds(538, 283, 99, 30);
- update.setForeground(Color.CYAN);
- update.setBackground(Color.BLACK);
- update.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- update();
- }
- });
- contentPane.add(update);
- delete = new JButton("Delete");
- delete.setBounds(538, 324, 99, 30);
- delete.setBackground(Color.BLACK);
- delete.setForeground(Color.CYAN);
- delete.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- delete();
- }
- });
- contentPane.add(delete);
- cb = new JComboBox();
- cb.setBounds(439, 55, 87, 29);
- cb.setFont(new Font("Tahoma", Font.PLAIN, 15));
- cb.setBackground(Color.BLACK);
- cb.setForeground(Color.CYAN);
- cb.setModel(new DefaultComboBoxModel(new String[] { "-", "Name", "Age", "Gender", "Contact" }));
- contentPane.add(cb);
- tf = new JTextField();
- tf.setBounds(538, 55, 110, 29);
- tf.setHorizontalAlignment(SwingConstants.CENTER);
- tf.setForeground(Color.CYAN);
- tf.setFont(new Font("Tahoma", Font.PLAIN, 15));
- tf.setBackground(Color.BLACK);
- tf.addKeyListener(new KeyAdapter() {
- @Override
- public void keyReleased(KeyEvent e) {
- sbo();
- }
- });
- contentPane.add(tf);
- tf.setColumns(10);
- JButton reset = new JButton("Reset");
- reset.setBounds(538, 365, 99, 30);
- reset.setForeground(Color.CYAN);
- reset.setBackground(Color.BLACK);
- reset.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- reset();
- }
- });
- contentPane.add(reset);
- btnLogOut = new JButton("Log Out");
- btnLogOut.setBounds(538, 408, 99, 30);
- btnLogOut.setBackground(Color.BLACK);
- btnLogOut.setForeground(Color.CYAN);
- btnLogOut.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- FJL f = new FJL();
- f.setVisible(true);
- dispose();
- }
- });
- contentPane.add(btnLogOut);
- cb1 = new JComboBox();
- cb1.setBounds(14, 55, 87, 29);
- cb1.setFont(new Font("Tahoma", Font.PLAIN, 15));
- cb1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- sbnt();
- }
- });
- cb1.setModel(new DefaultComboBoxModel(new String[] { "-" }));
- cb1.setForeground(Color.CYAN);
- cb1.setBackground(Color.BLACK);
- contentPane.add(cb1);
- scrollPane_1 = new JScrollPane();
- scrollPane_1.setBounds(14, 239, 87, 196);
- contentPane.add(scrollPane_1);
- adrslist = new JList();
- adrslist.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- sbat();
- }
- });
- adrslist.setBackground(Color.BLACK);
- adrslist.setForeground(Color.CYAN);
- adrslist.setFont(new Font("Tahoma", Font.PLAIN, 15));
- scrollPane_1.setViewportView(adrslist);
- }
- }
- ................................................................//CLASS NAME:FJL3
- import java.awt.BorderLayout;
- import java.awt.EventQueue;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.JLabel;
- import java.awt.Font;
- import java.awt.SystemColor;
- import javax.swing.JTextArea;
- import javax.swing.JCheckBox;
- import javax.swing.ButtonGroup;
- import javax.swing.JRadioButton;
- import javax.swing.JComboBox;
- import javax.swing.DefaultComboBoxModel;
- import javax.swing.JButton;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import java.awt.Color;
- public class FJL3 extends JFrame {
- private JPanel contentPane;
- private JTextArea name;
- private JTextArea age;
- private JTextArea pn;
- private JTextArea pass;
- private JRadioButton m,f;
- private JComboBox region;
- private JCheckBox cb;
- String p="";
- Connection a=null;
- PreparedStatement ps=null;
- ResultSet rs=null;
- private final ButtonGroup buttonGroup = new ButtonGroup();
- private final ButtonGroup buttonGroup_1 = new ButtonGroup();
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- FJL3 frame = new FJL3();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the frame.
- */
- public FJL3() {
- design();
- a=Cn.DB();
- }
- private void signup() {
- try {
- String z="INSERT INTO id(Name,Pass,Age,Gender,Contact,Region) VALUES (?,?,?,?,?,?)";
- ps=a.prepareStatement(z);
- ps.setString(1, name.getText());
- ps.setString(2, pass.getText());
- ps.setString(3, age.getText());
- if(m.isSelected()) {
- p= m.getText().toString();
- }else {
- p= f.getText().toString();
- }
- ps.setString(4,String.valueOf(p));
- //System.out.println(String.valueOf(p));
- ps.setString(5, pn.getText());
- ps.setString(6,region.getSelectedItem().toString());
- ps.execute();
- ps.close();
- FJL f=new FJL();
- f.setVisible(true);
- dispose();
- }catch(Exception e) {
- e.getStackTrace();
- }
- }
- private void design(){
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 433, 434);
- contentPane =
- new JPanel();
- contentPane.setBackground(Color.BLACK);
- contentPane.setForeground(Color.WHITE);
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- JLabel lblSignUpHere = new JLabel("Sign Up Here");
- lblSignUpHere.setForeground(Color.CYAN);
- lblSignUpHere.setBackground(SystemColor.control);
- lblSignUpHere.setFont(new Font("Tahoma", Font.BOLD, 18));
- lblSignUpHere.setBounds(152, 11, 122, 32);
- contentPane.add(lblSignUpHere);
- name = new JTextArea();
- name.setBounds(95, 73, 203, 23);
- contentPane.add(name);
- JLabel lblName = new JLabel("Name :");
- lblName.setForeground(Color.CYAN);
- lblName.setFont(new Font("Tahoma", Font.PLAIN, 15));
- lblName.setBounds(10, 70, 75, 26);
- contentPane.add(lblName);
- JLabel lblPass = new JLabel("Password :");
- lblPass.setForeground(Color.CYAN);
- lblPass.setFont(new Font("Tahoma", Font.PLAIN, 15));
- lblPass.setBounds(10, 107, 75, 26);
- contentPane.add(lblPass);
- JLabel lblAge = new JLabel("Age :");
- lblAge.setForeground(Color.CYAN);
- lblAge.setFont(new Font("Tahoma", Font.PLAIN, 15));
- lblAge.setBounds(10, 144, 87, 26);
- contentPane.add(lblAge);
- JLabel lblContact = new JLabel("Contact :");
- lblContact.setForeground(Color.CYAN);
- lblContact.setFont(new Font("Tahoma", Font.PLAIN, 15));
- lblContact.setBounds(10, 181, 87, 26);
- contentPane.add(lblContact);
- JLabel lblGender = new JLabel("Gender :");
- lblGender.setForeground(Color.CYAN);
- lblGender.setFont(new Font("Tahoma", Font.PLAIN, 15));
- lblGender.setBounds(10, 218, 87, 26);
- contentPane.add(lblGender);
- JLabel lblRegion = new JLabel("Region :");
- lblRegion.setForeground(Color.CYAN);
- lblRegion.setFont(new Font("Tahoma", Font.PLAIN, 15));
- lblRegion.setBounds(10, 255, 87, 26);
- contentPane.add(lblRegion);
- pass = new JTextArea();
- pass.setBounds(95, 107, 203, 23);
- contentPane.add(pass);
- age = new JTextArea();
- age.setBounds(95, 147, 203, 23);
- contentPane.add(age);
- pn = new JTextArea();
- pn.setBounds(95, 184, 203, 23);
- contentPane.add(pn);
- m = new JRadioButton("Male");
- m.setBackground(Color.BLACK);
- m.setForeground(Color.CYAN);
- buttonGroup_1.add(m);
- m.setBounds(94, 222, 75, 23);
- contentPane.add(m);
- f = new JRadioButton("Female");
- f.setBackground(Color.BLACK);
- f.setForeground(Color.CYAN);
- buttonGroup_1.add(f);
- f.setBounds(171, 222, 109, 23);
- contentPane.add(f);
- region = new JComboBox();
- region.setBackground(Color.BLACK);
- region.setForeground(Color.CYAN);
- region.setModel(new DefaultComboBoxModel(new String[] {"Dhaka", "Rangpur","Shylet"}));
- region.setBounds(95, 260, 155, 20);
- contentPane.add(region);
- cb = new JCheckBox("I Accept All The Condition And Terms");
- cb.setBackground(Color.BLACK);
- cb.setForeground(Color.CYAN);
- cb.setBounds(93, 293, 276, 23);
- contentPane.add(cb);
- JButton su = new JButton("Sign Up");
- su.setBackground(Color.BLACK);
- su.setForeground(Color.CYAN);
- su.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- if(cb.isSelected()) {
- signup();
- }
- }
- });
- su.setFont(new Font("Tahoma", Font.BOLD, 11));
- su.setBounds(142, 339, 109, 26);
- contentPane.add(su);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement