Advertisement
S_h_u_v_r_o

HW(4TH)

Jul 21st, 2019
701
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.82 KB | None | 0 0
  1. hw4
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.EventQueue;
  5.  
  6. import javax.swing.JFrame;
  7. import javax.swing.JPanel;
  8. import javax.swing.border.EmptyBorder;
  9.  
  10. import net.proteanit.sql.DbUtils;
  11.  
  12. import java.awt.Color;
  13. import javax.swing.JLabel;
  14. import javax.swing.JTable;
  15. import javax.swing.JButton;
  16. import java.awt.event.ActionListener;
  17. import java.sql.Connection;
  18. import java.sql.PreparedStatement;
  19. import java.sql.ResultSet;
  20. import java.awt.event.ActionEvent;
  21. import javax.swing.JScrollPane;
  22.  
  23. public class FJL extends JFrame {
  24.  
  25. private JPanel contentPane;
  26. private JTable table;
  27. Connection a = null;
  28. PreparedStatement ps = null;
  29. ResultSet rs = null;
  30. private JScrollPane scrollPane;
  31.  
  32. /**
  33. * Launch the application.
  34. */
  35. public static void main(String[] args) {
  36. EventQueue.invokeLater(new Runnable() {
  37. public void run() {
  38. try {
  39. FJL frame = new FJL();
  40. frame.setVisible(true);
  41. } catch (Exception e) {
  42. e.printStackTrace();
  43. }
  44. }
  45. });
  46. }
  47.  
  48. /**
  49. * Create the frame.
  50. */
  51.  
  52. public FJL() {
  53. design();
  54. a = Cn.DB();
  55.  
  56. }
  57.  
  58. private void login() {
  59. try {
  60. String x = "SELECT * FROM id1";
  61. ps = a.prepareStatement(x);
  62. rs = ps.executeQuery();
  63. table.setModel(DbUtils.resultSetToTableModel(rs));
  64.  
  65. } catch (Exception e) {
  66. e.printStackTrace();
  67. }
  68. }
  69.  
  70. private void design() {
  71. setBackground(Color.BLACK);
  72. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  73. setBounds(100, 100, 450, 300);
  74. contentPane = new JPanel();
  75. contentPane.setBackground(Color.BLACK);
  76. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  77. setContentPane(contentPane);
  78. contentPane.setLayout(null);
  79.  
  80. scrollPane = new JScrollPane();
  81. scrollPane.setBounds(10, 11, 414, 166);
  82. contentPane.add(scrollPane);
  83.  
  84. table = new JTable();
  85. scrollPane.setViewportView(table);
  86.  
  87. JButton B = new JButton("B");
  88. B.addActionListener(new ActionListener() {
  89. public void actionPerformed(ActionEvent arg0) {
  90. login(); }
  91. });
  92. B.setBounds(172, 209, 89, 23);
  93. contentPane.add(B);
  94. }
  95. }
  96.  
  97.  
  98. //CLASS NAME:Cn
  99.  
  100. import java.sql.Connection;
  101. import java.sql.DriverManager;
  102.  
  103. import javax.swing.JOptionPane;
  104.  
  105. public class Cn {
  106.  
  107. static Connection a;
  108.  
  109. public static Connection DB() {
  110.  
  111. try {
  112. Class.forName("com.mysql.jdbc.Driver");
  113.  
  114. a = DriverManager.getConnection("jdbc:mysql://localhost:3306/sms", "root", "");
  115. //JOptionPane.showMessageDialog(null, "Connected");
  116.  
  117. return a;
  118. } catch (Exception e) {
  119.  
  120. JOptionPane.showMessageDialog(null, "Connection Error");
  121. return null;
  122. }
  123. }
  124. }
  125.  
  126. ................................................................//CLASS NAME:FJL
  127.  
  128. import java.awt.BorderLayout;
  129. import java.awt.EventQueue;
  130.  
  131. import javax.swing.JFrame;
  132. import javax.swing.JPanel;
  133. import javax.swing.border.EmptyBorder;
  134. import javax.swing.JButton;
  135. import java.awt.Font;
  136. import java.sql.Connection;
  137. import java.sql.PreparedStatement;
  138. import java.sql.ResultSet;
  139. import java.text.SimpleDateFormat;
  140. import java.util.Calendar;
  141. import java.util.Date;
  142. import java.util.GregorianCalendar;
  143.  
  144. import javax.swing.JTextField;
  145. import javax.swing.JTextArea;
  146. import javax.swing.JTextPane;
  147. import java.awt.event.ActionListener;
  148. import java.awt.event.ActionEvent;
  149. import java.awt.SystemColor;
  150. import javax.swing.JPasswordField;
  151. import javax.swing.JTable;
  152. import javax.swing.JLabel;
  153. import java.awt.Color;
  154. import javax.swing.SwingConstants;
  155.  
  156. public class FJL extends JFrame {
  157.  
  158. private JPanel contentPane;
  159. private JTextField tfn;
  160. private JTextField cmnt;
  161.  
  162. public static String name1="";
  163. Connection a = null;
  164. PreparedStatement ps = null;
  165. ResultSet rs = null;
  166. private JPasswordField tfp;
  167. private JLabel lblClock;
  168. private JLabel lblTime;
  169.  
  170. /**
  171. * Launch the application.
  172. */
  173. public static void main(String[] args) {
  174. EventQueue.invokeLater(new Runnable() {
  175. public void run() {
  176. try {
  177. FJL frame = new FJL();
  178. frame.setVisible(true);
  179. } catch (Exception e) {
  180. e.printStackTrace();
  181. }
  182. }
  183. });
  184. }
  185.  
  186. /**
  187. * Create the frame.
  188. */
  189. public FJL() {
  190. design();
  191. a = Cn.DB();
  192. clock();
  193. }
  194.  
  195. private void login() {
  196. try {
  197. String x = "SELECT * FROM id WHERE name=? and pass=?";
  198. ps = a.prepareStatement(x);
  199. ps.setString(1, tfn.getText());
  200. ps.setString(2, tfp.getText());
  201. rs = ps.executeQuery();
  202.  
  203. if (rs.next()) {
  204. name1=rs.getString("Name");
  205. FJL2 f = new FJL2();
  206. dispose();
  207. f.setVisible(true);
  208. ps.close();
  209. rs.close();
  210. // cmnt.setText("Succesful");
  211. } else {
  212. cmnt.setText(" Please Sign Up");
  213. }
  214.  
  215. } catch (Exception e) {
  216. e.printStackTrace();
  217. }
  218. }
  219.  
  220. private void clock() {
  221. Thread clock =new Thread() {
  222. public void run() {
  223. try {
  224. for(;;) {
  225. Calendar cal = new GregorianCalendar();
  226.  
  227. SimpleDateFormat formatter=new SimpleDateFormat("dd-MM-yyyy");
  228. SimpleDateFormat formatt=new SimpleDateFormat("hh:mm:ss a");
  229.  
  230. Date date=cal.getTime();
  231. Date time=cal.getTime();
  232.  
  233. String timestring=formatter.format(date);
  234. String timestringg=formatt.format(date);
  235.  
  236. lblClock.setText(timestring);
  237. lblTime.setText(timestringg);
  238. sleep(1000);
  239. }
  240. }catch(Exception e) {
  241. e.printStackTrace();
  242. }
  243. }
  244. };
  245. clock.start();
  246. }
  247.  
  248. private void design() {
  249. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  250. setBounds(100, 100, 450, 300);
  251. contentPane = new JPanel();
  252. contentPane.setBackground(Color.BLACK);
  253. contentPane.setBorder(null);
  254. setContentPane(contentPane);
  255. contentPane.setLayout(null);
  256.  
  257. JButton li = new JButton("Log In");
  258. li.setForeground(Color.CYAN);
  259. li.setBackground(Color.BLACK);
  260. li.addActionListener(new ActionListener() {
  261. public void actionPerformed(ActionEvent arg0) {
  262. if(tfn.getText().equals("")) {
  263. cmnt.setText(" Enter Name");
  264. }
  265. else if(tfp.getText().equals("")) {
  266. cmnt.setText(" Enter Password");
  267. }
  268. else {
  269. login();
  270. }
  271. }
  272. });
  273. li.setFont(new Font("Tahoma", Font.BOLD, 14));
  274. li.setBounds(273, 168, 118, 28);
  275. contentPane.add(li);
  276.  
  277. JButton su = new JButton("Sign Up");
  278. su.setBackground(Color.BLACK);
  279. su.setForeground(Color.CYAN);
  280. su.addActionListener(new ActionListener() {
  281. public void actionPerformed(ActionEvent arg0) {
  282. FJL3 f = new FJL3();
  283. f.setVisible(true);
  284. dispose();
  285. }
  286. });
  287. su.setFont(new Font("Tahoma", Font.BOLD, 14));
  288. su.setBounds(273, 207, 118, 28);
  289. contentPane.add(su);
  290.  
  291. tfn = new JTextField();
  292. tfn.setBounds(10, 45, 137, 28);
  293. contentPane.add(tfn);
  294. tfn.setColumns(10);
  295.  
  296. cmnt = new JTextField();
  297. cmnt.setForeground(Color.BLACK);
  298. cmnt.setBackground(SystemColor.control);
  299. cmnt.setFont(new Font("Tahoma", Font.BOLD, 15));
  300. cmnt.setBounds(10, 183, 137, 28);
  301. contentPane.add(cmnt);
  302. cmnt.setColumns(10);
  303.  
  304. tfp = new JPasswordField();
  305. tfp.setBounds(10, 117, 137, 28);
  306. contentPane.add(tfp);
  307.  
  308. JLabel lblName = new JLabel("Name:");
  309. lblName.setForeground(Color.CYAN);
  310. lblName.setFont(new Font("Tahoma", Font.PLAIN, 13));
  311. lblName.setBackground(SystemColor.control);
  312. lblName.setBounds(10, 11, 70, 22);
  313. contentPane.add(lblName);
  314.  
  315. JLabel lblPassword = new JLabel("Password:");
  316. lblPassword.setForeground(Color.CYAN);
  317. lblPassword.setFont(new Font("Tahoma", Font.PLAIN, 13));
  318. lblPassword.setBackground(SystemColor.control);
  319. lblPassword.setBounds(10, 84, 80, 22);
  320. contentPane.add(lblPassword);
  321.  
  322. lblClock = new JLabel("CLOCK");
  323. lblClock.setFont(new Font("Tahoma", Font.PLAIN, 25));
  324. lblClock.setHorizontalAlignment(SwingConstants.CENTER);
  325. lblClock.setForeground(Color.CYAN);
  326. lblClock.setBounds(236, 84, 188, 58);
  327. contentPane.add(lblClock);
  328.  
  329. lblTime = new JLabel("TIME");
  330. lblTime.setHorizontalAlignment(SwingConstants.CENTER);
  331. lblTime.setForeground(Color.CYAN);
  332. lblTime.setFont(new Font("Tahoma", Font.PLAIN, 25));
  333. lblTime.setBounds(236, 27, 188, 52);
  334. contentPane.add(lblTime);
  335. }
  336. }
  337.  
  338. ................................................................//CLASS NAME:FJL2
  339.  
  340. import java.awt.BorderLayout; //line308
  341. import java.awt.EventQueue;
  342. import java.sql.Connection;
  343. import java.sql.PreparedStatement;
  344. import java.sql.ResultSet;
  345.  
  346. import javax.swing.JFrame;
  347. import javax.swing.JPanel;
  348. import javax.swing.border.EmptyBorder;
  349.  
  350. import net.proteanit.sql.DbUtils;
  351.  
  352. import javax.swing.JTextArea;
  353. import javax.swing.JTable;
  354. import javax.swing.JRadioButton;
  355. import javax.swing.JComboBox;
  356. import javax.swing.JLabel;
  357. import javax.swing.JOptionPane;
  358.  
  359. import java.awt.Font;
  360. import javax.swing.DefaultComboBoxModel;
  361. import javax.swing.DefaultListModel;
  362. import javax.swing.JButton;
  363. import javax.swing.JCheckBox;
  364. import javax.swing.JTextField;
  365. import java.awt.SystemColor;
  366. import java.awt.event.ActionListener;
  367. import java.awt.event.ActionEvent;
  368. import java.awt.event.MouseAdapter;
  369. import java.awt.event.MouseEvent;
  370. import javax.swing.JScrollPane;
  371. import javax.swing.ButtonGroup;
  372. import java.awt.Color;
  373. import java.awt.event.KeyAdapter;
  374. import java.awt.event.KeyEvent;
  375. import javax.swing.SwingConstants;
  376. import javax.swing.JList;
  377.  
  378. public class FJL2 extends JFrame {
  379.  
  380. private JPanel contentPane;
  381.  
  382. Connection a = null;
  383. PreparedStatement ps = null;
  384. ResultSet rs = null;
  385.  
  386. private JTextArea name;
  387. private JTextArea age;
  388. private JTextArea pn;
  389. private JTextArea pass;
  390.  
  391. private JRadioButton m, f;
  392. private JComboBox region;
  393. private JButton add, delete, update;
  394. private String p = "";
  395. private String combo = "";
  396. private int Id = 0;
  397.  
  398. private JTable table;
  399. private JScrollPane scrollPane;
  400. private final ButtonGroup buttonGroup = new ButtonGroup();
  401. private JComboBox cb;
  402. private JTextField tf;
  403. private JButton btnLogOut;
  404. private JComboBox cb1;
  405. private JList adrslist;
  406. private JScrollPane scrollPane_1;
  407. private JLabel ta;
  408. private JLabel ta2;
  409.  
  410. /**
  411. * Launch the application.
  412. */
  413. public static void main(String[] args) {
  414. EventQueue.invokeLater(new Runnable() {
  415. public void run() {
  416. try {
  417. FJL2 frame = new FJL2();
  418. frame.setVisible(true);
  419. } catch (Exception e) {
  420. e.printStackTrace();
  421. }
  422. }
  423. });
  424. }
  425.  
  426. /**
  427. * Create the frame.
  428. */
  429. public FJL2() {
  430. design();
  431. a = Cn.DB();
  432. ta.setText(" Welcome " + FJL.name1);
  433. ta2.setText("----------------------------------------");
  434.  
  435. FJL2();
  436. sbn();
  437. sba();
  438. }
  439.  
  440. private void FJL2() {
  441. try {
  442. String s = "Select Id,Name,Age,Gender,Contact,Region FROM id ";// Name,Age,Gender,Contact,Region
  443. ps = a.prepareStatement(s);
  444. rs = ps.executeQuery();
  445.  
  446. table.setModel(DbUtils.resultSetToTableModel(rs));
  447.  
  448. ps.close();
  449. rs.close();
  450.  
  451. } catch (Exception e) {
  452. e.getStackTrace();
  453. }
  454. }
  455.  
  456. private void addd() {
  457.  
  458. try {
  459. String z = "INSERT INTO id(Name,Pass,Age,Gender,Contact,Region) VALUES (?,?,?,?,?,?)";
  460. ps = a.prepareStatement(z);
  461.  
  462. ps.setString(1, name.getText());
  463. ps.setString(2, pass.getText());
  464. ps.setString(3, age.getText());
  465. if (m.isSelected()) {
  466. p = m.getText().toString();
  467. } else {
  468. p = f.getText().toString();
  469. }
  470. ps.setString(4, String.valueOf(p));
  471.  
  472. // System.out.println(String.valueOf(p));
  473.  
  474. ps.setString(5, pn.getText());
  475. ps.setString(6, region.getSelectedItem().toString());
  476.  
  477. ps.execute();
  478. ps.close();
  479.  
  480. reset();
  481.  
  482. } catch (Exception e) {
  483. e.getStackTrace();
  484. }
  485. }
  486.  
  487. private void table() {
  488. try {
  489. int row = table.getSelectedRow();
  490. String A = (table.getModel().getValueAt(row, 0)).toString();
  491. String B = "Select * FROM id WHERE Id='" + A + "'";
  492. ps = a.prepareStatement(B);
  493. rs = ps.executeQuery();
  494.  
  495. while (rs.next()) {
  496. Id = rs.getInt("Id");
  497. name.setText(rs.getString("Name"));
  498. // System.out.println(name);
  499. pass.setText(rs.getString("Pass"));
  500. age.setText(rs.getString("Age"));
  501.  
  502. p = rs.getString("Gender");
  503.  
  504. if (p.equals("Male")) {
  505. m.setSelected(true);
  506. f.setSelected(false);
  507. }
  508.  
  509. else if (p.equals("Female")) {
  510. f.setSelected(true);
  511. m.setSelected(false);
  512. }
  513. pn.setText(rs.getString("Contact"));
  514.  
  515. combo = rs.getString("Region");
  516.  
  517. if (combo.equals("Dhaka")) {
  518. region.setSelectedItem("Dhaka");
  519. }
  520.  
  521. else if (combo.equals("Shylet")) {
  522. region.setSelectedItem("Shylet");
  523. } else if (combo.equals("Khulna")) {
  524. region.setSelectedItem("Khulna");
  525. } else {
  526. region.setSelectedItem("Barishal");
  527. }
  528. }
  529. ps.close();
  530. rs.close();
  531.  
  532. } catch (Exception e) {
  533. e.printStackTrace();
  534. }
  535. }
  536.  
  537. private void update() {
  538.  
  539. // ctrl+shift+f=format
  540. try {
  541. String s = "Update id SET Name='" + name.getText() + "',Pass='" + pass.getText() + "',Age='" + age.getText()
  542. + "',Gender='" + p + "',Contact='" + pn.getText() + "',Region='"
  543. + region.getSelectedItem().toString() + "' Where Id='" + Id + "' ";
  544.  
  545. ps = a.prepareStatement(s);
  546. ps.execute();
  547. ps.close();
  548. reset();
  549. sba();
  550. } catch (Exception e) {
  551. e.printStackTrace();
  552. }
  553.  
  554. }
  555.  
  556. private void delete() {
  557. try {
  558. int x = JOptionPane.showConfirmDialog(null, "Are you sure?", "Delete", JOptionPane.YES_NO_CANCEL_OPTION);
  559. if (x == 0) {
  560. String s = "Delete From Id Where Id='" + Id + "' ";
  561. ps = a.prepareStatement(s);
  562. ps.execute();
  563. ps.close();
  564. reset();
  565. }
  566.  
  567. } catch (Exception e) {
  568. e.printStackTrace();
  569. }
  570.  
  571. }
  572.  
  573. private void sbo() {
  574. try {
  575. String s = (String) cb.getSelectedItem();
  576. String i = "SELECT Name,Pass,Age,Gender,Contact,Region FROM id WHERE " + s + " LIKE '" + tf.getText()
  577. + "%'";
  578. ps = a.prepareStatement(i);
  579. // ps.setString(1, tf.getText());
  580. rs = ps.executeQuery();
  581. table.setModel(DbUtils.resultSetToTableModel(rs));
  582. ps.close();
  583. rs.close();
  584.  
  585. } catch (Exception e) {
  586. e.printStackTrace();
  587. }
  588. }
  589.  
  590. private void reset() {
  591. name.setText(null);
  592. pass.setText(null);
  593. pn.setText(null);
  594. tf.setText(null);
  595. //buttonGroup.clearSelection();
  596. region.setSelectedItem("-");
  597. cb.setSelectedItem("-");
  598. cb1.setSelectedItem("-");
  599. age.setText(null);
  600. sba();
  601. FJL2();
  602. }
  603.  
  604. private void sbn() {
  605. try {
  606. String i = "SELECT Name FROM id";
  607. ps = a.prepareStatement(i);
  608.  
  609. rs = ps.executeQuery();
  610.  
  611. while (rs.next()) {
  612. cb1.addItem(rs.getString("Name"));
  613. }
  614. ps.close();
  615. rs.close();
  616.  
  617. } catch (Exception e) {
  618. e.printStackTrace();
  619. }
  620. }
  621.  
  622. private void sbnt() {// search by name table
  623. try {
  624. String B = "Select * FROM id WHERE Name= ?";
  625. ps = a.prepareStatement(B);
  626. ps.setString(1, (String) cb1.getSelectedItem());
  627. rs = ps.executeQuery();
  628.  
  629. while (rs.next()) {
  630. Id = rs.getInt("Id");
  631. name.setText(rs.getString("Name"));
  632. // System.out.println(name);
  633. pass.setText(rs.getString("Pass"));
  634. age.setText(rs.getString("Age"));
  635.  
  636. p = rs.getString("Gender");
  637.  
  638. if (p.equals("Male")) {
  639. m.setSelected(true);
  640. f.setSelected(false);
  641. }
  642.  
  643. else if (p.equals("Female")) {
  644. f.setSelected(true);
  645. m.setSelected(false);
  646. }
  647. pn.setText(rs.getString("Contact"));
  648.  
  649. combo = rs.getString("Region");
  650.  
  651. if (combo.equals("Dhaka")) {
  652. region.setSelectedItem("Dhaka");
  653. }
  654.  
  655. else if (combo.equals("Shylet")) {
  656. region.setSelectedItem("Shylet");
  657. } else if (combo.equals("Khulna")) {
  658. region.setSelectedItem("Khulna");
  659. } else {
  660. region.setSelectedItem("Barishal");
  661. }
  662. }
  663. ps.close();
  664. rs.close();
  665.  
  666. } catch (Exception e) {
  667. e.printStackTrace();
  668. }
  669. }
  670.  
  671. private void sba() {// a=address
  672. try {
  673. DefaultListModel dlm = new DefaultListModel();
  674. String i = "SELECT DISTINCT Region FROM id";
  675. ps = a.prepareStatement(i);
  676.  
  677. rs = ps.executeQuery();
  678.  
  679. while (rs.next()) {
  680. dlm.addElement(rs.getString("Region"));
  681. }
  682. adrslist.setModel(dlm);
  683. ps.close();
  684. rs.close();
  685.  
  686. } catch (Exception e) {
  687. e.printStackTrace();
  688. }
  689. }
  690.  
  691. private void sbat() {// search by adress table
  692. try {
  693. String B = "Select * FROM id WHERE Region= ?";
  694. ps = a.prepareStatement(B);
  695. ps.setString(1, (String) adrslist.getSelectedValue());
  696. rs = ps.executeQuery();
  697. table.setModel(DbUtils.resultSetToTableModel(rs));
  698.  
  699. /*
  700. * while (rs.next()) { Id = rs.getInt("Id"); name.setText(rs.getString("Name"));
  701. * // System.out.println(name); pass.setText(rs.getString("Pass"));
  702. * age.setText(rs.getString("Age"));
  703. *
  704. * p = rs.getString("Gender");
  705. *
  706. * if (p.equals("Male")) { m.setSelected(true); f.setSelected(false); }
  707. *
  708. * else if(p.equals("Female")) { f.setSelected(true); m.setSelected(false); }
  709. * pn.setText(rs.getString("Contact"));
  710. *
  711. * combo = rs.getString("Region");
  712. *
  713. * if (combo.equals("Dhaka")) { region.setSelectedItem("Dhaka"); }
  714. *
  715. * else if (combo.equals("Shylet")) { region.setSelectedItem("Shylet"); } else
  716. * if(combo.equals("Khulna")){ region.setSelectedItem("Khulna"); } else {
  717. * region.setSelectedItem("Barishal"); } }
  718. */
  719. ps.close();
  720. rs.close();
  721.  
  722. } catch (
  723.  
  724. Exception e) {
  725. e.printStackTrace();
  726. }
  727. }
  728.  
  729. private void design() {
  730. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  731. setBounds(100, 100, 671, 501);
  732. contentPane = new JPanel();
  733. contentPane.setBackground(Color.BLACK);
  734. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  735. setContentPane(contentPane);
  736. contentPane.setLayout(null);
  737.  
  738. scrollPane = new JScrollPane();
  739. scrollPane.setBounds(0, 105, 655, 111);
  740. contentPane.add(scrollPane);
  741.  
  742. ta = new JLabel("New label");
  743. ta.setForeground(Color.CYAN);
  744. ta.setFont(new Font("Tahoma", Font.BOLD, 18));
  745. ta.setBounds(223, 11, 209, 33);
  746. contentPane.add(ta);
  747.  
  748. table = new JTable();
  749. table.setBackground(Color.BLACK);
  750. table.setForeground(Color.CYAN);
  751. table.addMouseListener(new MouseAdapter() {
  752. @Override
  753. public void mouseClicked(MouseEvent arg0) {
  754. table();
  755. }
  756. });
  757. scrollPane.setViewportView(table);
  758.  
  759. f = new JRadioButton("Female");
  760. f.setBounds(287, 374, 109, 23);
  761. f.setBackground(Color.BLACK);
  762. f.setForeground(Color.CYAN);
  763. buttonGroup.add(f);
  764. contentPane.add(f);
  765.  
  766. JLabel label = new JLabel("Region :");
  767. label.setBounds(125, 404, 87, 26);
  768. label.setForeground(Color.CYAN);
  769. label.setFont(new Font("Tahoma", Font.PLAIN, 15));
  770. contentPane.add(label);
  771.  
  772. ta2 = new JLabel("");
  773. ta2.setForeground(Color.CYAN);
  774. ta2.setBackground(Color.BLACK);
  775. ta2.setBounds(218, 30, 191, 23);
  776. contentPane.add(ta2);
  777.  
  778. JLabel lblName = new JLabel("Name :");
  779. lblName.setBounds(125, 239, 75, 26);
  780. lblName.setForeground(Color.CYAN);
  781. lblName.setFont(new Font("Tahoma", Font.PLAIN, 15));
  782. contentPane.add(lblName);
  783.  
  784. name = new JTextArea();
  785. name.setBounds(210, 244, 203, 23);
  786. name.setForeground(Color.CYAN);
  787. name.setFont(new Font("Tahoma", Font.PLAIN, 15));
  788. name.setBackground(Color.BLACK);
  789. contentPane.add(name);
  790.  
  791. pass = new JTextArea();
  792. pass.setBounds(210, 278, 203, 23);
  793. pass.setBackground(Color.BLACK);
  794. pass.setFont(new Font("Tahoma", Font.PLAIN, 15));
  795. pass.setForeground(Color.CYAN);
  796. contentPane.add(pass);
  797.  
  798. age = new JTextArea();
  799. age.setBounds(210, 312, 203, 23);
  800. age.setFont(new Font("Tahoma", Font.PLAIN, 15));
  801. age.setForeground(Color.CYAN);
  802. age.setBackground(Color.BLACK);
  803. contentPane.add(age);
  804.  
  805. pn = new JTextArea();
  806. pn.setBounds(210, 346, 203, 23);
  807. pn.setBackground(Color.BLACK);
  808. pn.setForeground(Color.CYAN);
  809. pn.setFont(new Font("Tahoma", Font.PLAIN, 15));
  810. contentPane.add(pn);
  811.  
  812. m = new JRadioButton("Male");
  813. m.setBounds(210, 374, 75, 23);
  814. m.setForeground(Color.CYAN);
  815. m.setBackground(Color.BLACK);
  816. buttonGroup.add(m);
  817. contentPane.add(m);
  818.  
  819. region = new JComboBox();
  820. region.setBounds(210, 407, 155, 20);
  821. region.setFont(new Font("Tahoma", Font.PLAIN, 15));
  822. region.setBackground(Color.BLACK);
  823. region.setForeground(Color.CYAN);
  824. region.setModel(new DefaultComboBoxModel(new String[] { "-", "Dhaka", "Barishal", "Shylet", "Khulna" }));
  825. contentPane.add(region);
  826.  
  827. JLabel label_2 = new JLabel("Password :");
  828. label_2.setBounds(125, 273, 75, 26);
  829. label_2.setForeground(Color.CYAN);
  830. label_2.setFont(new Font("Tahoma", Font.PLAIN, 15));
  831. contentPane.add(label_2);
  832.  
  833. JLabel lblAge = new JLabel("Age :");
  834. lblAge.setBounds(125, 307, 75, 26);
  835. lblAge.setForeground(Color.CYAN);
  836. lblAge.setFont(new Font("Tahoma", Font.PLAIN, 15));
  837. contentPane.add(lblAge);
  838.  
  839. JLabel lblContact = new JLabel("Contact :");
  840. lblContact.setBounds(125, 341, 75, 26);
  841. lblContact.setForeground(Color.CYAN);
  842. lblContact.setFont(new Font("Tahoma", Font.PLAIN, 15));
  843. contentPane.add(lblContact);
  844.  
  845. JLabel lblGender = new JLabel("Gender :");
  846. lblGender.setBounds(125, 370, 75, 26);
  847. lblGender.setForeground(Color.CYAN);
  848. lblGender.setFont(new Font("Tahoma", Font.PLAIN, 15));
  849. contentPane.add(lblGender);
  850.  
  851. add = new JButton("Add");
  852. add.setBounds(538, 239, 99, 30);
  853. add.setBackground(Color.BLACK);
  854. add.setForeground(Color.CYAN);
  855. add.addActionListener(new ActionListener() {
  856. public void actionPerformed(ActionEvent e) {
  857. addd();
  858. }
  859. });
  860. contentPane.add(add);
  861.  
  862. update = new JButton("Update");
  863. update.setBounds(538, 283, 99, 30);
  864. update.setForeground(Color.CYAN);
  865. update.setBackground(Color.BLACK);
  866. update.addActionListener(new ActionListener() {
  867. public void actionPerformed(ActionEvent e) {
  868. update();
  869. }
  870. });
  871. contentPane.add(update);
  872.  
  873. delete = new JButton("Delete");
  874. delete.setBounds(538, 324, 99, 30);
  875. delete.setBackground(Color.BLACK);
  876. delete.setForeground(Color.CYAN);
  877. delete.addActionListener(new ActionListener() {
  878. public void actionPerformed(ActionEvent arg0) {
  879. delete();
  880. }
  881. });
  882. contentPane.add(delete);
  883.  
  884. cb = new JComboBox();
  885. cb.setBounds(439, 55, 87, 29);
  886. cb.setFont(new Font("Tahoma", Font.PLAIN, 15));
  887. cb.setBackground(Color.BLACK);
  888. cb.setForeground(Color.CYAN);
  889. cb.setModel(new DefaultComboBoxModel(new String[] { "-", "Name", "Age", "Gender", "Contact" }));
  890. contentPane.add(cb);
  891.  
  892. tf = new JTextField();
  893. tf.setBounds(538, 55, 110, 29);
  894. tf.setHorizontalAlignment(SwingConstants.CENTER);
  895. tf.setForeground(Color.CYAN);
  896. tf.setFont(new Font("Tahoma", Font.PLAIN, 15));
  897. tf.setBackground(Color.BLACK);
  898. tf.addKeyListener(new KeyAdapter() {
  899. @Override
  900. public void keyReleased(KeyEvent e) {
  901. sbo();
  902. }
  903. });
  904. contentPane.add(tf);
  905. tf.setColumns(10);
  906.  
  907. JButton reset = new JButton("Reset");
  908. reset.setBounds(538, 365, 99, 30);
  909. reset.setForeground(Color.CYAN);
  910. reset.setBackground(Color.BLACK);
  911. reset.addActionListener(new ActionListener() {
  912. public void actionPerformed(ActionEvent arg0) {
  913. reset();
  914. }
  915. });
  916. contentPane.add(reset);
  917.  
  918. btnLogOut = new JButton("Log Out");
  919. btnLogOut.setBounds(538, 408, 99, 30);
  920. btnLogOut.setBackground(Color.BLACK);
  921. btnLogOut.setForeground(Color.CYAN);
  922. btnLogOut.addActionListener(new ActionListener() {
  923. public void actionPerformed(ActionEvent e) {
  924. FJL f = new FJL();
  925. f.setVisible(true);
  926. dispose();
  927. }
  928. });
  929. contentPane.add(btnLogOut);
  930.  
  931. cb1 = new JComboBox();
  932. cb1.setBounds(14, 55, 87, 29);
  933. cb1.setFont(new Font("Tahoma", Font.PLAIN, 15));
  934. cb1.addActionListener(new ActionListener() {
  935. public void actionPerformed(ActionEvent arg0) {
  936. sbnt();
  937. }
  938. });
  939. cb1.setModel(new DefaultComboBoxModel(new String[] { "-" }));
  940. cb1.setForeground(Color.CYAN);
  941. cb1.setBackground(Color.BLACK);
  942. contentPane.add(cb1);
  943.  
  944. scrollPane_1 = new JScrollPane();
  945. scrollPane_1.setBounds(14, 239, 87, 196);
  946. contentPane.add(scrollPane_1);
  947.  
  948. adrslist = new JList();
  949. adrslist.addMouseListener(new MouseAdapter() {
  950. @Override
  951. public void mouseClicked(MouseEvent arg0) {
  952. sbat();
  953. }
  954. });
  955. adrslist.setBackground(Color.BLACK);
  956. adrslist.setForeground(Color.CYAN);
  957. adrslist.setFont(new Font("Tahoma", Font.PLAIN, 15));
  958. scrollPane_1.setViewportView(adrslist);
  959. }
  960. }
  961.  
  962. ................................................................//CLASS NAME:FJL3
  963.  
  964. import java.awt.BorderLayout;
  965. import java.awt.EventQueue;
  966. import java.sql.Connection;
  967. import java.sql.PreparedStatement;
  968. import java.sql.ResultSet;
  969.  
  970. import javax.swing.JFrame;
  971. import javax.swing.JPanel;
  972. import javax.swing.border.EmptyBorder;
  973. import javax.swing.JLabel;
  974. import java.awt.Font;
  975. import java.awt.SystemColor;
  976. import javax.swing.JTextArea;
  977. import javax.swing.JCheckBox;
  978. import javax.swing.ButtonGroup;
  979. import javax.swing.JRadioButton;
  980. import javax.swing.JComboBox;
  981. import javax.swing.DefaultComboBoxModel;
  982. import javax.swing.JButton;
  983. import java.awt.event.ActionListener;
  984. import java.awt.event.ActionEvent;
  985. import java.awt.Color;
  986.  
  987. public class FJL3 extends JFrame {
  988.  
  989. private JPanel contentPane;
  990. private JTextArea name;
  991. private JTextArea age;
  992. private JTextArea pn;
  993. private JTextArea pass;
  994.  
  995. private JRadioButton m,f;
  996. private JComboBox region;
  997. private JCheckBox cb;
  998. String p="";
  999.  
  1000.  
  1001. Connection a=null;
  1002. PreparedStatement ps=null;
  1003. ResultSet rs=null;
  1004.  
  1005. private final ButtonGroup buttonGroup = new ButtonGroup();
  1006. private final ButtonGroup buttonGroup_1 = new ButtonGroup();
  1007.  
  1008. /**
  1009. * Launch the application.
  1010. */
  1011. public static void main(String[] args) {
  1012. EventQueue.invokeLater(new Runnable() {
  1013. public void run() {
  1014. try {
  1015. FJL3 frame = new FJL3();
  1016. frame.setVisible(true);
  1017. } catch (Exception e) {
  1018. e.printStackTrace();
  1019. }
  1020. }
  1021. });
  1022. }
  1023.  
  1024. /**
  1025. * Create the frame.
  1026. */
  1027. public FJL3() {
  1028. design();
  1029. a=Cn.DB();
  1030. }
  1031.  
  1032. private void signup() {
  1033.  
  1034. try {
  1035. String z="INSERT INTO id(Name,Pass,Age,Gender,Contact,Region) VALUES (?,?,?,?,?,?)";
  1036. ps=a.prepareStatement(z);
  1037.  
  1038. ps.setString(1, name.getText());
  1039. ps.setString(2, pass.getText());
  1040. ps.setString(3, age.getText());
  1041. if(m.isSelected()) {
  1042. p= m.getText().toString();
  1043. }else {
  1044. p= f.getText().toString();
  1045. }
  1046. ps.setString(4,String.valueOf(p));
  1047.  
  1048. //System.out.println(String.valueOf(p));
  1049.  
  1050. ps.setString(5, pn.getText());
  1051. ps.setString(6,region.getSelectedItem().toString());
  1052.  
  1053. ps.execute();
  1054. ps.close();
  1055.  
  1056. FJL f=new FJL();
  1057. f.setVisible(true);
  1058. dispose();
  1059.  
  1060. }catch(Exception e) {
  1061. e.getStackTrace();
  1062. }
  1063. }
  1064.  
  1065. private void design(){
  1066. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  1067. setBounds(100, 100, 433, 434);
  1068. contentPane =
  1069. new JPanel();
  1070. contentPane.setBackground(Color.BLACK);
  1071. contentPane.setForeground(Color.WHITE);
  1072. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  1073. setContentPane(contentPane);
  1074. contentPane.setLayout(null);
  1075.  
  1076. JLabel lblSignUpHere = new JLabel("Sign Up Here");
  1077. lblSignUpHere.setForeground(Color.CYAN);
  1078. lblSignUpHere.setBackground(SystemColor.control);
  1079. lblSignUpHere.setFont(new Font("Tahoma", Font.BOLD, 18));
  1080. lblSignUpHere.setBounds(152, 11, 122, 32);
  1081. contentPane.add(lblSignUpHere);
  1082.  
  1083. name = new JTextArea();
  1084. name.setBounds(95, 73, 203, 23);
  1085. contentPane.add(name);
  1086.  
  1087. JLabel lblName = new JLabel("Name :");
  1088. lblName.setForeground(Color.CYAN);
  1089. lblName.setFont(new Font("Tahoma", Font.PLAIN, 15));
  1090. lblName.setBounds(10, 70, 75, 26);
  1091. contentPane.add(lblName);
  1092.  
  1093. JLabel lblPass = new JLabel("Password :");
  1094. lblPass.setForeground(Color.CYAN);
  1095. lblPass.setFont(new Font("Tahoma", Font.PLAIN, 15));
  1096. lblPass.setBounds(10, 107, 75, 26);
  1097. contentPane.add(lblPass);
  1098.  
  1099. JLabel lblAge = new JLabel("Age :");
  1100. lblAge.setForeground(Color.CYAN);
  1101. lblAge.setFont(new Font("Tahoma", Font.PLAIN, 15));
  1102. lblAge.setBounds(10, 144, 87, 26);
  1103. contentPane.add(lblAge);
  1104.  
  1105. JLabel lblContact = new JLabel("Contact :");
  1106. lblContact.setForeground(Color.CYAN);
  1107. lblContact.setFont(new Font("Tahoma", Font.PLAIN, 15));
  1108. lblContact.setBounds(10, 181, 87, 26);
  1109. contentPane.add(lblContact);
  1110.  
  1111. JLabel lblGender = new JLabel("Gender :");
  1112. lblGender.setForeground(Color.CYAN);
  1113. lblGender.setFont(new Font("Tahoma", Font.PLAIN, 15));
  1114. lblGender.setBounds(10, 218, 87, 26);
  1115. contentPane.add(lblGender);
  1116.  
  1117. JLabel lblRegion = new JLabel("Region :");
  1118. lblRegion.setForeground(Color.CYAN);
  1119. lblRegion.setFont(new Font("Tahoma", Font.PLAIN, 15));
  1120. lblRegion.setBounds(10, 255, 87, 26);
  1121. contentPane.add(lblRegion);
  1122.  
  1123. pass = new JTextArea();
  1124. pass.setBounds(95, 107, 203, 23);
  1125. contentPane.add(pass);
  1126.  
  1127. age = new JTextArea();
  1128. age.setBounds(95, 147, 203, 23);
  1129. contentPane.add(age);
  1130.  
  1131. pn = new JTextArea();
  1132. pn.setBounds(95, 184, 203, 23);
  1133. contentPane.add(pn);
  1134.  
  1135. m = new JRadioButton("Male");
  1136. m.setBackground(Color.BLACK);
  1137. m.setForeground(Color.CYAN);
  1138. buttonGroup_1.add(m);
  1139. m.setBounds(94, 222, 75, 23);
  1140. contentPane.add(m);
  1141.  
  1142. f = new JRadioButton("Female");
  1143. f.setBackground(Color.BLACK);
  1144. f.setForeground(Color.CYAN);
  1145. buttonGroup_1.add(f);
  1146. f.setBounds(171, 222, 109, 23);
  1147. contentPane.add(f);
  1148.  
  1149. region = new JComboBox();
  1150. region.setBackground(Color.BLACK);
  1151. region.setForeground(Color.CYAN);
  1152. region.setModel(new DefaultComboBoxModel(new String[] {"Dhaka", "Rangpur","Shylet"}));
  1153. region.setBounds(95, 260, 155, 20);
  1154. contentPane.add(region);
  1155.  
  1156. cb = new JCheckBox("I Accept All The Condition And Terms");
  1157. cb.setBackground(Color.BLACK);
  1158. cb.setForeground(Color.CYAN);
  1159. cb.setBounds(93, 293, 276, 23);
  1160. contentPane.add(cb);
  1161.  
  1162. JButton su = new JButton("Sign Up");
  1163. su.setBackground(Color.BLACK);
  1164. su.setForeground(Color.CYAN);
  1165. su.addActionListener(new ActionListener() {
  1166. public void actionPerformed(ActionEvent arg0) {
  1167. if(cb.isSelected()) {
  1168. signup();
  1169. }
  1170.  
  1171. }
  1172. });
  1173. su.setFont(new Font("Tahoma", Font.BOLD, 11));
  1174. su.setBounds(142, 339, 109, 26);
  1175. contentPane.add(su);
  1176. }
  1177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement