Advertisement
Guest User

Untitled

a guest
May 27th, 2015
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.54 KB | None | 0 0
  1. import java.awt.CardLayout;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.EventQueue;
  5. import java.awt.Font;
  6. import java.awt.SystemColor;
  7. import java.awt.event.ActionEvent;
  8. import java.awt.event.ActionListener;
  9. import java.util.ArrayList;
  10.  
  11. import javax.swing.ButtonGroup;
  12. import javax.swing.JButton;
  13. import javax.swing.JFrame;
  14. import javax.swing.JLabel;
  15. import javax.swing.JOptionPane;
  16. import javax.swing.JPanel;
  17. import javax.swing.JPasswordField;
  18. import javax.swing.JRadioButton;
  19. import javax.swing.JScrollPane;
  20. import javax.swing.JTable;
  21. import javax.swing.JTextField;
  22. import javax.swing.JTextPane;
  23. import javax.swing.border.BevelBorder;
  24. import javax.swing.border.LineBorder;
  25. import javax.swing.table.DefaultTableModel;
  26. import java.sql.*;
  27.  
  28. import org.eclipse.wb.swing.FocusTraversalOnArray;
  29.  
  30. public class Database {
  31.  
  32. private JFrame frame;
  33. private JFrame frame1;
  34. private JTextField Username;
  35. private JPasswordField password;
  36. private JPanel panel;
  37. private CardLayout card;
  38. private JTextField usersign;
  39. private JTextField firstname;
  40. private JTextField lastname;
  41. private JPasswordField passwordsign;
  42. private JTextField textField_2;
  43. private JTextField threshold;
  44. private JTextField EnterISBN;
  45. private JTextField title;
  46. private JTextField Publisher;
  47. private JTextField Year;
  48. private JTextField price;
  49. private JTextField category;
  50. private JTextField copies;
  51. private JTextPane authorList;
  52.  
  53. // private Connection con;
  54. // private Statement stt;
  55.  
  56. String insertINtoTable(String table, ArrayList<String> attr,
  57. ArrayList<String> values) {
  58.  
  59. String query = "Insert into `" + table + "`(";
  60. for (int i = 0; i < attr.size(); i++) {
  61.  
  62. query += "`" + attr.get(i) + "`";
  63.  
  64. if (i != attr.size() - 1)
  65. query += ",";
  66. }
  67. query += ") values (";
  68. for (int i = 0; i < values.size(); i++) {
  69. query += "'" + values.get(i) + "'";
  70. if (i != values.size() - 1)
  71. query += ",";
  72. }
  73. query += ")";
  74. return query;
  75.  
  76. }
  77.  
  78. boolean validateEmpty(String a) {
  79. if (a.length() == 0)
  80. return false;
  81.  
  82. return true;
  83.  
  84. }
  85.  
  86. boolean validatePrice(String a) {
  87. try {
  88. double k = Double.parseDouble(a);
  89. return true;
  90. } catch (Exception e) {
  91. return false;
  92. }
  93. }
  94.  
  95. boolean checkInsert() {
  96. boolean check = true;
  97. if (EnterISBN.getText().equals("") || !validateNum(EnterISBN.getText())) {
  98. check = false;
  99. } else if (title.getText().equals("")) {
  100. check = false;
  101. } else if (Publisher.getText().equals("")) {
  102. check = false;
  103.  
  104. } else if (Year.getText().equals("") || !validateNum(Year.getText())) {
  105. check = false;
  106. } else if (price.getText().equals("")
  107. || !validatePrice(price.getText())) {
  108. check = false;
  109. } else if (category.getText().equals("")) {
  110. check = false;
  111. } else if (copies.getText().equals("")
  112. || !validateNum(copies.getText())) {
  113. check = false;
  114. } else if (threshold.getText().equals("")
  115. || !validateNum(threshold.getText())) {
  116. check = false;
  117. } else if (authorList.getText().equals("")) {
  118. check = false;
  119. }
  120.  
  121. if (!check) {
  122.  
  123. JOptionPane.showMessageDialog(frame,
  124. "please check inserted fields.", "Inane error",
  125. JOptionPane.ERROR_MESSAGE);
  126.  
  127. }
  128. return check;
  129. }
  130.  
  131. boolean validatePhone(String a) {
  132. if (a.length() == 0)
  133. return false;
  134. if (a.charAt(0) != '+' && (a.charAt(0) < '0' || a.charAt(0) > '9'))
  135. return false;
  136. for (int i = 1; i < a.length(); i++) {
  137. if (a.charAt(i) >= '0' && a.charAt(i) <= '9')
  138. continue;
  139. return false;
  140. }
  141. return true;
  142. }
  143.  
  144. boolean validateNum(String a) {
  145. for (int i = 1; i < a.length(); i++) {
  146. if (a.charAt(i) >= '0' && a.charAt(i) <= '9')
  147. continue;
  148. return false;
  149. }
  150. return true;
  151. }
  152.  
  153. void publisherData() {
  154. String publisher = Publisher.getText();
  155.  
  156. try {
  157.  
  158. /*
  159. * ResultSet res =
  160. * stt.executeQuery("SELECT * FROM book WHERE `Publisher` = '"
  161. * +publisher+"'");
  162. */
  163. // if(!res.next()){
  164. JTextField address = new JTextField();
  165. JTextField phone = new JTextField();
  166. Object[] message = { "address:", address, "phone:", phone };
  167.  
  168. int option = JOptionPane.showConfirmDialog(null, message,
  169. "Publisher", JOptionPane.OK_CANCEL_OPTION);
  170. while (option == JOptionPane.OK_OPTION
  171. && (address.getText().equals("") || !validatePhone(phone
  172. .getText()))) {
  173. option = JOptionPane.showConfirmDialog(null, message,
  174. "Publisher", JOptionPane.OK_CANCEL_OPTION);
  175. }
  176. if (option == JOptionPane.OK_OPTION) {
  177. ArrayList<String> attr = new ArrayList();
  178. ArrayList<String> value = new ArrayList();
  179. attr.add("Publisher");
  180. attr.add("Address");
  181. attr.add("Phone");
  182. value.add(publisher);
  183. value.add(address.getText());
  184. value.add(phone.getText());
  185. String query = insertINtoTable("Publisher", attr, value);
  186. // stt.execute(query);
  187. System.out.println(query);
  188. }
  189.  
  190. // }
  191. } catch (Exception e) {
  192. e.printStackTrace();
  193. }
  194. }
  195.  
  196. /**
  197. * Launch the application.
  198. */
  199. public static void main(String[] args) {
  200. EventQueue.invokeLater(new Runnable() {
  201. public void run() {
  202. try {
  203. Database window = new Database();
  204. window.frame.setVisible(true);
  205. } catch (Exception e) {
  206. e.printStackTrace();
  207. }
  208. }
  209. });
  210. }
  211.  
  212. /**
  213. * Create the application.
  214. *
  215. * @throws SQLException
  216. * @throws ClassNotFoundException
  217. * @throws IllegalAccessException
  218. * @throws InstantiationException
  219. */
  220. public Database() throws InstantiationException, IllegalAccessException,
  221. ClassNotFoundException, SQLException {
  222. initialize();
  223. }
  224.  
  225. /**
  226. * Initialize the contents of the frame.
  227. *
  228. * @throws SQLException
  229. * @throws ClassNotFoundException
  230. * @throws IllegalAccessException
  231. * @throws InstantiationException
  232. */
  233. private void initialize() throws SQLException, InstantiationException,
  234. IllegalAccessException, ClassNotFoundException {
  235.  
  236. /*
  237. * Class.forName("com.mysql.jdbc.Driver").newInstance();
  238. *
  239. * String url = "jdbc:mysql://localhost:3306/"; con =
  240. * DriverManager.getConnection(url, "root", "");
  241. *
  242. * stt = con.createStatement(); stt.execute("USE book_store");
  243. */
  244.  
  245. frame = new JFrame();
  246. frame.getContentPane().setForeground(SystemColor.activeCaption);
  247. frame.getContentPane().setBackground(Color.LIGHT_GRAY);
  248. frame.getContentPane().setFont(new Font("Tahoma", Font.BOLD, 13));
  249. frame.setBounds(100, 100, 541, 476);
  250. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  251. frame.getContentPane().setLayout(null);
  252. /*
  253. * frame1=new JFrame();
  254. * frame1.getContentPane().setForeground(SystemColor.activeCaption);
  255. * frame1.getContentPane().setBackground(Color.LIGHT_GRAY);
  256. * frame1.getContentPane().setFont(new Font("Tahoma", Font.BOLD, 13));
  257. * frame1.setBounds(100, 100, 450, 476);
  258. * frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  259. * frame1.getContentPane().setLayout(null);
  260. */
  261. panel = new JPanel();
  262. panel.setBounds(0, 0, 544, 430);
  263. frame.getContentPane().add(panel);
  264. card = new CardLayout(0, 0);
  265. panel.setLayout(card);
  266.  
  267. JPanel panel_1 = new JPanel();
  268. panel_1.setBounds(0, 0, 544, 430);
  269. panel.add(panel_1, "first");
  270. panel_1.setLayout(null);
  271.  
  272. Username = new JTextField();
  273. Username.setBounds(154, 163, 126, 20);
  274. panel_1.add(Username);
  275. Username.setColumns(10);
  276.  
  277. JLabel lblUsername = new JLabel("Username");
  278. lblUsername.setBounds(64, 166, 75, 14);
  279. lblUsername.setFont(new Font("Tahoma", Font.BOLD, 13));
  280. lblUsername.setBackground(Color.BLUE);
  281. panel_1.add(lblUsername);
  282.  
  283. JLabel lblPassword = new JLabel("Password");
  284. lblPassword.setBounds(64, 197, 69, 14);
  285. lblPassword.setFont(new Font("Tahoma", Font.BOLD, 13));
  286. panel_1.add(lblPassword);
  287.  
  288. password = new JPasswordField();
  289. password.setBounds(154, 194, 126, 20);
  290. panel_1.add(password);
  291.  
  292. JButton btnLogin = new JButton("login");
  293. btnLogin.setBounds(154, 249, 89, 23);
  294.  
  295. btnLogin.setBackground(Color.ORANGE);
  296. panel_1.add(btnLogin);
  297.  
  298. final JPanel panel_2 = new JPanel();
  299. panel_2.setBounds(318, 58, 89, 23);
  300. panel_1.add(panel_2, "second");
  301. panel_2.setLayout(null);
  302.  
  303. JButton btnSignUp = new JButton("sign up");
  304.  
  305. btnSignUp.setBounds(0, 0, 89, 23);
  306. panel_2.add(btnSignUp);
  307. btnSignUp.setFont(new Font("Tahoma", Font.BOLD, 13));
  308. btnSignUp.setBackground(Color.WHITE);
  309.  
  310. JPanel panel_3 = new JPanel();
  311. panel_3.setBorder(new BevelBorder(BevelBorder.LOWERED, new Color(255,
  312. 0, 0), Color.RED, Color.RED, Color.RED));
  313. panel_3.setBounds(36, 107, 331, 215);
  314. panel_1.add(panel_3, "third");
  315. panel_3.setLayout(null);
  316.  
  317. JLabel lblNewLabel = new JLabel("Login");
  318. lblNewLabel.setBounds(149, 24, 46, 14);
  319. panel_3.add(lblNewLabel);
  320.  
  321. JLabel errorMsg = new JLabel("");
  322. errorMsg.setBounds(85, 117, 197, 14);
  323. panel_3.add(errorMsg);
  324.  
  325. panel.setFocusTraversalPolicy(new FocusTraversalOnArray(
  326. new Component[] { Username, lblUsername, lblPassword, password,
  327. btnLogin, btnSignUp }));
  328. JPanel panel_4 = new JPanel();
  329. panel_4.setBackground(Color.WHITE);
  330. panel_4.setBounds(0, 0, 544, 430);
  331. panel.add(panel_4, "fourth");
  332. panel_4.setLayout(null);
  333.  
  334. JLabel lblSignUp = new JLabel("Sign up");
  335. lblSignUp.setFont(new Font("Tahoma", Font.BOLD, 14));
  336. lblSignUp.setBounds(188, 54, 102, 31);
  337. panel_4.add(lblSignUp);
  338.  
  339. usersign = new JTextField();
  340. usersign.setBounds(150, 122, 154, 20);
  341. panel_4.add(usersign);
  342. usersign.setColumns(10);
  343.  
  344. firstname = new JTextField();
  345. firstname.setBounds(150, 240, 154, 20);
  346. panel_4.add(firstname);
  347. firstname.setColumns(10);
  348.  
  349. lastname = new JTextField();
  350. lastname.setBounds(150, 300, 154, 20);
  351. panel_4.add(lastname);
  352. lastname.setColumns(10);
  353.  
  354. JLabel lblUsername_1 = new JLabel("Username");
  355. lblUsername_1.setBounds(35, 128, 105, 14);
  356. panel_4.add(lblUsername_1);
  357.  
  358. passwordsign = new JPasswordField();
  359. passwordsign.setBounds(150, 179, 154, 20);
  360. panel_4.add(passwordsign);
  361.  
  362. JLabel lblPassword_1 = new JLabel("Password");
  363. lblPassword_1.setBounds(35, 185, 105, 14);
  364. panel_4.add(lblPassword_1);
  365.  
  366. JLabel lblFirstName = new JLabel("First Name");
  367. lblFirstName.setBounds(35, 246, 105, 14);
  368. panel_4.add(lblFirstName);
  369.  
  370. JLabel lblNewLabel_1 = new JLabel("Last Name");
  371. lblNewLabel_1.setBounds(35, 306, 105, 14);
  372. panel_4.add(lblNewLabel_1);
  373.  
  374. JButton btnSubmit = new JButton("Register");
  375. btnSubmit.addActionListener(new ActionListener() {
  376. public void actionPerformed(ActionEvent arg0) {
  377.  
  378. if (validateEmpty(usersign.getText())
  379. && validateEmpty(passwordsign.getText())
  380. && validateEmpty(firstname.getText())
  381. && validateEmpty(lastname.getText())) {
  382. ArrayList<String> attr = new ArrayList();
  383. ArrayList<String> values = new ArrayList();
  384. attr.add("Username");
  385. attr.add("Password");
  386. attr.add("First_name");
  387. attr.add("Last_name");
  388. values.add(usersign.getText());
  389. values.add(passwordsign.getText());
  390. values.add(firstname.getText());
  391. values.add(lastname.getText());
  392. String query = insertINtoTable("Register", attr, values);
  393. System.out.println(query);
  394. // insert this query into register table
  395. // username is primary key
  396. // if this username is not duplicate ,show this message
  397.  
  398. JOptionPane.showMessageDialog(frame,
  399. "Register done successfully !", "A plain message",
  400. JOptionPane.PLAIN_MESSAGE);
  401.  
  402. //else show this message
  403. JOptionPane.showMessageDialog(frame,
  404. "This username exist before !",
  405. "Inane warning",
  406. JOptionPane.WARNING_MESSAGE);
  407. } else {
  408. JOptionPane.showMessageDialog(frame,
  409. "Please fill empty fields !", "Inane warning",
  410. JOptionPane.WARNING_MESSAGE);
  411.  
  412. }
  413.  
  414. }
  415. });
  416. btnSubmit.setBounds(178, 372, 89, 23);
  417. panel_4.add(btnSubmit);
  418.  
  419. JButton btnNewButton = new JButton("Back");
  420. btnNewButton.addActionListener(new ActionListener() {
  421. public void actionPerformed(ActionEvent arg0) {
  422. card.show(panel, "first");
  423.  
  424. }
  425. });
  426. btnNewButton.setBounds(10, 11, 89, 23);
  427. panel_4.add(btnNewButton);
  428.  
  429. JLabel usernameMsg = new JLabel("");
  430. usernameMsg.setBounds(150, 151, 236, 14);
  431. panel_4.add(usernameMsg);
  432.  
  433. JLabel passwordMsg = new JLabel("");
  434. passwordMsg.setBounds(150, 215, 236, 14);
  435. panel_4.add(passwordMsg);
  436.  
  437. JLabel firstnameMsg = new JLabel("");
  438. firstnameMsg.setBounds(150, 275, 236, 14);
  439. panel_4.add(firstnameMsg);
  440.  
  441. JLabel lastnameMsg = new JLabel("");
  442. lastnameMsg.setBounds(150, 331, 291, 14);
  443. panel_4.add(lastnameMsg);
  444. btnSignUp.addActionListener(new ActionListener() {
  445. public void actionPerformed(ActionEvent e) {
  446. card.show(panel, "fourth");
  447. }
  448. });
  449.  
  450. // *************************operations***************************
  451.  
  452. JPanel panel_5 = new JPanel();
  453. panel_5.setBackground(Color.CYAN);
  454. panel_5.setBounds(0, 0, 424, 419);
  455. panel.add(panel_5, "operations");
  456. panel_5.setLayout(null);
  457.  
  458. JPanel panel_7 = new JPanel();
  459. panel_7.setBackground(Color.BLUE);
  460. panel_7.setBorder(new LineBorder(new Color(0, 0, 0), 4));
  461. panel_7.setBounds(125, 92, 137, 254);
  462. panel_5.add(panel_7);
  463. panel_7.setLayout(null);
  464.  
  465. JButton btnNewButton1 = new JButton("add book");
  466. btnNewButton1.addActionListener(new ActionListener() {
  467. public void actionPerformed(ActionEvent e) {
  468. card.show(panel, "addbooks");
  469. }
  470. });
  471. btnNewButton1.setBounds(6, 16, 125, 23);
  472. panel_7.add(btnNewButton1);
  473.  
  474. JButton btnNewButton_1 = new JButton("update");
  475. btnNewButton_1.addActionListener(new ActionListener() {
  476. public void actionPerformed(ActionEvent e) {
  477. card.show(panel, "search/update");
  478. }
  479. });
  480. btnNewButton_1.setBounds(6, 86, 125, 23);
  481. panel_7.add(btnNewButton_1);
  482.  
  483. JButton btnNewButton_2 = new JButton("confirm order");
  484. btnNewButton_2.addActionListener(new ActionListener() {
  485. public void actionPerformed(ActionEvent e) {
  486. card.show(panel, "confirmOrders");
  487. }
  488. });
  489. btnNewButton_2.setBounds(6, 148, 125, 23);
  490. panel_7.add(btnNewButton_2);
  491.  
  492. JButton btnNewButton_3 = new JButton("search");
  493. btnNewButton_3.addActionListener(new ActionListener() {
  494. public void actionPerformed(ActionEvent e) {
  495. card.show(panel, "search/update");
  496. }
  497. });
  498. btnNewButton_3.setBounds(6, 216, 125, 23);
  499. panel_7.add(btnNewButton_3);
  500.  
  501. JLabel lblUsersOperations = new JLabel(
  502. " Users operations");
  503. lblUsersOperations.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC,
  504. 14));
  505. lblUsersOperations.setBounds(45, 50, 363, 39);
  506. panel_5.add(lblUsersOperations);
  507.  
  508. JLabel lblNewLabel_2 = new JLabel("New label");
  509. lblNewLabel_2.setBounds(10, 11, 150, 28);
  510. panel_5.add(lblNewLabel_2);
  511.  
  512. JButton btnLogout = new JButton("logout");
  513. btnLogout.addActionListener(new ActionListener() {
  514. public void actionPerformed(ActionEvent e) {
  515. card.show(panel, "first");
  516. }
  517. });
  518. btnLogout.setBounds(319, 14, 89, 23);
  519. panel_5.add(btnLogout);
  520.  
  521. JPanel panel_8 = new JPanel();
  522. panel_8.setBounds(50, 50, 10, 10);
  523. panel.add(panel_8, "confirmOrders");
  524. panel_8.setLayout(null);
  525.  
  526. JButton btnNewButton_4 = new JButton("Back");
  527. btnNewButton_4.addActionListener(new ActionListener() {
  528. public void actionPerformed(ActionEvent e) {
  529. card.show(panel, "operations");
  530. }
  531. });
  532. btnNewButton_4.setBounds(10, 11, 89, 23);
  533. panel_8.add(btnNewButton_4);
  534.  
  535. textField_2 = new JTextField();
  536. textField_2.setBounds(162, 138, 138, 20);
  537. panel_8.add(textField_2);
  538. textField_2.setColumns(10);
  539.  
  540. JLabel lblNewLabel_3 = new JLabel("Enter ISBN");
  541. lblNewLabel_3.setBounds(38, 141, 114, 14);
  542. panel_8.add(lblNewLabel_3);
  543.  
  544. JLabel lblNewLabel_4 = new JLabel("Confirm Order");
  545. lblNewLabel_4.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 13));
  546. lblNewLabel_4.setBounds(177, 73, 156, 14);
  547. panel_8.add(lblNewLabel_4);
  548.  
  549. JButton btnNewButton_5 = new JButton("Confirm");
  550. btnNewButton_5.setBounds(177, 207, 89, 23);
  551. panel_8.add(btnNewButton_5);
  552.  
  553. JLabel msg = new JLabel("");
  554. msg.setBounds(96, 303, 304, 14);
  555. panel_8.add(msg);
  556. panel_5.setLayout(null);
  557.  
  558. JPanel panel_9 = new JPanel();
  559. panel_9.setBounds(55, 92, 10, 10);
  560. panel.add(panel_9, "addbooks");
  561. panel_9.setLayout(null);
  562.  
  563. JButton btnNewButton_6 = new JButton("Back");
  564. btnNewButton_6.addActionListener(new ActionListener() {
  565. public void actionPerformed(ActionEvent e) {
  566. card.show(panel, "operations");
  567. }
  568. });
  569. btnNewButton_6.setBounds(0, 11, 89, 23);
  570. panel_9.add(btnNewButton_6);
  571.  
  572. threshold = new JTextField();
  573. threshold.setBounds(238, 258, 170, 20);
  574. panel_9.add(threshold);
  575. threshold.setColumns(10);
  576.  
  577. EnterISBN = new JTextField();
  578. EnterISBN.setBounds(21, 92, 170, 20);
  579. panel_9.add(EnterISBN);
  580. EnterISBN.setColumns(10);
  581.  
  582. JLabel lblNewLabel_5 = new JLabel("");
  583. lblNewLabel_5.setForeground(Color.RED);
  584. lblNewLabel_5.setBackground(Color.WHITE);
  585. lblNewLabel_5.setBounds(347, 58, 127, 14);
  586. panel_9.add(lblNewLabel_5);
  587.  
  588. title = new JTextField();
  589. title.setBounds(238, 92, 170, 20);
  590. panel_9.add(title);
  591. title.setColumns(10);
  592.  
  593. Publisher = new JTextField();
  594. Publisher.setBounds(21, 148, 170, 20);
  595. panel_9.add(Publisher);
  596. Publisher.setColumns(10);
  597.  
  598. Year = new JTextField();
  599. Year.setBounds(238, 148, 170, 20);
  600. panel_9.add(Year);
  601. Year.setColumns(10);
  602.  
  603. price = new JTextField();
  604. price.setBounds(21, 202, 170, 20);
  605. panel_9.add(price);
  606. price.setColumns(10);
  607.  
  608. category = new JTextField();
  609. category.setBounds(238, 202, 170, 20);
  610. panel_9.add(category);
  611. category.setColumns(10);
  612.  
  613. copies = new JTextField();
  614. copies.setBounds(21, 258, 170, 20);
  615. panel_9.add(copies);
  616. copies.setColumns(10);
  617.  
  618. JLabel lblNewLabel_6 = new JLabel("Insert Book");
  619. lblNewLabel_6.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 14));
  620. lblNewLabel_6.setBounds(216, 40, 176, 14);
  621. panel_9.add(lblNewLabel_6);
  622.  
  623. JLabel lblNewLabel_7 = new JLabel("Enter ISBN");
  624. lblNewLabel_7.setBounds(28, 67, 114, 14);
  625. panel_9.add(lblNewLabel_7);
  626.  
  627. JLabel lblNewLabel_8 = new JLabel("Title");
  628. lblNewLabel_8.setBounds(274, 67, 79, 14);
  629. panel_9.add(lblNewLabel_8);
  630.  
  631. JLabel lblNewLabel_9 = new JLabel("Publisher");
  632. lblNewLabel_9.setBounds(31, 121, 114, 14);
  633. panel_9.add(lblNewLabel_9);
  634.  
  635. JLabel year = new JLabel("Publication year");
  636. year.setBounds(274, 123, 147, 14);
  637. panel_9.add(year);
  638.  
  639. JLabel lblNewLabel_11 = new JLabel("Selling price");
  640. lblNewLabel_11.setBounds(31, 177, 114, 14);
  641. panel_9.add(lblNewLabel_11);
  642.  
  643. JLabel lblNewLabel_12 = new JLabel("Category");
  644. lblNewLabel_12.setBounds(274, 179, 114, 14);
  645. panel_9.add(lblNewLabel_12);
  646.  
  647. JLabel lblNewLabel_13 = new JLabel("Copies");
  648. lblNewLabel_13.setBounds(31, 233, 79, 14);
  649. panel_9.add(lblNewLabel_13);
  650.  
  651. JLabel lblNewLabel_14 = new JLabel("Threshold");
  652. lblNewLabel_14.setBounds(271, 233, 102, 14);
  653. panel_9.add(lblNewLabel_14);
  654.  
  655. JButton btnNewButton_7 = new JButton("Insert");
  656. btnNewButton_7.addActionListener(new ActionListener() {
  657. public void actionPerformed(ActionEvent e) {
  658. if (checkInsert()) {
  659. publisherData();
  660. ArrayList<String> attr = new ArrayList();
  661. ArrayList<String> value = new ArrayList();
  662. attr.add("ISBN");
  663. attr.add("Title");
  664. attr.add("Publisher");
  665. attr.add("Publication year");
  666. attr.add("Price");
  667. attr.add("Category");
  668. attr.add("Copies");
  669. attr.add("Threshold");
  670. value.add(EnterISBN.getText());
  671. value.add(title.getText());
  672. value.add(Publisher.getText());
  673. value.add(Year.getText());
  674. value.add(price.getText());
  675. value.add(category.getText());
  676. value.add(copies.getText());
  677. value.add(threshold.getText());
  678. String query = insertINtoTable("Book", attr, value);
  679.  
  680. /*
  681. * try { stt.execute(query);
  682. *
  683. * String kk[] = authorList.getText().split("\n"); String
  684. * query2 = ""; ArrayList<String> attr1; ArrayList<String>
  685. * value1; for (int i = 0; i < kk.length; i++) { attr1 = new
  686. * ArrayList(); value1 = new ArrayList(); attr1.add("ISBN");
  687. * attr1.add("Author"); value1.add(EnterISBN.getText());
  688. * value1.add(kk[i]); query2 = insertINtoTable("Authors",
  689. * attr1, value1);
  690. *
  691. * try { stt.execute(query2); } catch (SQLException e1) { //
  692. * TODO Auto-generated // catch // block //
  693. * e1.printStackTrace(); }
  694. *
  695. * System.out.println(query2); } } catch (SQLException e1) {
  696. * JOptionPane.showConfirmDialog(null, "duplicate ISBN"); //
  697. * TODO Auto-generated catch block e1.printStackTrace(); }
  698. */
  699.  
  700. }
  701.  
  702. }
  703. });
  704. btnNewButton_7.setBounds(200, 384, 89, 23);
  705. panel_9.add(btnNewButton_7);
  706. authorList = new JTextPane();
  707. authorList.setEditable(false);
  708. JScrollPane scrollPane = new JScrollPane();
  709. scrollPane.setBounds(21, 312, 429, 71);
  710. panel_9.add(scrollPane);
  711. scrollPane.setViewportView(authorList);
  712. JButton btnNewButton_9 = new JButton("insert author");
  713. btnNewButton_9.addActionListener(new ActionListener() {
  714. public void actionPerformed(ActionEvent e) {
  715. JTextField author = new JTextField();
  716. int option = JOptionPane.showConfirmDialog(null, author,
  717. "search", JOptionPane.OK_CANCEL_OPTION);
  718. if (option == JOptionPane.OK_OPTION
  719. && !author.getText().equals("")) {
  720. if (!authorList.getText().equals(""))
  721. authorList.setText(authorList.getText() + "\n"
  722. + author.getText());
  723. else
  724. authorList.setText(author.getText());
  725. }
  726.  
  727. }
  728. });
  729. btnNewButton_9.setBounds(168, 285, 121, 23);
  730. panel_9.add(btnNewButton_9);
  731.  
  732. JPanel panel_6 = new JPanel();
  733. panel_6.setBounds(0, 0, 432, 419);
  734. panel.add(panel_6, "search/update");
  735. btnLogin.addActionListener(new ActionListener() {
  736. public void actionPerformed(ActionEvent arg0) {
  737. if (validateEmpty(Username.getText())) {
  738. if (validateEmpty(password.getText())) {
  739. // search username and password in your database
  740. //if found do this
  741. card.show(panel, "operations");
  742. //else show this message
  743. JOptionPane.showMessageDialog(frame,
  744. "Invalid username or password !",
  745. "Inane warning",
  746. JOptionPane.WARNING_MESSAGE);
  747. } else {
  748. JOptionPane.showMessageDialog(frame,
  749. "Invalid Password", "Inane error",
  750. JOptionPane.ERROR_MESSAGE);
  751. }
  752. } else {
  753. JOptionPane.showMessageDialog(frame, "Invalid Username",
  754. "Inane error", JOptionPane.ERROR_MESSAGE);
  755. }
  756. }
  757. });
  758. panel_6.setLayout(null);
  759.  
  760. JLabel lblSearchBy = new JLabel("search by");
  761. lblSearchBy.setBounds(10, 39, 65, 14);
  762. panel_6.add(lblSearchBy);
  763.  
  764. JRadioButton rdbtnIsbnAndTiltle = new JRadioButton("ISBN and Tiltle");
  765. rdbtnIsbnAndTiltle.addActionListener(new ActionListener() {
  766. public void actionPerformed(ActionEvent e) {
  767.  
  768. JTextField ISBN = new JTextField();
  769. JTextField Title = new JTextField();
  770. Object[] message = { "ISBN:", ISBN, "Title:", Title };
  771.  
  772. int option = JOptionPane.showConfirmDialog(null, message,
  773. "search", JOptionPane.OK_CANCEL_OPTION);
  774. if (option == JOptionPane.OK_OPTION) {
  775.  
  776. }
  777. }
  778. });
  779. rdbtnIsbnAndTiltle.setBounds(66, 35, 115, 23);
  780. panel_6.add(rdbtnIsbnAndTiltle);
  781.  
  782. JRadioButton rdbtnCategory = new JRadioButton("Category");
  783. rdbtnCategory.addActionListener(new ActionListener() {
  784. public void actionPerformed(ActionEvent arg0) {
  785. JTextField catg = new JTextField();
  786. int option = JOptionPane.showConfirmDialog(null, catg,
  787. "search", JOptionPane.OK_CANCEL_OPTION);
  788. if (option == JOptionPane.OK_OPTION) {
  789.  
  790. }
  791. }
  792. });
  793. rdbtnCategory.setBounds(178, 35, 83, 23);
  794. panel_6.add(rdbtnCategory);
  795.  
  796. JRadioButton rdbtnAuthor = new JRadioButton("author");
  797. rdbtnAuthor.addActionListener(new ActionListener() {
  798. public void actionPerformed(ActionEvent arg0) {
  799. JTextField author = new JTextField();
  800. int option = JOptionPane.showConfirmDialog(null, author,
  801. "search", JOptionPane.OK_CANCEL_OPTION);
  802. if (option == JOptionPane.OK_OPTION) {
  803.  
  804. }
  805. }
  806. });
  807. rdbtnAuthor.setBounds(257, 35, 65, 23);
  808. panel_6.add(rdbtnAuthor);
  809.  
  810. JRadioButton rdbtnPublisher = new JRadioButton("publisher");
  811. rdbtnPublisher.addActionListener(new ActionListener() {
  812. public void actionPerformed(ActionEvent arg0) {
  813. JTextField author = new JTextField();
  814. int option = JOptionPane.showConfirmDialog(null, author,
  815. "search", JOptionPane.OK_CANCEL_OPTION);
  816. if (option == JOptionPane.OK_OPTION) {
  817.  
  818. }
  819. }
  820. });
  821. rdbtnPublisher.setBounds(324, 35, 94, 23);
  822. panel_6.add(rdbtnPublisher);
  823.  
  824. JRadioButton rdbtnCopies = new JRadioButton("copies");
  825. rdbtnCopies.addActionListener(new ActionListener() {
  826. public void actionPerformed(ActionEvent arg0) {
  827. JTextField copy = new JTextField();
  828. int option = JOptionPane.showConfirmDialog(null, copy,
  829. "search", JOptionPane.OK_CANCEL_OPTION);
  830. if (option == JOptionPane.OK_OPTION) {
  831.  
  832. }
  833. }
  834. });
  835. rdbtnCopies.setBounds(414, 35, 77, 23);
  836. panel_6.add(rdbtnCopies);
  837.  
  838. ButtonGroup group = new ButtonGroup();
  839. group.add(rdbtnIsbnAndTiltle);
  840. group.add(rdbtnCategory);
  841. group.add(rdbtnAuthor);
  842. group.add(rdbtnPublisher);
  843. group.add(rdbtnCopies);
  844.  
  845. JButton btnNewButton_41 = new JButton("Update");
  846. btnNewButton_41.addActionListener(new ActionListener() {
  847. public void actionPerformed(ActionEvent arg0) {
  848. // check search al 2wl
  849. // lma y3ml
  850. JTextField update = new JTextField();
  851. int option = JOptionPane.showConfirmDialog(null, update,
  852. "update", JOptionPane.OK_CANCEL_OPTION);
  853. if (option == JOptionPane.OK_OPTION) {
  854.  
  855. }
  856. }
  857. });
  858. btnNewButton_41.setBounds(182, 72, 94, 23);
  859. panel_6.add(btnNewButton_41);
  860.  
  861. JButton btnNewButton_8 = new JButton("back");
  862. btnNewButton_8.addActionListener(new ActionListener() {
  863. public void actionPerformed(ActionEvent arg0) {
  864. card.show(panel, "operations");
  865. }
  866. });
  867. btnNewButton_8.setBounds(0, 5, 89, 23);
  868. panel_6.add(btnNewButton_8);
  869.  
  870. JTable table = new JTable();
  871. table.setModel(new DefaultTableModel(new Object[][] {
  872. { "ISBN", "Title", "Publisher", "Year", "Price", "Categ",
  873. "#Copy", "Threshold" },
  874. { null, null, null, null, null, null, null, null },
  875. { null, null, null, null, null, null, null, null },
  876. { null, null, null, null, null, null, null, null },
  877. { null, null, null, null, null, null, null, null },
  878. { null, null, null, null, null, null, null, null },
  879. { null, null, null, null, null, null, null, null },
  880. { null, null, null, null, null, null, null, null },
  881. { null, null, null, null, null, null, null, null },
  882. { null, null, null, null, null, null, null, null },
  883. { null, null, null, null, null, null, null, null },
  884. { null, null, null, null, null, null, null, null },
  885. { null, null, null, null, null, null, null, null },
  886. { null, null, null, null, null, null, null, null },
  887. { null, null, null, null, null, null, null, null },
  888. { null, null, null, null, null, null, null, null },
  889. { null, null, null, null, null, null, null, null },
  890. { null, null, null, null, null, null, null, null },
  891. { null, null, null, null, null, null, null, null },
  892. { null, null, null, null, null, null, null, null }, },
  893. new String[] { "ISBN", "Title", "Publisher", "Year", "Price",
  894. "Categ", "#Copy", "Threshold" }) {
  895. boolean[] columnEditables = new boolean[] { false, false, false,
  896. false, false, false, false, false };
  897.  
  898. public boolean isCellEditable(int row, int column) {
  899. return columnEditables[column];
  900. }
  901. });
  902.  
  903. table.setBounds(10, 99, 512, 320);
  904.  
  905. panel_6.add(table);
  906.  
  907. }
  908. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement