fork download
  1. import javax.swing.*;
  2.  
  3. import javax.swing.event.*; // for ChangeListener of JTabbedPane.
  4.  
  5. import java.awt.event.*;
  6.  
  7. import java.awt.*;
  8.  
  9. import java.io.*;
  10.  
  11. import java.net.*;
  12.  
  13. import java.util.*;
  14.  
  15. import java.text.*;
  16.  
  17. import java.sql.*;
  18.  
  19.  
  20.  
  21. public class Server extends JFrame implements ActionListener, ChangeListener, Runnable {
  22.  
  23.  
  24.  
  25. // a list of the clients that are logged currently:
  26.  
  27. private static Vector clients = new Vector();
  28.  
  29. // number of ports to receive messages from clients:
  30.  
  31. private static int client_port;
  32.  
  33. //object to AccessServer class
  34.  
  35. AccessServer lastClient;
  36.  
  37. AccessDbase aDbase;
  38.  
  39. // keeps server's address:
  40.  
  41. private static InetAddress localHost = null;
  42.  
  43.  
  44.  
  45. // GUI's
  46.  
  47. AdminEntryLevel adminEntry;
  48.  
  49. AdminCreateAcc adminCreate;
  50.  
  51. AdminDeleteAcc adminDelete;
  52.  
  53. AdminEditAcc adminEdit;
  54.  
  55. AdminMainMenu adminMain;
  56.  
  57. AdminUpdateAcc adminUpdate;
  58.  
  59. AdminViewAccount adminViewAcct;
  60.  
  61. AdminViewReport adminView;
  62.  
  63. // AdminMainMenu adminMain;
  64.  
  65. // AdminCreateAcc adminCreate;
  66.  
  67. //server sockets for receiving connection from clients:
  68.  
  69. ServerSocket socketForClient = null;
  70.  
  71. // visual interface:
  72.  
  73. String Dattee;
  74.  
  75. // char dt = new char[50] ;
  76.  
  77. // button for termination of a client:
  78.  
  79. JButton btnTerminate = new JButton("Terminate ");
  80.  
  81. //button for administrator previlages
  82.  
  83. JButton btnAdministrator = new JButton("Administrator ");
  84.  
  85. JLabel lblRunning; // label to show how many clients are logged.
  86.  
  87. JLabel timeRunning; // label to show the updated time.
  88.  
  89. /*
  90.  
  91. JLabel lblWaiting = new JLabel("lblWaiting"); // expected connection status.
  92.  
  93. JLabel lblWaitAddress = new JLabel("lblWaitAddress"); // waiting player host.
  94.  
  95. JLabel lblWaitPort = new JLabel("lblWaitPort"); // waiting player port.
  96.  
  97. JButton btnCancelWait = new JButton("Cancel Waiting"); // button to cancel waiting.
  98.  
  99. */
  100.  
  101. long acctno,balance;
  102.  
  103. ImageIcon icon = new ImageIcon("pic.gif"); // picture for tabbedPane.
  104.  
  105. JTextArea txtInfo = new JTextArea(); // text area for information.
  106.  
  107. JTabbedPane tabbedPane = new JTabbedPane(); // tabs to select clients.
  108.  
  109. JPanel pInnerTab = new JPanel (new BorderLayout()); // panel inside the tabbedPane.
  110.  
  111. JLabel lblDateRunning ;
  112.  
  113. // thread that cares about accepting new clients:
  114.  
  115. Thread thClientAccept = null;
  116.  
  117. // thread that cares about updating the client info:
  118.  
  119. Thread thUpdateClientInfo = null;
  120.  
  121. // thread that cares about updating the date:
  122.  
  123. Thread clockThread = null;
  124.  
  125. Thread dateThread = null;
  126.  
  127. String dtString = new String("");;
  128.  
  129. String currentTime = new String("");
  130.  
  131. /**
  132.  
  133.  * Default Constructor.
  134.  
  135.  */
  136.  
  137. public Server() {
  138.  
  139. super ("The Server"); // set window caption.
  140.  
  141. // set server sockets:
  142.  
  143. try {
  144.  
  145. socketForClient = new ServerSocket(client_port);
  146.  
  147. } catch (IOException ioe) {
  148.  
  149. System.err.println("Cannot open server socket: " + ioe);
  150.  
  151. System.exit(0);
  152.  
  153. }
  154.  
  155. adminEntry= new AdminEntryLevel(this);
  156.  
  157. adminCreate = new AdminCreateAcc(this);
  158.  
  159. adminDelete = new AdminDeleteAcc(this);
  160.  
  161. adminEdit = new AdminEditAcc(this);
  162.  
  163. adminMain = new AdminMainMenu(this);
  164.  
  165. adminUpdate = new AdminUpdateAcc(this);
  166.  
  167. adminViewAcct = new AdminViewAccount(this);
  168.  
  169. setDisplay();
  170.  
  171. // adminView = new AdminViewReport(this);
  172.  
  173.  
  174.  
  175. // look & feel setup:
  176.  
  177. try {
  178.  
  179. UIManager.setLookAndFeel(
  180.  
  181. UIManager.getSystemLookAndFeelClassName() );
  182.  
  183. } catch (Exception e) {
  184.  
  185. System.err.println("Couldn't use the system "
  186.  
  187. + "look and feel: " + e);
  188.  
  189. }
  190.  
  191.  
  192.  
  193. // update look & feel for those components created in
  194.  
  195. // declaration (if required):
  196.  
  197. btnTerminate.updateUI();
  198.  
  199. btnAdministrator.updateUI();
  200.  
  201. txtInfo.updateUI();
  202.  
  203. tabbedPane.updateUI();
  204.  
  205. pInnerTab.updateUI();
  206.  
  207.  
  208.  
  209. /* The default value is: HIDE_ON_CLOSE,
  210.  
  211.   we need to ask user "Are you sure?" when there are clients logged.
  212.  
  213. */
  214.  
  215. setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
  216.  
  217. // processing window events:
  218.  
  219.  
  220. public void windowClosing(WindowEvent e) {
  221.  
  222. closeApplication();
  223.  
  224. }
  225.  
  226. };
  227.  
  228. addWindowListener(L);
  229.  
  230. // prepare the layout:
  231.  
  232. JPanel pMain = new JPanel (new BorderLayout()); // main layout.
  233.  
  234. JPanel pUpper = new JPanel (new GridLayout(1,2)); // upper layout.
  235.  
  236. JPanel pLLBL = new JPanel (new GridLayout(5,1)); // for labels at left.
  237.  
  238. JPanel pRLBL = new JPanel (new GridLayout(1,1)); // for labels at right.
  239.  
  240. lblRunning = new JLabel(" Currently logged : 0 client(s).");
  241.  
  242. lblDateRunning = new JLabel("");
  243.  
  244. pLLBL.add(new JLabel(" "));
  245.  
  246. pLLBL.add(new JLabel(" "));
  247.  
  248. pLLBL.add(lblDateRunning);
  249.  
  250. pLLBL.add(new JLabel(" Server is running on host: " + localHost));
  251.  
  252. pLLBL.add(lblRunning);
  253.  
  254. timeRunning = new JLabel(" ");
  255.  
  256. // add labels for displaying the time:
  257.  
  258. pRLBL.add(timeRunning);
  259.  
  260.  
  261.  
  262. // upper part conatins server state labels on one side,
  263.  
  264. // and current connection state on the other:
  265.  
  266.  
  267.  
  268. pUpper.add(pLLBL);
  269.  
  270. pUpper.add(pRLBL);
  271.  
  272.  
  273.  
  274. JPanel pBtns = new JPanel (new FlowLayout()); // for "Terminate" button.
  275.  
  276. btnTerminate.addActionListener(this);
  277.  
  278. pBtns.add(btnTerminate);
  279.  
  280. // shown inside the tabbedPane:
  281.  
  282. pInnerTab.add(txtInfo, BorderLayout.CENTER);
  283.  
  284. pInnerTab.add(pBtns, BorderLayout.SOUTH);
  285.  
  286. pMain.add(pUpper, BorderLayout.NORTH);
  287.  
  288. tabbedPane.addChangeListener(this);
  289.  
  290. pMain.add(tabbedPane, BorderLayout.CENTER);
  291.  
  292. JPanel adminBtns = new JPanel (new BorderLayout());
  293.  
  294. JPanel adminDisplay = new JPanel (new FlowLayout());
  295.  
  296. adminDisplay.add(new JLabel("Login as : "));
  297.  
  298. btnAdministrator.addActionListener(this);
  299.  
  300. adminDisplay.add(btnAdministrator);
  301.  
  302. adminBtns.add(adminDisplay,BorderLayout.SOUTH);
  303.  
  304. pMain.add(adminBtns,BorderLayout.SOUTH);
  305.  
  306. // set content pane:
  307.  
  308. setContentPane (pMain);
  309.  
  310.  
  311.  
  312. // it doesn't work with our JTabbedPane !!! ---> pack();
  313.  
  314. setSize(600, 500);
  315.  
  316. setBounds(100,20,600,500);
  317.  
  318. // show the window:
  319.  
  320. setVisible(true);
  321.  
  322. setResizable(false);
  323.  
  324. aDbase= new AccessDbase();
  325.  
  326. aDbase.connectionDb();
  327.  
  328. pause(2000);
  329.  
  330. adminView = new AdminViewReport(this);
  331.  
  332. // start threads:
  333.  
  334. thClientAccept = new Thread(this);
  335.  
  336. thUpdateClientInfo = new Thread(this);
  337.  
  338. clockThread = new Thread(this);
  339.  
  340. dateThread = new Thread(this);
  341.  
  342. thClientAccept.start(); // start accepting new clients.
  343.  
  344. thUpdateClientInfo.start(); // start to care about updating the info.
  345.  
  346. clockThread.start();
  347.  
  348. dateThread.start(); // start to care about the time.
  349.  
  350. }
  351.  
  352. /**
  353.  
  354.   * The run method is used by all threads.
  355.  
  356.   */
  357.  
  358. public void run( ) {
  359.  
  360. Thread thisThread = Thread.currentThread();
  361.  
  362. // thread that cares about accepting new clients:
  363.  
  364. while (thClientAccept == thisThread) {
  365.  
  366. try {
  367.  
  368. // wait for client to connect, and then validate connection:
  369.  
  370. // use temporary pointer for new connection:
  371.  
  372. Socket clientConnection = socketForClient.accept();
  373.  
  374. System.out.println("Client accepted!");
  375.  
  376. // register a new client:
  377.  
  378. addNewTab();
  379.  
  380. lastClient = new AccessServer(this);
  381.  
  382. clients.addElement(lastClient);
  383.  
  384. lblRunning.setText("Currently logged :" + clients.size() + " client(s)" );
  385.  
  386. // connect client to AccessServer:
  387.  
  388. lastClient.connectClient(clientConnection);
  389.  
  390.  
  391.  
  392. }catch (Exception e) {
  393.  
  394. if (thClientAccept != null) // not shutting down yet?
  395.  
  396. System.err.println("Accept client -> " + e);
  397.  
  398. }
  399.  
  400. }
  401.  
  402.  
  403.  
  404. // thread that cares about updating the client info:
  405.  
  406. // automatic update of info for selected client:
  407.  
  408. while (thUpdateClientInfo == thisThread) {
  409.  
  410. if (clients.size() > 0) // no clients?
  411.  
  412. showClientData();
  413.  
  414. thUpdateClientInfo.yield(); // this thread isn't so important, think of others.
  415.  
  416. pause(1200); // update every 1.2 of a second.
  417.  
  418. }
  419.  
  420. while (clockThread == thisThread) {
  421.  
  422. iterateTime();
  423.  
  424. try {
  425.  
  426. Thread.sleep(1000);
  427.  
  428.  
  429.  
  430. } catch (InterruptedException e) {
  431.  
  432. System.err.println("clock thread -> " + e);
  433.  
  434. // the VM doesn't want us to sleep anymore,
  435.  
  436. // so get back to work
  437.  
  438. }
  439.  
  440. }
  441.  
  442. while (dateThread == thisThread) {
  443.  
  444. iterateDate();
  445.  
  446. try {
  447.  
  448. Thread.sleep(1000);
  449.  
  450.  
  451.  
  452. } catch (InterruptedException e) {
  453.  
  454. System.err.println("clock thread -> " + e);
  455.  
  456. // the VM doesn't want us to sleep anymore,
  457.  
  458. // so get back to work
  459.  
  460. }
  461.  
  462. }
  463.  
  464. } // end of run().
  465.  
  466.  
  467.  
  468. private void iterateTime() {
  469.  
  470. // get the time and convert it to a date
  471.  
  472. Calendar cal = Calendar.getInstance();
  473.  
  474. java.util.Date date = cal.getTime();
  475.  
  476. //System.out.println("Display time : " + date.toString());
  477.  
  478. //char dts[] = date.toString().toCharArray() ;
  479.  
  480. // Dattee ;
  481.  
  482. //System.out.println("Display time : " + dts);
  483.  
  484. //Dattee.valueOf(dts,12,9);
  485.  
  486. //System.out.println("Display time : " + Dattee);
  487.  
  488. // format it and display it
  489.  
  490. DateFormat dateFormatter = DateFormat.getTimeInstance();
  491.  
  492. SimpleDateFormat dateFormatterH = new SimpleDateFormat("HH:mm:ss");
  493.  
  494. currentTime = dateFormatterH.format(date);
  495.  
  496. timeRunning.setText(" Time : " + dateFormatter.format(date));
  497.  
  498. }
  499.  
  500. private void iterateDate() {
  501.  
  502. // get the time and convert it to a date
  503.  
  504. // format it and display it
  505.  
  506. Calendar cal = Calendar.getInstance();
  507.  
  508. java.util.Date date = cal.getTime();
  509.  
  510. SimpleDateFormat dt = new SimpleDateFormat ("dd MMM yyyy '(' EE ')' ");
  511.  
  512. //java.util.Date currTime = new java.util.Date();
  513.  
  514. dtString = dt.format(date);
  515.  
  516. lblDateRunning.setText(" Date : " + dtString);
  517.  
  518. }
  519.  
  520. /**
  521.  
  522.   * Makes current thread to pause.
  523.  
  524.   *
  525.  
  526.   * @param time miliseconds to sleep.
  527.  
  528.   */
  529.  
  530. public void pause(int time) {
  531.  
  532. try {
  533.  
  534. Thread.sleep(time);
  535.  
  536. }
  537.  
  538. catch (InterruptedException e) {
  539.  
  540. System.err.println(e.getMessage());
  541.  
  542. }
  543.  
  544. }
  545.  
  546. /**
  547.  
  548.   * Processes clicks on buttons.
  549.  
  550.   *
  551.  
  552.   * @param e the ActionEvent object.
  553.  
  554.   */
  555.  
  556. public void actionPerformed(ActionEvent e){
  557.  
  558. // JButton tempBtn = (JButton)e.getSource();
  559.  
  560. JButton src = (JButton)e.getSource();
  561.  
  562. if (src==btnTerminate) { // terminate the client
  563.  
  564. try {
  565.  
  566. AccessServer t; // temporary pointer.
  567.  
  568. t = (AccessServer) clients.get(tabbedPane.getSelectedIndex());
  569.  
  570. t.sendToClient("TERMINATED");
  571.  
  572. removeClient(t);
  573.  
  574. }
  575.  
  576.  
  577. txtInfo.setText( "No client with index: " + tabbedPane.getSelectedIndex());
  578.  
  579. }
  580.  
  581. }
  582.  
  583. else if (src == btnAdministrator){
  584.  
  585. btnAdministrator.setEnabled(false);
  586.  
  587. adminEntry.setClear();
  588.  
  589. adminEntry.setVisible(true);
  590.  
  591.  
  592.  
  593. }
  594.  
  595. else if(src == adminEntry.logIn)
  596.  
  597. {
  598.  
  599. String s=new String(adminEntry.pField.getPassword());
  600.  
  601. if((adminEntry.txtID.getText().equalsIgnoreCase("Administrator"))&&
  602.  
  603. (s.equals("Admin") ))
  604.  
  605. {
  606.  
  607. System.out.println("AdminEntryLevel: Logged In");
  608.  
  609. adminEntry.setVisible(false);
  610.  
  611. adminMain.setClear();
  612.  
  613. adminMain.setVisible(true);
  614.  
  615. }
  616.  
  617. else {
  618.  
  619. System.out.println("AdminEntryLevel:Log In Failed");
  620.  
  621. JOptionPane.showMessageDialog(adminEntry,
  622.  
  623. "Log In Failed",
  624.  
  625. "Admin Entry Level",
  626.  
  627. JOptionPane.ERROR_MESSAGE
  628.  
  629. );
  630.  
  631. }
  632.  
  633. }
  634.  
  635. else if(src==adminEntry.cancelLogIn)
  636.  
  637. {
  638.  
  639. adminEntry.setVisible(false);
  640.  
  641. btnAdministrator.setEnabled(true);
  642.  
  643. }
  644.  
  645. else if(src==adminMain.btnCreate)
  646.  
  647. {
  648.  
  649. adminMain.setVisible(false);
  650.  
  651. adminCreate.setClear();
  652.  
  653. adminCreate.setVisible(true);
  654.  
  655. System.out.println("Admin Create Acc");
  656.  
  657. }
  658.  
  659. else if(src==adminMain.btnDelete)
  660.  
  661. {
  662.  
  663. adminMain.setVisible(false);
  664.  
  665. adminDelete.setClear();
  666.  
  667. adminDelete.setVisible(true);
  668.  
  669. System.out.println("Admin Delete Acc");
  670.  
  671. }
  672.  
  673. else if(src==adminMain.btnEdit )
  674.  
  675. {
  676.  
  677. adminMain.setVisible(false);
  678.  
  679. adminEdit.setClear();
  680.  
  681. adminEdit.setVisible(true);
  682.  
  683. System.out.println("Admin Edit Acc");
  684.  
  685. }
  686.  
  687. else if(src==adminMain.btnViewAcct)
  688.  
  689. {
  690.  
  691. adminMain.setVisible(false);
  692.  
  693. adminViewAcct.setClear();
  694.  
  695. adminViewAcct.setVisible(true);
  696.  
  697. }
  698.  
  699. else if(src == adminMain.btnViewReport)
  700.  
  701. {
  702.  
  703. adminMain.setVisible(false);
  704.  
  705. adminView.setActionCmd();
  706.  
  707.  
  708.  
  709. //adminView.setMaximizedBounds(new Rectangle(0,0,Integer.MAX_VALUE,Integer.MAX_VALUE));
  710.  
  711. adminView.setVisible(true);
  712.  
  713. }
  714.  
  715. else if(src==adminMain.btnLogout)
  716.  
  717. {
  718.  
  719. adminEntry.setClear();
  720.  
  721. adminMain.setVisible(false);
  722.  
  723. adminEntry.setVisible(true);
  724.  
  725. }
  726.  
  727. else if(src==adminCreate.btnSubmit)
  728.  
  729. {
  730.  
  731. try { if((adminCreate.fields[1].getText().trim().equals(""))||(adminCreate.fields[2].getText().trim().equals(""))||(adminCreate.fields[3].getText().trim().equals(""))||(adminCreate.fields[4].getText().trim().equals(""))||(adminCreate.fields[5].getText().trim().equals(""))||(adminCreate.fields[6].getText().trim().equals(""))||(adminCreate.fields[7].getText().trim().equals("")))
  732.  
  733. {
  734.  
  735. JOptionPane.showMessageDialog(adminCreate,
  736.  
  737. "Fields are incomplete.\n Status :Error" ,
  738.  
  739. "Admin Create Account",
  740.  
  741. JOptionPane.ERROR_MESSAGE
  742.  
  743. );
  744.  
  745. }
  746.  
  747. else
  748.  
  749. {
  750.  
  751. aDbase.stmt.executeUpdate("INSERT INTO ClientInfo" + " VALUES( " + adminCreate.fields[0].getText() + ",'" + adminCreate.fields[1].getText() + "','" + adminCreate.fields[2].getText() + "','" + adminCreate.fields[3].getText() + "','" + adminCreate.fields[4].getText() + "','" + adminCreate.fields[5].getText() + "','" + adminCreate.fields[6].getText() + "'," + "'" + adminCreate.fields[7].getText() + "',True," + adminCreate.fields[8].getText() + " )" );
  752.  
  753. aDbase.stmt.executeUpdate("INSERT INTO ClientAccStatus" + " VALUES( " + adminCreate.fields[0].getText() + ",'" + adminCreate.fields[1].getText() + "',500, No)");
  754.  
  755. System.out.println("Dbase Created");
  756.  
  757. JOptionPane.showMessageDialog(adminCreate,
  758.  
  759. "Account No : " + adminCreate.fields[0].getText() +"\nName : " + adminCreate.fields[1].getText() + "\nPassword : " + adminCreate.fields[2].getText() + "\nPin : " + adminCreate.fields[8].getText() + "\nStatus : Account Created" ,
  760.  
  761. "Admin Create Account",
  762.  
  763. JOptionPane.INFORMATION_MESSAGE
  764.  
  765. );
  766.  
  767. adminCreate.setVisible(false);
  768.  
  769. adminMain.setVisible(true);
  770.  
  771. }
  772.  
  773. }
  774.  
  775. catch(SQLException sqle)
  776.  
  777. {
  778.  
  779. System.out.println("Error:"+sqle);
  780.  
  781. }
  782.  
  783. }
  784.  
  785. else if(src==adminCreate.btnCancel)
  786.  
  787. {
  788.  
  789. adminCreate.setVisible(false);
  790.  
  791. adminMain.setVisible(true);
  792.  
  793. }
  794.  
  795. else if(src==adminDelete.btnDelete)
  796.  
  797. {
  798.  
  799. try{
  800.  
  801. String s = adminDelete.txtAcctNo.getText();
  802.  
  803.  
  804.  
  805. String updateQuery = "UPDATE ClientInfo SET Validity = False WHERE AccountNo = " + s ;
  806.  
  807. aDbase.stmt.executeUpdate(updateQuery);
  808.  
  809. aDbase.uprs = aDbase.stmt.executeQuery("SELECT Name FROM ClientInfo WHERE AccountNo = " + s );
  810.  
  811. aDbase.uprs.next();
  812.  
  813. String name = aDbase.uprs.getString(1);
  814.  
  815. JOptionPane.showMessageDialog(adminDelete,
  816.  
  817. "Account No : " + s +"\nName : " + name + " \nStatus : Deleted" ,
  818.  
  819. "Admin Delete Account",
  820.  
  821. JOptionPane.INFORMATION_MESSAGE
  822.  
  823. );
  824.  
  825. System.out.println("Dbase Deleted");
  826.  
  827. adminDelete.setVisible(false);
  828.  
  829. adminMain.setVisible(true);
  830.  
  831. }
  832.  
  833. catch(SQLException sqle)
  834.  
  835. {
  836.  
  837. JOptionPane.showMessageDialog(adminDelete,
  838.  
  839. "Invalid Account Number",
  840.  
  841. "Admin Delete Account",
  842.  
  843. JOptionPane.ERROR_MESSAGE
  844.  
  845. );
  846.  
  847. System.out.println("Error:"+sqle);
  848.  
  849. }
  850.  
  851. }
  852.  
  853. else if(src==adminDelete.btnCancel)
  854.  
  855. {
  856.  
  857. adminDelete.setVisible(false);
  858.  
  859. adminMain.setVisible(true);
  860.  
  861. }
  862.  
  863. else if(src==adminEdit.btnEdit)
  864.  
  865. {
  866.  
  867. try {
  868.  
  869. String s = adminEdit.txtAcctNo.getText();
  870.  
  871. aDbase.uprs = aDbase.stmt.executeQuery("SELECT * FROM ClientInfo WHERE AccountNo = " + s );
  872.  
  873.  
  874.  
  875. aDbase.uprs.next();
  876.  
  877. adminUpdate.fields[0].setText(s);
  878.  
  879. adminUpdate.fields[0].setEditable(false);
  880.  
  881. adminUpdate.fields[1].setText(aDbase.uprs.getString(2));
  882.  
  883. adminUpdate.fields[2].setText(aDbase.uprs.getString(3));
  884.  
  885. adminUpdate.fields[3].setText(aDbase.uprs.getString(4));
  886.  
  887. adminUpdate.fields[4].setText(aDbase.uprs.getString(5));
  888.  
  889. adminUpdate.fields[5].setText(aDbase.uprs.getString(6));
  890.  
  891. adminUpdate.fields[6].setText(aDbase.uprs.getString(7));
  892.  
  893. adminUpdate.fields[7].setText(aDbase.uprs.getString(8));
  894.  
  895. adminEdit.setVisible(false);
  896.  
  897. adminUpdate.setVisible(true);
  898.  
  899. }
  900.  
  901. catch(SQLException sqle)
  902.  
  903. {
  904.  
  905. JOptionPane.showMessageDialog(adminEdit,
  906.  
  907. "Invalid Account Number",
  908.  
  909. "Admin Edit Account",
  910.  
  911. JOptionPane.ERROR_MESSAGE
  912.  
  913. );
  914.  
  915. }
  916.  
  917. }
  918.  
  919. else if(src==adminEdit.btnCancel)
  920.  
  921. {
  922.  
  923. adminEdit.setVisible(false);
  924.  
  925. adminMain.setVisible(true);
  926.  
  927. }
  928.  
  929. else if(src==adminUpdate.btnUpdate)
  930.  
  931. {
  932.  
  933. try {
  934.  
  935. String s= adminEdit.txtAcctNo.getText();
  936.  
  937.  
  938.  
  939. String updateQuery = "UPDATE ClientInfo SET Name = '" + adminUpdate.fields[1].getText() + "', Password = '" + adminUpdate.fields[2].getText() + "', AddressLine1 = '" + adminUpdate.fields[3].getText() + "', AddressLine2 = '" + adminUpdate.fields[4].getText() + "',City = '" + adminUpdate.fields[5].getText() + "', State = '" + adminUpdate.fields[6].getText() + "', Phone = '" + adminUpdate.fields[7].getText() + "', Validity = True WHERE AccountNo = " + s ;
  940.  
  941.  
  942.  
  943. aDbase.stmt.executeUpdate(updateQuery);
  944.  
  945. aDbase.uprs = aDbase.stmt.executeQuery("SELECT Name,Password FROM ClientInfo WHERE AccountNo = " + s );
  946.  
  947. aDbase.uprs.next();
  948.  
  949.  
  950.  
  951. String name = aDbase.uprs.getString(1);
  952.  
  953. String pword = aDbase.uprs.getString(2);
  954.  
  955. JOptionPane.showMessageDialog(adminUpdate,
  956.  
  957. "Account No : " + s +"\nName : " + name + "\nPassword : " + pword + "\nStatus : Updated" ,
  958.  
  959. "Admin Update Account",
  960.  
  961. JOptionPane.INFORMATION_MESSAGE
  962.  
  963. );
  964.  
  965. adminUpdate.setVisible(false);
  966.  
  967. adminMain.setVisible(true);
  968.  
  969. }
  970.  
  971. catch(SQLException sqle)
  972.  
  973. {
  974.  
  975. System.out.println("Error" + sqle);
  976.  
  977. }
  978.  
  979. }
  980.  
  981. else if(src==adminUpdate.btnCancel)
  982.  
  983. {
  984.  
  985. adminUpdate.setVisible(false);
  986.  
  987. adminMain.setVisible(true);
  988.  
  989. }
  990.  
  991. else if(src==adminViewAcct.btnDbBegin)
  992.  
  993. {
  994.  
  995. try{
  996.  
  997. String query1 = " SELECT * FROM ClientInfo ";
  998.  
  999. String query2 = " SELECT Balance FROM ClientAccStatus ";
  1000.  
  1001. aDbase.tmpuprs = aDbase.tmpStmt.executeQuery(query1);
  1002.  
  1003. aDbase.tmpuprs.first();
  1004.  
  1005. acctno = aDbase.uprs.getLong(1);
  1006.  
  1007. String AcNo = Long.toString(acctno);
  1008.  
  1009. boolean val = aDbase.uprs.getBoolean(9);
  1010.  
  1011. String valid;
  1012.  
  1013. if (val)
  1014.  
  1015. valid = "Yes";
  1016.  
  1017. else
  1018.  
  1019. valid = "No";
  1020.  
  1021.  
  1022.  
  1023. adminViewAcct.fields[0].setText(" " + AcNo);
  1024.  
  1025. adminViewAcct.fields[1].setText(" " + aDbase.uprs.getString(2));
  1026.  
  1027. adminViewAcct.fields[3].setText(" " + valid);
  1028.  
  1029. adminViewAcct.fields[4].setText(" " + aDbase.uprs.getString(4));
  1030.  
  1031. adminViewAcct.fields[5].setText(" " + aDbase.uprs.getString(5));
  1032.  
  1033. adminViewAcct.fields[6].setText(" " + aDbase.uprs.getString(6));
  1034.  
  1035. adminViewAcct.fields[7].setText(" " + aDbase.uprs.getString(7));
  1036.  
  1037. adminViewAcct.fields[8].setText(" " + aDbase.uprs.getString(8));
  1038.  
  1039. balance = aDbase.tmpuprs.getLong(1);
  1040.  
  1041. String Bal = Long.toString(balance);
  1042.  
  1043. adminViewAcct.fields[2].setText(" Rs " + Bal + "\\-");
  1044.  
  1045. System.out.println("Admin View Acct |<");
  1046.  
  1047. }
  1048.  
  1049. catch(SQLException sqle)
  1050.  
  1051. {
  1052.  
  1053. System.out.println("Error :" + sqle);
  1054.  
  1055. }
  1056.  
  1057. }
  1058.  
  1059. else if(src==adminViewAcct.btnDbBwd)
  1060.  
  1061. {
  1062.  
  1063. //long acct = Long.parseLong(adminViewAcct.fields[0].getText()) ;
  1064.  
  1065.  
  1066.  
  1067. try{
  1068.  
  1069. if(!aDbase.uprs.isFirst())
  1070.  
  1071. {
  1072.  
  1073. aDbase.uprs.previous();
  1074.  
  1075. aDbase.tmpuprs.previous();
  1076.  
  1077. acctno = aDbase.uprs.getLong(1);
  1078.  
  1079. String AcNo = Long.toString(acctno);
  1080.  
  1081.  
  1082.  
  1083. boolean val = aDbase.uprs.getBoolean(9);
  1084.  
  1085. String valid;
  1086.  
  1087. if (val)
  1088.  
  1089. valid = "Yes";
  1090.  
  1091. else
  1092.  
  1093. valid = "No";
  1094.  
  1095.  
  1096.  
  1097. adminViewAcct.fields[0].setText(" " + AcNo);
  1098.  
  1099. adminViewAcct.fields[1].setText(" " + aDbase.uprs.getString(2));
  1100.  
  1101.  
  1102.  
  1103. adminViewAcct.fields[3].setText(" " + valid);
  1104.  
  1105. adminViewAcct.fields[4].setText(" " + aDbase.uprs.getString(4));
  1106.  
  1107. adminViewAcct.fields[5].setText(" " + aDbase.uprs.getString(5));
  1108.  
  1109. adminViewAcct.fields[6].setText(" " + aDbase.uprs.getString(6));
  1110.  
  1111. adminViewAcct.fields[7].setText(" " + aDbase.uprs.getString(7));
  1112.  
  1113. adminViewAcct.fields[8].setText(" " + aDbase.uprs.getString(8));
  1114.  
  1115. balance = aDbase.tmpuprs.getLong(1);
  1116.  
  1117. String Bal = Long.toString(balance);
  1118.  
  1119. adminViewAcct.fields[2].setText(" Rs " + Bal + "\\-");
  1120.  
  1121. System.out.println("Admin View Acct <<");
  1122.  
  1123. }
  1124.  
  1125. }
  1126.  
  1127. catch(SQLException sqle)
  1128.  
  1129. {
  1130.  
  1131. System.out.println("Error :" + sqle);
  1132.  
  1133. }
  1134.  
  1135. }
  1136.  
  1137. else if(src==adminViewAcct.btnDbFwd)
  1138.  
  1139. {
  1140.  
  1141. try{
  1142.  
  1143. if(!aDbase.uprs.isLast())
  1144.  
  1145. {
  1146.  
  1147. //acct = acct -1 ;
  1148.  
  1149. //String Actno = Long.toString(acct) ;
  1150.  
  1151. //String query1 = " SELECT * FROM ClientInfo WHERE AccountNo = " + Actno ;
  1152.  
  1153. //String query2 = " SELECT Balance FROM ClientAccStatus WHERE AccountNo = " + Actno;
  1154.  
  1155. //aDbase.uprs = aDbase.tmpStmt.executeQuery(query1);
  1156.  
  1157.  
  1158.  
  1159. aDbase.uprs.next();
  1160.  
  1161. aDbase.tmpuprs.next();
  1162.  
  1163. acctno = aDbase.uprs.getLong(1);
  1164.  
  1165. String AcNo = Long.toString(acctno);
  1166.  
  1167.  
  1168.  
  1169. boolean val = aDbase.uprs.getBoolean(9);
  1170.  
  1171. String valid;
  1172.  
  1173. if (val)
  1174.  
  1175. valid = "Yes";
  1176.  
  1177. else
  1178.  
  1179. valid = "No";
  1180.  
  1181. adminViewAcct.fields[0].setText(" " + AcNo);
  1182.  
  1183. adminViewAcct.fields[1].setText(" " + aDbase.uprs.getString(2));
  1184.  
  1185. adminViewAcct.fields[3].setText(" " + valid);
  1186.  
  1187. adminViewAcct.fields[4].setText(" " + aDbase.uprs.getString(4));
  1188.  
  1189. adminViewAcct.fields[5].setText(" " + aDbase.uprs.getString(5));
  1190.  
  1191. adminViewAcct.fields[6].setText(" " + aDbase.uprs.getString(6));
  1192.  
  1193. adminViewAcct.fields[7].setText(" " + aDbase.uprs.getString(7));
  1194.  
  1195. adminViewAcct.fields[8].setText(" " + aDbase.uprs.getString(8));
  1196.  
  1197. balance = aDbase.tmpuprs.getLong(1);
  1198.  
  1199. String Bal = Long.toString(balance);
  1200.  
  1201. adminViewAcct.fields[2].setText(" Rs " + Bal + "\\-");
  1202.  
  1203. System.out.println("Admin View Acct >>");
  1204.  
  1205. }
  1206.  
  1207. }
  1208.  
  1209. catch(SQLException sqle)
  1210.  
  1211. {
  1212.  
  1213. System.out.println("Error :" + sqle);
  1214.  
  1215. }
  1216.  
  1217. }
  1218.  
  1219. }
  1220.  
  1221. /**
  1222.  
  1223.   * processes events for the JTabbedPane.
  1224.  
  1225.   *
  1226.  
  1227.   * @param e the ChangeEvent object.
  1228.  
  1229.   */
  1230.  
  1231. public void stateChanged(ChangeEvent e) {
  1232.  
  1233. Object src=e.getSource();
  1234.  
  1235.  
  1236.  
  1237. if (src == tabbedPane) { // click on a tab
  1238.  
  1239. showClientData();
  1240.  
  1241. }
  1242.  
  1243. }
  1244.  
  1245. /**
  1246.  
  1247.   * Adds new tab to tabbedPane,
  1248.  
  1249.   * the same component is displayed for all tabs,
  1250.  
  1251.   * so if there are not tabs the pInnerTab is added.
  1252.  
  1253.   */
  1254.  
  1255. private void addNewTab() {
  1256.  
  1257. try {
  1258.  
  1259. int curTabs = tabbedPane.getTabCount();
  1260.  
  1261. if (curTabs == 0) { // no tabs in tabbedPane?
  1262.  
  1263. tabbedPane.addTab("Client 1", icon, pInnerTab);
  1264.  
  1265. tabbedPane.setSelectedIndex(0);
  1266.  
  1267. }
  1268.  
  1269. else {
  1270.  
  1271. // add empty tab, component from Tab#0 will be used:
  1272.  
  1273. tabbedPane.addTab("Client " + (curTabs+1), icon, null);
  1274.  
  1275. // activate last tab (newly added):
  1276.  
  1277. tabbedPane.setSelectedIndex(curTabs);
  1278.  
  1279. }
  1280.  
  1281. }
  1282.  
  1283. catch (Exception e) {
  1284.  
  1285. System.err.println("addNewTab() -> " + e);
  1286.  
  1287. }
  1288.  
  1289. }
  1290.  
  1291. /**
  1292.  
  1293.   * Removes the last tab from tabbedPane,
  1294.  
  1295.   * (used when game is terminated).
  1296.  
  1297.   */
  1298.  
  1299. private void removeLastTab() {
  1300.  
  1301. try {
  1302.  
  1303. int curTabs = tabbedPane.getTabCount();
  1304.  
  1305. tabbedPane.removeTabAt(curTabs-1);//check for the correction..PENDING......
  1306.  
  1307. // activate first tab (if any):
  1308.  
  1309. if (curTabs > 1)
  1310.  
  1311. tabbedPane.setSelectedIndex(0);
  1312.  
  1313. }
  1314.  
  1315. catch (Exception e) {
  1316.  
  1317. System.err.println("removeLastTab() -> " + e);
  1318.  
  1319. }
  1320.  
  1321. }
  1322.  
  1323. /**
  1324.  
  1325.   * Updates the text box that shows the information for
  1326.  
  1327.   * currectly selected client (by the tabbedPane).
  1328.  
  1329.   */
  1330.  
  1331. private void showClientData() {
  1332.  
  1333. try {
  1334.  
  1335. AccessServer temp; // temporary pointer.
  1336.  
  1337. temp = (AccessServer) clients.get(tabbedPane.getSelectedIndex());
  1338.  
  1339. String sInfo = temp.getInfo();
  1340.  
  1341. if (!sInfo.equals( txtInfo.getText() )) // update text only when required.
  1342.  
  1343. txtInfo.setText(sInfo);
  1344.  
  1345. }
  1346.  
  1347.  
  1348. txtInfo.setText( "No client with index: " + tabbedPane.getSelectedIndex());
  1349.  
  1350. }
  1351.  
  1352. }
  1353.  
  1354. /**
  1355.  
  1356.   * Main function, from where Server starts.
  1357.  
  1358.   */
  1359.  
  1360. public static void main(String args[]) {
  1361.  
  1362.  
  1363.  
  1364. // validate parameter count:
  1365.  
  1366. if (args.length!=1) {
  1367.  
  1368. System.err.println("Wrong parameters! Usage:");
  1369.  
  1370. System.err.println("java Server <client_port> ");
  1371.  
  1372. System.exit(1);
  1373.  
  1374. }
  1375.  
  1376. // process parameters:
  1377.  
  1378. try {
  1379.  
  1380. client_port = Integer.parseInt(args[0]);
  1381.  
  1382. }
  1383.  
  1384. catch (NumberFormatException e) {
  1385.  
  1386. System.err.println("Wrong number for a port -> " + e);
  1387.  
  1388. System.exit(1);
  1389.  
  1390. }
  1391.  
  1392. // get address of the server:
  1393.  
  1394. try {
  1395.  
  1396. localHost = InetAddress.getLocalHost();
  1397.  
  1398. } catch (UnknownHostException e) {
  1399.  
  1400. System.out.println("Unknown host - probably localhost with no IP!");
  1401.  
  1402. // no exit, since can work on "localhost" without internet.
  1403.  
  1404. }
  1405.  
  1406. // print out the info (the same info is also shown on the server's
  1407.  
  1408. // GUI window).
  1409.  
  1410. System.out.println("Server is running on host: " + localHost);
  1411.  
  1412. System.out.println("Waiting clients on port: " + client_port);
  1413.  
  1414. // create & start server GUI engine:
  1415.  
  1416. new Server();
  1417.  
  1418. } // end of main().
  1419.  
  1420. /**
  1421.  
  1422.   * Closes the server, cares about closing all sockets,
  1423.  
  1424.   * and informing the clients are running
  1425.  
  1426.   * currenlty about the shutdown, and terminating clients.
  1427.  
  1428.   */
  1429.  
  1430. private void closeApplication() {
  1431.  
  1432.  
  1433.  
  1434. // ask user if he/she is sure to shut down the server when
  1435.  
  1436. // there are clients running:
  1437.  
  1438. if (clients.size() > 0) {
  1439.  
  1440. int result;
  1441.  
  1442. result = JOptionPane.showConfirmDialog(this,
  1443.  
  1444. "Are you sure you want to shut down the SERVER?\n" +
  1445.  
  1446. "All clients will be terminated!",
  1447.  
  1448. "Close anyway?",
  1449.  
  1450. JOptionPane.YES_NO_OPTION,
  1451.  
  1452. JOptionPane.WARNING_MESSAGE);
  1453.  
  1454. if (result != 0) // no, cancel.
  1455.  
  1456. return;
  1457.  
  1458. // otherwise - yes, close.
  1459.  
  1460. // send termination message to all clients:
  1461.  
  1462. for (int i=clients.size()-1; i>=0; i--) {
  1463.  
  1464. AccessServer temp;
  1465.  
  1466. temp = (AccessServer) clients.get(i);
  1467.  
  1468. temp.sendToClient("TERMINATED");
  1469.  
  1470. removeClient(temp);
  1471.  
  1472. }
  1473.  
  1474. }
  1475.  
  1476.  
  1477.  
  1478. // stop the server's threads:
  1479.  
  1480. thClientAccept = null;
  1481.  
  1482. // close sockets:
  1483.  
  1484. try {
  1485.  
  1486. socketForClient.close();
  1487.  
  1488. }catch (IOException e) {
  1489.  
  1490. System.err.println("On close -> " + e);
  1491.  
  1492. }
  1493.  
  1494. // close everything:
  1495.  
  1496. System.exit(0);
  1497.  
  1498. }
  1499.  
  1500. public void setDisplay(){
  1501.  
  1502. adminEntry.setVisible(false);
  1503.  
  1504. adminCreate.setVisible(false);
  1505.  
  1506. adminDelete.setVisible(false);
  1507.  
  1508. adminEdit.setVisible(false);
  1509.  
  1510. adminMain.setVisible(false);
  1511.  
  1512. adminUpdate.setVisible(false);
  1513.  
  1514. adminViewAcct.setVisible(false);
  1515.  
  1516. //adminView.setVisible(false);
  1517.  
  1518. }
  1519.  
  1520. /**
  1521.  
  1522.   * Terminates the client.
  1523.  
  1524.   *
  1525.  
  1526.   * @param clientToDelete the pointer to client to be deleted.
  1527.  
  1528.   */
  1529.  
  1530. public void removeClient(AccessServer clientToDelete) {
  1531.  
  1532. if (clients.contains(clientToDelete)) { // check if not removed already.
  1533.  
  1534. // close sockets, streams, stop threads:
  1535.  
  1536. pause(1500);
  1537.  
  1538. clientToDelete.closeEverything();
  1539.  
  1540. clients.remove(clientToDelete); // remove from vector.
  1541.  
  1542. lblRunning.setText("Currently logged: " + clients.size() + " client(s).");
  1543.  
  1544. removeLastTab();
  1545.  
  1546. }
  1547.  
  1548. }
  1549.  
  1550. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:21: error: class Server is public, should be declared in a file named Server.java
public class Server extends JFrame implements ActionListener, ChangeListener, Runnable { 
       ^
Main.java:35: error: cannot find symbol
AccessServer lastClient; 
^
  symbol:   class AccessServer
  location: class Server
Main.java:37: error: cannot find symbol
AccessDbase aDbase; 
^
  symbol:   class AccessDbase
  location: class Server
Main.java:47: error: cannot find symbol
  AdminEntryLevel adminEntry; 
  ^
  symbol:   class AdminEntryLevel
  location: class Server
Main.java:49: error: cannot find symbol
  AdminCreateAcc adminCreate; 
  ^
  symbol:   class AdminCreateAcc
  location: class Server
Main.java:51: error: cannot find symbol
  AdminDeleteAcc adminDelete; 
  ^
  symbol:   class AdminDeleteAcc
  location: class Server
Main.java:53: error: cannot find symbol
  AdminEditAcc adminEdit; 
  ^
  symbol:   class AdminEditAcc
  location: class Server
Main.java:55: error: cannot find symbol
  AdminMainMenu adminMain; 
  ^
  symbol:   class AdminMainMenu
  location: class Server
Main.java:57: error: cannot find symbol
  AdminUpdateAcc adminUpdate; 
  ^
  symbol:   class AdminUpdateAcc
  location: class Server
Main.java:59: error: cannot find symbol
  AdminViewAccount adminViewAcct; 
  ^
  symbol:   class AdminViewAccount
  location: class Server
Main.java:61: error: cannot find symbol
  AdminViewReport adminView; 
  ^
  symbol:   class AdminViewReport
  location: class Server
Main.java:1533: error: cannot find symbol
    public void removeClient(AccessServer clientToDelete) { 
                             ^
  symbol:   class AccessServer
  location: class Server
Main.java:155: error: cannot find symbol
        adminEntry=  new  AdminEntryLevel(this); 
                          ^
  symbol:   class AdminEntryLevel
  location: class Server
Main.java:157: error: cannot find symbol
        adminCreate = new AdminCreateAcc(this); 
                          ^
  symbol:   class AdminCreateAcc
  location: class Server
Main.java:159: error: cannot find symbol
        adminDelete = new AdminDeleteAcc(this); 
                          ^
  symbol:   class AdminDeleteAcc
  location: class Server
Main.java:161: error: cannot find symbol
        adminEdit = new AdminEditAcc(this); 
                        ^
  symbol:   class AdminEditAcc
  location: class Server
Main.java:163: error: cannot find symbol
        adminMain = new AdminMainMenu(this); 
                        ^
  symbol:   class AdminMainMenu
  location: class Server
Main.java:165: error: cannot find symbol
        adminUpdate = new AdminUpdateAcc(this); 
                          ^
  symbol:   class AdminUpdateAcc
  location: class Server
Main.java:167: error: cannot find symbol
        adminViewAcct = new AdminViewAccount(this); 
                            ^
  symbol:   class AdminViewAccount
  location: class Server
Main.java:325: error: cannot find symbol
         aDbase= new AccessDbase(); 
                     ^
  symbol:   class AccessDbase
  location: class Server
Main.java:331: error: cannot find symbol
        adminView = new AdminViewReport(this); 
                        ^
  symbol:   class AdminViewReport
  location: class Server
Main.java:381: error: cannot find symbol
                  lastClient = new AccessServer(this); 
                                   ^
  symbol:   class AccessServer
  location: class Server
Main.java:567: error: cannot find symbol
                AccessServer t;      // temporary pointer. 
                ^
  symbol:   class AccessServer
  location: class Server
Main.java:569: error: cannot find symbol
                t = (AccessServer) clients.get(tabbedPane.getSelectedIndex()); 
                     ^
  symbol:   class AccessServer
  location: class Server
Main.java:1337: error: cannot find symbol
                AccessServer temp;  // temporary pointer. 
                ^
  symbol:   class AccessServer
  location: class Server
Main.java:1339: error: cannot find symbol
                temp = (AccessServer) clients.get(tabbedPane.getSelectedIndex()); 
                        ^
  symbol:   class AccessServer
  location: class Server
Main.java:1467: error: cannot find symbol
                AccessServer temp; 
                ^
  symbol:   class AccessServer
  location: class Server
Main.java:1469: error: cannot find symbol
                temp = (AccessServer) clients.get(i); 
                        ^
  symbol:   class AccessServer
  location: class Server
28 errors
stdout
Standard output is empty