Jump to content

razvandragos29

Active Members
  • Posts

    125
  • Joined

  • Last visited

Everything posted by razvandragos29

  1. Sunt de nota 1000 cursurile postate de tine mersi mult !
  2. da asta era lipsea un plus neatentia asta si sunt si racit .
  3. Salut incerc sa aduc acuma informatiile in tabel bazat pe un sistem de login am urmatoarele clasa package proiect;import java.awt.ScrollPane; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.Vector; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPasswordField; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextField; import javax.swing.table.DefaultTableModel; public class Gui extends JFrame { static JTextField user; JPasswordField pass; JButton login; JLabel username; JLabel password; public Gui() throws SQLException { super("Log in Window"); setSize(300,200); setLayout(null); Componente(); add(user); add(pass); add(login); add(username); add(password); setResizable(false); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); } public void Componente() { user=new JTextField(15); user.setBounds(70, 30, 150, 20); pass=new JPasswordField(15); pass.setBounds(70, 65, 150, 20); login=new JButton("Log in"); login.setBounds(110,100,80,20); login.addActionListener(actiune); username=new JLabel("Username"); username.setBounds(1,30,70,20); password=new JLabel("Password"); password.setBounds(1, 65, 70, 20); } Actiune actiune=new Actiune(); public class Actiune implements ActionListener { @Override public void actionPerformed(ActionEvent argument) { String pname=user.getText(); String ppass=new String(pass.getPassword()); if (argument.getSource()==login){ BD dbHandler=new BD(); int tip =dbHandler.queryUserType(pname, ppass); if(tip==1) { System.out.println("Userul este admin") ; dispose(); new GuiProfesor(); } else { System.out.println("Userul este normalll"); dispose(); try { new GuiElev(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } } } package proiect;import java.sql.SQLException; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; public class GuiElev extends JFrame { JTable table ; BD conex; JScrollPane pane; JButton buton; public GuiElev() throws SQLException { super("Gui Elev"); setSize(400,400); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(null); setVisible(true); tabel(); add(pane); add(buton); } public void tabel() throws SQLException { conex=new BD(); String nume=Gui.user.getText(); System.out.println(nume); DefaultTableModel model=new DefaultTableModel(); model = conex.extractTableModel(nume) ; // model.addrow(lista); table =new JTable(model); pane=new JScrollPane(table); // aici am sters declararea unei noi variable. era declarata la nivel de clasa. table.setFillsViewportHeight(true); table.setBounds(10, 10, 400,200); buton =new JButton("Buton aici"); buton.setBounds(200, 10, 20, 20); } } public DefaultTableModel extractTableModel(String nume) throws SQLException { DefaultTableModel model = new DefaultTableModel(); model.addColumn("Nume"); model.addColumn("Adresa");// etc... aici poti sa pui ce coloane te astepti sa ai in tabel. Retine ordinea lor! model.addColumn("ide"); Connection con=(Connection) DriverManager.getConnection(conbd, user, parola); java.sql.Statement stmt=con.createStatement(); String queryy="select nume,adresa,id from elev where" + "nume='" +nume+ "'"; ResultSet rsett=stmt.executeQuery(queryy); while(rsett.next()) { String numee=rsett.getString("nume"); String adresa=rsett.getString("adresa"); int ide=rsett.getInt("ide"); model.addRow(new Object[] {numee, adresa,ide}); } return model; } imi spune ca nu am sintaxa corecta la sql insa am verificat in mysql exact acelasi select si merge imi returneaza ceea ce vreau
  4. Da multumesc mult totul a mers de minune
  5. Am pus codul dat de tine insa nu imi returneaza nimica in tabel codul merge am mai adaugat eu in clasa Gui, am declarat variabila model ca fiind defaulttablemodel :Dv + unde ai pus tu cu mode.addColumn ar trebui cred ca sus sa imi scrie numele coloanei nu merge nici asta
  6. package proiect;import java.awt.ScrollPane; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.Vector; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; public class Gui extends JFrame { JTable table ; BD conex; JScrollPane pane; JButton buton; public Gui() throws SQLException { super("Fereastra"); setSize(400,400); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); tabel(); setLayout(null); add(table); add(buton); setVisible(true); } public void tabel() throws SQLException { conex=new BD(); conex.return1(); String lista=conex.rand; model=new DefaulTableModel(); model.addrow(lista); table =new JTable(model); JScrollPane pane=new JScrollPane(table); table.setFillsViewportHeight(true); table.setBounds(10, 10, 400,200); buton =new JButton("Buton aici"); buton.setBounds(200, 10, 20, 20); } } sper sa intelegi ce vreau sa fac multumesc anticipat stiu ca inca nu stapanesc unele chestii bine si am anumite goluri dar sunt presat de facultate sa termin proiectu pana vineri si nu vreau sa ii fac ceva complicat ceva simplu si la obiect
  7. deci mai sus am variabila string declarata String rand[]; eu vreau sa ma pot folosi de stringu acela intr-o alta clasa Gui unde am tabelul pus o sa folosesc DefaultTableModel pentru a putea folosi metoda addrow(String []), pt a adauga randuri in tabel depinzand de fiecare metoda pe care o apelez acolo am lasat null asa stiu ca trebuia sa intoarca un String
  8. Incerc sa adaug un nou rand intr-un tabel si acesta sa fie cu informatii din baza de date am public String [] return1() throws SQLException { Connection con=(Connection) DriverManager.getConnection(conbd, user, parola); java.sql.Statement stmt=con.createStatement(); String query="select * from elev"; ResultSet rset=stmt.executeQuery(query); int i=0; while(rset.next()) { String nume=rset.getString("nume"); String ceva1=rset.getString("adresa"); rand[i]={nume,ceva1} ; i++; } return null; } nu pot pune acele stringuri intr-un array de stringuri ca pe urma sa folosesc metoda addrow() care primeste in paranteza ca parametru un array separat de virgule
  9. imi zice page not found la toate linkurile
  10. Salut fac la facultate masurari electronice si trebuie sa scriu un program in C++ care sa "activeze" un montaj cu leduri stie cineva vreun simulator sau ceva de genu ?
  11. Multumin din nou !
  12. Bine ai venit ! ><
  13. multumesc mult pentru cupoane !
  14. da pai cred ca lai luat inaintea mea de asta a mers
  15. cuponul freetown nu merge
  16. cuponul ala tintin numai merge ..deloc imi zice ca a fost dezactivat de instructor
  17. Bine ai venit !
  18. imi spune ca cuponul a fost vandut
  19. Bine ai venit !
  20. Cum asi putea sa folosesc si eu scriptu ?
  21. Salut si bine ai venit !
  22. Da mersi mult poti inchide
  23. M2G admin este o coloana din tabelul Person nu ?
  24. Iti multumesc din inima , aveam deja clasa Launcher facuta numai ca la mine se numeste main ..am incercat si eu sa scot mainu unde aveam conexiunea catre baza de date insa imi dadea o eroare , incercasem sa fac un constructor dar tot eroare probabil facem eu ceva gresit acuma imi da o eroare destul de mare java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLSer verDriver at java.net.URLClassLoader$1.run(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at jar_pm.Database.<init>(Database.java:14) at jar_pm.GUILOGIN$Actiune.actionPerformed(GUILOGIN.java:80) at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.setPressed(Unknown Source) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) at java.awt.Component.processMouseEvent(Unknown Source) at javax.swing.JComponent.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Window.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$200(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source) nu am mai lucrat cu baze de date si cu java de asta imi este greu cu java am mai lucrat si am facut vreo 2-3 proiecte mici dar am ceva in spate
  25. In fisierul cu clasa Database este si mainu si nu asi vrea sa fie eu am alt main unde apelez clasa Guilogin si cand rulez imi apare un log in form tu spui sa fac un membru Database db =new Database() ; ? ceva de genu ?
×
×
  • Create New...