private void setcbr() { try { ResultSet rst = DBConnection.getDBConnection() .createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE) .executeQuery( "SELECT * FROM Passenger where Booked_status='Booked' and Pay_Status='Not_Paid'"); System.out.println("Hello"); while (rst.next()) { combo1.addItem(rst.getString(1)); combo2.addItem(rst.getString(2)); } } catch (Exception n) { n.printStackTrace(); } }
// Вид формы при изменении сотрудника public void sotrDiaUpdate(Sotrudnik s) { label_id_hidden.setText(Integer.toString(s.getId_sotrudnika())); textField_familiya.setText(s.getFamiliya()); textField_imya.setText(s.getImya()); textField_otchestvo.setText(s.getOtchestvo()); textField_phone.setText(s.getPhone()); textField_date.setText(s.getData_priema().toString()); comboBox_doljnost.removeAllItems(); comboBox_kvalification.removeAllItems(); try { DBClass db = new DBClass(); ArrayList<Doljnost> d = db.doljnostFromDB(); DBClass db2 = new DBClass(); Doljnost dd = db2.doljnostFromDB(s); for (int i = 0; i < d.size(); i++) { comboBox_doljnost.addItem(d.get(i)); Doljnost ddd = (Doljnost) comboBox_doljnost.getItemAt(i); if (dd.getNazvanie_doljnosti().equals(ddd.getNazvanie_doljnosti())) dd = ddd; } comboBox_doljnost.setSelectedItem(dd); DBClass db3 = new DBClass(); ArrayList<Kvalification> k = db3.kvalificationFromDB(); DBClass db4 = new DBClass(); Kvalification kk = db4.kvalificationFromDB(s); for (int i = 0; i < k.size(); i++) { comboBox_kvalification.addItem(k.get(i)); Kvalification kkk = (Kvalification) comboBox_kvalification.getItemAt(i); if (kk.getNazvanie_kvalification().equals(kkk.getNazvanie_kvalification())) kk = kkk; } comboBox_kvalification.setSelectedItem(kk); } catch (ClassNotFoundException e) { e.printStackTrace(); JOptionPane.showMessageDialog(panelException, e.getMessage()); } catch (SQLException ee) { ee.printStackTrace(); JOptionPane.showMessageDialog(panelException, ee.getMessage()); } }
// Вид формы при добавлении нового сотрудника public void sotrDiaInsert() { label_id_hidden.setText("Новый сотрудник"); textField_familiya.setText(""); textField_imya.setText(""); textField_otchestvo.setText(""); textField_phone.setText(""); comboBox_doljnost.removeAllItems(); comboBox_kvalification.removeAllItems(); Calendar calend = Calendar.getInstance(); if (calend.get(Calendar.MONTH) <= 9) { textField_date.setText( String.valueOf( (calend.get(Calendar.YEAR) + "-" + ("0" + (1 + calend.get(Calendar.MONTH))) + "-") + (calend.get(Calendar.DATE)))); } else textField_date.setText( String.valueOf( ((calend.get(Calendar.YEAR)) + "-" + (1 + calend.get(Calendar.MONTH)) + "-") + (calend.get(Calendar.DATE)))); textField_date.setEnabled(false); try { DBClass db = new DBClass(); ArrayList<Doljnost> d = db.doljnostFromDB(); for (int i = 0; i < d.size(); i++) { comboBox_doljnost.addItem(d.get(i)); } DBClass db2 = new DBClass(); ArrayList<Kvalification> k = db2.kvalificationFromDB(); for (int i = 0; i < k.size(); i++) { comboBox_kvalification.addItem(k.get(i)); } } catch (ClassNotFoundException e) { e.printStackTrace(); JOptionPane.showMessageDialog(panelException, e.getMessage()); } catch (SQLException ee) { ee.printStackTrace(); JOptionPane.showMessageDialog(panelException, ee.getMessage()); } }
private void setamount() { try { ResultSet rst = DBConnection.getDBConnection() .createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE) .executeQuery( "SELECT Amount FROM BOOKING where Pass_No='" + combo1.getSelectedItem() + "'"); while (rst.next()) { combo8.addItem(rst.getString(1)); } } catch (Exception n) { n.printStackTrace(); } }
private void setCombo() { try { ResultSet rst = DBConnection.getDBConnection() .createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE) .executeQuery( "SELECT Emp.empNo, Emp.Sname, Emp.Fname, Emp.Lname, Emp.Designation FROM Emp WHERE Emp.Designation='Booking Clerk'"); while (rst.next()) { combo3.addItem(rst.getString(3)); } } catch (Exception n) { n.printStackTrace(); } }
public static void updateKvalification() { try { DBClass db2 = new DBClass(); ArrayList<Kvalification> k = db2.kvalificationFromDB(); comboBox_kvalification.removeAllItems(); for (int i = 0; i < k.size(); i++) { comboBox_kvalification.addItem(k.get(i)); } } catch (ClassNotFoundException e) { e.printStackTrace(); JOptionPane.showMessageDialog(null, e.getMessage()); } catch (SQLException ee) { ee.printStackTrace(); JOptionPane.showMessageDialog(null, ee.getMessage()); } }
public static void updateDoljnost() { try { DBClass db = new DBClass(); ArrayList<Doljnost> d = db.doljnostFromDB(); comboBox_doljnost.removeAllItems(); for (int i = 0; i < d.size(); i++) { comboBox_doljnost.addItem(d.get(i)); } } catch (ClassNotFoundException e) { e.printStackTrace(); JOptionPane.showMessageDialog(null, e.getMessage()); } catch (SQLException ee) { ee.printStackTrace(); JOptionPane.showMessageDialog(null, ee.getMessage()); } }
public Payment() { super("Payment Process", false, true, false, true); setDefaultCloseOperation(DISPOSE_ON_CLOSE); label1 = new JLabel("Paymnent Number"); label2 = new JLabel("Passenger Number"); label3 = new JLabel("Passenger Name"); label6 = new JLabel("Mode of Payment"); label4 = new JLabel("Date of Payment"); label5 = new JLabel("Amount Paid"); label7 = new JLabel("Received By"); text1 = new JTextField(10); text5 = new JTextField(10); p_date = new DateButton(); p_date.setForeground(Color.red); combo1 = new JComboBox(); combo2 = new JComboBox(); combo3 = new JComboBox(); combo4 = new JComboBox(); combo4.addItem("Cash"); combo4.addItem("Bank"); combo8 = new JComboBox(); button1 = new JButton("Pay", new ImageIcon(ClassLoader.getSystemResource("Images/payments.png"))); button2 = new JButton( "Print Receipt", new ImageIcon(ClassLoader.getSystemResource("Images/print.png"))); button3 = new JButton("Cancel", new ImageIcon(ClassLoader.getSystemResource("Images/exit.png"))); button4 = new JButton("Search", new ImageIcon(ClassLoader.getSystemResource("Images/search.png"))); button5 = new JButton("Delete", new ImageIcon(ClassLoader.getSystemResource("Images/delete.png"))); // combo3.addItem(new) panel1 = new JPanel(new GridLayout(7, 2)); panel1.setPreferredSize(new Dimension(350, 250)); panel1.add(label1); panel1.add(text1); panel1.add(label2); panel1.add(combo1); panel1.add(label3); panel1.add(combo2); panel1.add(label6); panel1.add(combo4); panel1.add(label4); panel1.add(p_date); panel1.add(label5); panel1.add(combo8); panel1.add(label7); panel1.add(combo3); // combo8.removeAllItems(); pane = new JPanel(); pane.add(button1); pane.add(button2); pane.add(button3); pane.add(button4); panel3 = new JPanel(); panel3.add(panel1); panel3.add(pane); button2.setEnabled(false); add(panel3); setSize(500, 350); setCombo(); setcbr(); generator(); setamount(); setLocation((screen.width - 300) / 2, ((screen.height - 300) / 2)); setResizable(false); combo1.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { combo2.setSelectedIndex(combo1.getSelectedIndex()); combo8.removeItem(combo8.getSelectedItem()); setamount(); } }); button3.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { setVisible(true); dispose(); } }); button2.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { Receipt frm = new Receipt(); MDIWindow.desktop.add(frm); frm.setVisible(true); button2.setEnabled(false); } }); button1.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { if (combo1.getSelectedItem() == null) { JOptionPane.showMessageDialog( null, "All Passenger have paid", "Error", JOptionPane.DEFAULT_OPTION); return; } if (combo2.getSelectedItem() == null) { JOptionPane.showMessageDialog( null, "All Passenger have paid", "Error", JOptionPane.DEFAULT_OPTION); return; } generator(); if (combo8.getSelectedItem() == null) { JOptionPane.showMessageDialog( null, "The Passenger has not been booked", "ERROR", JOptionPane.DEFAULT_OPTION); return; } try { Statement statement = DBConnection.getDBConnection().createStatement(); { String temp = "INSERT INTO Payment (Payment_No, Pass_No, Pass_Name, Payment_Mode, Date_Payment,Amount_Paid,Received_By) VALUES ('" + text1.getText() + "', '" + combo1.getSelectedItem() + "', '" + combo2.getSelectedItem() + "', '" + combo4.getSelectedItem() + "', '" + p_date.getText() + "', '" + combo8.getSelectedItem() + "', '" + combo3.getSelectedItem() + "')"; combo1.removeItem(combo1.getSelectedItem()); combo2.removeItem(combo2.getSelectedItem()); int result = statement.executeUpdate(temp); JOptionPane.showMessageDialog( null, "Passenger Account updated", "Updated", JOptionPane.DEFAULT_OPTION); } } catch (SQLException sqlex) { sqlex.printStackTrace(); } try { Statement statement = DBConnection.getDBConnection().createStatement(); { String temp = "UPDATE Passenger SET Pay_Status='Paid'" + "WHERE Pass_NO LIKE '" + combo1.getSelectedItem() + "'"; int result = statement.executeUpdate(temp); } } catch (SQLException sqlex) { sqlex.printStackTrace(); } button1.setEnabled(false); button2.setEnabled(true); } }); button4.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { try { if (!text1.equals("")) { Statement statement = DBConnection.getDBConnection().createStatement(); String query = ("SELECT * FROM Payment where Payment_No ='" + text1.getText() + "'"); ResultSet rs = statement.executeQuery(query); display(rs); statement.close(); } } catch (SQLException sqlex) { sqlex.printStackTrace(); } setVisible(true); } }); }
public NewUser() { super("Adding New User"); label1 = new JLabel("Name"); label2 = new JLabel("Category"); username = new JLabel("Username"); password = new JLabel("Password"); confirm = new JLabel("Re-enter Password"); pass1 = new JPasswordField(); pass2 = new JPasswordField(); txtusername = new JTextField(); name = new JTextField(); combo1 = new JComboBox(); button1 = new JButton("Ok", new ImageIcon("Icon/i16x16/ok.png")); button2 = new JButton("Cancel", new ImageIcon("Icon/i16x16/exit.png")); panel1 = new JPanel(new GridLayout(6, 2)); panel1.add(label1); panel1.add(name); panel1.add(label2); panel1.add(combo1); panel1.add(username); panel1.add(txtusername); panel1.add(password); panel1.add(pass1); panel1.add(confirm); panel1.add(pass2); panel1.add(button1); panel1.add(button2); combo1.addItem("Manager"); combo1.addItem("Booking Clerk"); combo1.addItem("Supervisor"); panel2 = new JPanel(); panel2.add(panel1); getContentPane().add(panel2); setSize(350, 195); setVisible(true); setLocation((screen.width - 500) / 2, ((screen.height - 350) / 2)); setResizable(false); name.addKeyListener( new KeyAdapter() { public void keyTyped(KeyEvent e) { char c = e.getKeyChar(); if (!(Character.isLetter(c) || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_SPACE) || (c == KeyEvent.VK_DELETE))) { getToolkit().beep(); JOptionPane.showMessageDialog( null, "Invalid Character", "ERROR", JOptionPane.DEFAULT_OPTION); e.consume(); } } }); txtusername.addKeyListener( new KeyAdapter() { public void keyTyped(KeyEvent e) { char c = e.getKeyChar(); if (!(Character.isLetter(c) || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_SPACE) || (c == KeyEvent.VK_DELETE))) { getToolkit().beep(); JOptionPane.showMessageDialog( null, "Invalid Character", "ERROR", JOptionPane.DEFAULT_OPTION); e.consume(); } } }); button1.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { if (name.getText() == null || name.getText().equals("")) { JOptionPane.showMessageDialog( null, "Enter name", "ERROR", JOptionPane.DEFAULT_OPTION); name.requestFocus(); return; } if (txtusername.getText() == null || txtusername.getText().equals("")) { JOptionPane.showMessageDialog( null, "Enter username", "ERROR", JOptionPane.DEFAULT_OPTION); txtusername.requestFocus(); return; } if (pass1.getText() == null || pass1.getText().equals("")) { JOptionPane.showMessageDialog( null, "Enter password", "ERROR", JOptionPane.DEFAULT_OPTION); pass1.requestFocus(); return; } if (pass2.getText() == null || pass2.getText().equals("")) { JOptionPane.showMessageDialog( null, "Confirm your password", "ERROR", JOptionPane.DEFAULT_OPTION); pass2.requestFocus(); return; } if (!pass1.getText().equals(pass2.getText())) { JOptionPane.showMessageDialog( null, "passwords do not match.", "ERROR", JOptionPane.DEFAULT_OPTION); pass2.requestFocus(); return; } try { Statement statement = Connect.getConnection().createStatement(); { String temp = "INSERT INTO users (Name,Category,username, password) VALUES ('" + name.getText() + "', '" + combo1.getSelectedItem() + "', '" + txtusername.getText() + "', '" + pass1.getText() + "')"; int result = statement.executeUpdate(temp); JOptionPane.showMessageDialog( null, "User is succesfully added", "SUCCESS", JOptionPane.DEFAULT_OPTION); dispose(); } } catch (Exception in) { in.printStackTrace(); } } }); button2.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { dispose(); } }); }
public QueryDBFrame() { setTitle("QueryDB"); setSize(400, 300); addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); getContentPane().setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); authors = new JComboBox(); authors.setEditable(false); authors.addItem("Any"); publishers = new JComboBox(); publishers.setEditable(false); publishers.addItem("Any"); result = new JTextArea(4, 50); result.setEditable(false); priceChange = new JTextField(8); priceChange.setText("-5.00"); try { // 连接数据库 con = getConnection(); stmt = con.createStatement(); // 将数据库中的作者名添加到组合框 String query = "SELECT Name FROM Authors"; ResultSet rs = stmt.executeQuery(query); while (rs.next()) authors.addItem(rs.getString(1)); // 将出版社名添加到组合框 query = "SELECT Name FROM Publishers"; rs = stmt.executeQuery(query); while (rs.next()) publishers.addItem(rs.getString(1)); } catch (Exception e) { result.setText("Error " + e); } gbc.fill = GridBagConstraints.NONE; gbc.weightx = 100; gbc.weighty = 100; add(authors, gbc, 0, 0, 2, 1); add(publishers, gbc, 2, 0, 2, 1); gbc.fill = GridBagConstraints.NONE; JButton queryButton = new JButton("Query"); queryButton.addActionListener(this); add(queryButton, gbc, 0, 1, 1, 1); JButton changeButton = new JButton("Change prices"); changeButton.addActionListener(this); add(changeButton, gbc, 2, 1, 1, 1); gbc.fill = GridBagConstraints.HORIZONTAL; add(priceChange, gbc, 3, 1, 1, 1); gbc.fill = GridBagConstraints.BOTH; add(result, gbc, 0, 2, 4, 1); }
public Assi() { c = getContentPane(); c.setLayout(new BorderLayout()); c.add(pnn, BorderLayout.NORTH); c.add(pns, BorderLayout.SOUTH); c.add(pnc, BorderLayout.CENTER); c.add(pne, BorderLayout.EAST); pne.setLayout(new GridLayout(2, 1)); pne.add(pne1); pne.add(pne2); pne1.setLayout(new FlowLayout()); pne1.add(go); go.addItem("Student"); go.addItem("Teacher"); go.addItem("Course"); go.addItem("Result"); pne1.add(b6); pne2.setLayout(cl2); pns.add(b1); pns.add(b2); pns.add(b3); pns.add(b4); pns.add(b5); setJMenuBar(m); m.add(student); m.add(teacher); m.add(course); m.add(result); stu.setLayout(new GridLayout(8, 2)); stu.add(l1); stu.add(t1); stu.add(l2); stu.add(t2); stu.add(l3); stu.add(t3); stu.add(l4); stu.add(t4); stu.add(l5); stu.add(t5); stu.add(l6); stu.add(t6); cou.setLayout(new GridLayout(4, 2)); cou.add(l7); cou.add(t7); cou.add(l8); cou.add(t8); cou.add(l9); cou.add(t9); cou.add(l0); cou.add(t0); tea.setLayout(new GridLayout(4, 2)); tea.add(l11); tea.add(t11); tea.add(l12); tea.add(t12); tea.add(l13); tea.add(t13); tea.add(l14); tea.add(t14); res.setLayout(new GridLayout(15, 3)); res.add(l15); res.add(t15); res.add(l16); res.add(t16); res.add(l17); res.add(t17); res.add(lg); res.add(l); res.add(l18); res.add(t18); res.add(l19); res.add(t19); res.add(l20); res.add(t20); res.add(l21); res.add(t21); res.add(l22); res.add(t22); res.add(l23); res.add(t23); res.add(l24); res.add(t24); res.add(l25); res.add(t25); res.add(l26); res.add(t26); res.add(l27); res.add(t27); res.add(l28); res.add(t28); pnc.setLayout(cl); pnc.add(blk, "cblk"); pnc.add(stu, "cstu"); pnc.add(tea, "ctea"); pnc.add(cou, "ccou"); pnc.add(res, "cres"); b1.addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); b4.addActionListener(this); b5.addActionListener(this); b6.addActionListener(this); student.addActionListener(this); teacher.addActionListener(this); course.addActionListener(this); result.addActionListener(this); go.addItemListener(this); }
public emp() { setTitle("AMRITA HUMAN RESOURCE MANAGEMENT SYSTEM (EMPLOYEE DETAIL)"); getContentPane().add(p, BorderLayout.CENTER); getContentPane().add(q, BorderLayout.SOUTH); setTitle("Placement Office"); lname = new JLabel("Name: "); lextra = new JLabel("Vacancy(s): "); lfield = new JLabel("Field: "); lsal = new JLabel("Minimum Expected Salary: "); lusr = new JLabel("Login name: "); lpwd = new JLabel("Password: "******"5,000"); cbsal.addItem("10,000"); cbsal.addItem("15,000"); cbsal.addItem("20,000"); cbsal.setBackground(Color.ORANGE); it = new JRadioButton("Software Engg."); civil = new JRadioButton("Civil Engg."); mech = new JRadioButton("Mechanical Engg."); ButtonGroup bg2 = new ButtonGroup(); bg2.add(it); bg2.add(civil); bg2.add(mech); civil.setBackground(Color.ORANGE); bSub = new JButton("Submit"); bRes = new JButton("Reset"); p.setLayout(new GridLayout(11, 2)); Blank = new JLabel(""); Blank1 = new JLabel(""); Blank2 = new JLabel(""); Blank3 = new JLabel(""); Blank4 = new JLabel(""); p.add(lusr); p.add(tusr); p.add(lpwd); p.add(tpwd); p.add(lname); p.add(tname); p.add(lextra); p.add(textra); p.add(lfield); p.add(it); p.add(Blank4); p.add(civil); p.add(Blank1); p.add(mech); p.add(lsal); p.add(cbsal); q.add(bSub); q.add(bRes); bSub.addActionListener(this); bRes.addActionListener(this); setVisible(true); setBounds(200, 200, 300, 300); setDefaultCloseOperation(EXIT_ON_CLOSE); }
public vehicle() { message = new JLabel("VEHICLE DETAILS"); mname = new JLabel("Model Name"); cap = new JLabel("Capacity"); cc = new JLabel("CC"); eng = new JLabel("Engine"); stroke = new JLabel("Stroke"); bhp = new JLabel("BHP"); volt = new JLabel("Volts"); rpm = new JLabel("RPM"); weight = new JLabel("Weight"); kg = new JLabel("Kg"); gear = new JLabel("Gears"); color = new JLabel("Color"); jcmname = new JComboBox(); tfcap = new JTextField(30); tfeng = new JTextField(20); tfbhp = new JTextField(10); tfvolt = new JTextField(20); tfrpm = new JTextField(20); tfweight = new JTextField(20); tfgear = new JTextField(30); jccolor = new JComboBox(); ok = new JButton("OK"); can = new JButton("CANCEL"); can.addActionListener(this); can.setActionCommand("can"); ok.addActionListener(this); ok.setActionCommand("Ok"); Container c = getContentPane(); setSize(800, 600); setTitle("Vehicle Details"); c.setLayout(null); setVisible(true); c.add(message); c.add(mname); c.add(cap); c.add(cc); c.add(eng); c.add(stroke); c.add(bhp); c.add(volt); c.add(rpm); c.add(weight); c.add(kg); c.add(gear); c.add(color); c.add(jcmname); c.add(tfcap); c.add(tfeng); c.add(tfbhp); c.add(tfvolt); c.add(tfrpm); c.add(tfweight); c.add(tfgear); c.add(jccolor); c.add(ok); c.add(can); c.setBackground(Color.pink); message.setBounds(300, 40, 200, 50); mname.setBounds(50, 100, 100, 30); cap.setBounds(50, 150, 100, 30); cc.setBounds(275, 150, 50, 30); eng.setBounds(50, 200, 50, 30); stroke.setBounds(275, 200, 100, 30); bhp.setBounds(50, 250, 100, 30); volt.setBounds(50, 300, 100, 30); rpm.setBounds(50, 350, 100, 30); weight.setBounds(50, 400, 50, 30); kg.setBounds(275, 400, 100, 30); gear.setBounds(450, 150, 150, 30); color.setBounds(450, 200, 100, 30); jcmname.setBounds(200, 100, 100, 30); jcmname.addItem(" -- Select --"); jcmname.addItem("Pulsar"); jcmname.addItem("CT 100"); jcmname.addItem("Discover DTS-i"); jcmname.addItem("Wave DTS-i"); tfcap.setBounds(200, 150, 70, 30); tfeng.setBounds(200, 200, 70, 30); tfbhp.setBounds(200, 250, 70, 30); tfvolt.setBounds(200, 300, 70, 30); tfrpm.setBounds(200, 350, 70, 30); tfweight.setBounds(200, 400, 70, 30); tfgear.setBounds(500, 150, 70, 30); jccolor.setBounds(500, 200, 100, 30); jccolor.addItem("Black"); jccolor.addItem("Blue"); jccolor.addItem("Red"); jccolor.addItem("Grey"); ok.setBounds(270, 480, 85, 30); can.setBounds(370, 480, 85, 30); }
public Design() throws Exception { super.setBackground(Color.BLACK); this.setTitle(""); con = getContentPane(); con.setLayout(null); dim = tk.getDefaultToolkit().getScreenSize(); this.setTitle("Customer Peer Login"); l1 = new JLabel(new ImageIcon("plain.jpg")); l1.setBounds(0, 0, 400, 400); con.add(l1); l1.setBorder(BorderFactory.createEtchedBorder(5, Color.black, Color.black)); title = new JLabel("CUSTOMER PEER LOGIN "); title.setFont(new Font("Bookman Old Style", Font.ROMAN_BASELINE, 20)); title.setForeground(Color.red); title.setBounds(80, 30, 300, 30); l1.add(title); l4 = new JLabel("CMACHINE NAME"); l4.setFont(new Font("Bookman Old Style", Font.BOLD, 16)); l4.setForeground(Color.BLUE); l4.setBounds(70, 100, 160, 20); // l4.setBorder(BorderFactory.createEtchedBorder(5,Color.green,Color.green)); l1.add(l4); jtf2 = new JTextField(); jtf2.setBounds(250, 100, 100, 20); jtf2.setBorder(BorderFactory.createEtchedBorder(5, Color.green, Color.green)); l1.add(jtf2); l2 = new JLabel("CUSER LOGIN"); l2.setFont(new Font("Bookman Old Style", Font.BOLD, 16)); l2.setForeground(Color.blue); l2.setBounds(70, 150, 120, 20); l1.add(l2); jtf1 = new JTextField(); jtf1.setBounds(250, 150, 100, 20); jtf1.setBorder(BorderFactory.createEtchedBorder(5, Color.green, Color.green)); l1.add(jtf1); l3 = new JLabel("CPASSWORD"); l3.setFont(new Font("Bookman Old Style", Font.BOLD, 16)); l3.setForeground(Color.blue); l3.setBounds(70, 200, 120, 20); l1.add(l3); jptf1 = new JPasswordField(); jptf1.setBounds(250, 200, 100, 20); jptf1.setBorder(BorderFactory.createEtchedBorder(5, Color.green, Color.green)); l1.add(jptf1); JLabel l4 = new JLabel("DAgent"); l4.setFont(new Font("Bookman Old Style", Font.BOLD, 16)); l4.setForeground(Color.blue); l4.setBounds(70, 250, 120, 20); l1.add(l4); box = new JComboBox(); box.setBounds(250, 250, 100, 20); box.setBorder(BorderFactory.createEtchedBorder(5, Color.green, Color.green)); l1.add(box); b2 = new JButton("Register"); b2.setBounds(50, 300, 100, 20); l1.add(b2); b2.setBorder(BorderFactory.createEtchedBorder(10, Color.BLUE, Color.BLUE)); b3 = new JButton("Login"); b3.setBounds(150, 300, 100, 20); b3.setBorder(BorderFactory.createEtchedBorder(10, Color.BLUE, Color.BLUE)); l1.add(b3); b1 = new JButton("Cancel"); b1.setBounds(250, 300, 100, 20); b1.setBorder(BorderFactory.createEtchedBorder(10, Color.BLUE, Color.BLUE)); l1.add(b1); b1.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent we) { dispose(); } }); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn = DriverManager.getConnection("jdbc:odbc:agent"); } catch (Exception exp) { } try { Statement satem = conn.createStatement(); ResultSet rsatem = satem.executeQuery("select * from Dagent"); while (rsatem.next()) { String namem = rsatem.getString("uname"); box.addItem(namem); } } catch (Exception expo1) { } b2.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent we) { String username = jtf1.getText().trim(); String password = jptf1.getText().trim(); String mechine = jtf2.getText().trim(); String dname = box.getSelectedItem().toString(); int porte = 0; try { Statement sate = conn.createStatement(); ResultSet rsate = sate.executeQuery("select * from Dagent where uname='" + dname + "'"); if (rsate.next()) { servermachine = rsate.getString("umechine"); porte = rsate.getInt("ulistport"); System.out.println(servermachine); } System.out.println(servermachine); } catch (Exception exp) { exp.printStackTrace(); } try { packet p = new packet(); p.setaction("Creg"); p.setCuser(username); p.setCpass(password); p.setCmname(mechine); p.setCDpeer(dname); Socket soc = new Socket(servermachine, porte); ObjectOutputStream out = new ObjectOutputStream(soc.getOutputStream()); out.writeObject(p); ObjectInputStream in = new ObjectInputStream(soc.getInputStream()); packet rpac = (packet) in.readObject(); if (rpac.getaction().equals("ok")) { JOptionPane.showMessageDialog(null, "Sucessfully Registered"); jtf2.setText(""); jtf1.setText(""); jptf1.setText(""); } else { JOptionPane.showMessageDialog(null, "Already Registered"); jtf2.setText(""); jtf1.setText(""); jptf1.setText(""); } } catch (Exception exp) { } } }); b3.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent we) { String username = jtf1.getText().trim(); String password = jptf1.getText().trim(); String mechine = jtf2.getText().trim(); String Dname = box.getSelectedItem().toString(); int porte = 0; try { Statement sate = conn.createStatement(); ResultSet rsate = sate.executeQuery("select * from Dagent where uname='" + Dname + "'"); if (rsate.next()) { servermachine = rsate.getString("umechine"); porte = rsate.getInt("ulistport"); System.out.println(servermachine); } System.out.println(servermachine); } catch (Exception exp) { } try { packet p1 = new packet(); p1.setaction("clogin"); p1.setCuser(username); p1.setCpass(password); p1.setCmname(mechine); p1.setCDpeer(Dname); Socket soc1 = new Socket(servermachine, porte); ObjectOutputStream out1 = new ObjectOutputStream(soc1.getOutputStream()); out1.writeObject(p1); ObjectInputStream in1 = new ObjectInputStream(soc1.getInputStream()); packet rpac1 = (packet) in1.readObject(); if (rpac1.getaction().equals("ok")) { int port1 = 0; try { int portm = rpac1.getCport(); System.out.println("XXXXXXX" + portm); // JOptionPane.showMessageDialog(null,"Sucessfully Started"); new Listen(portm); new process(username, portm); dispose(); } catch (Exception exp) { } } else { JOptionPane.showMessageDialog( null, "Enter valid username and password", "Server reply", 2); jtf1.setText(""); jtf2.setText(""); jptf1.setText(""); } } catch (Exception exp) { } } }); setSize(400, 400); show(); setLocation(150, 100); setResizable(false); }