Results 1 to 2 of 2
  1. #1
    mmxmp is offline Member
    Join Date
    Jul 2014
    Posts
    1
    Rep Power
    0

    Default How to use datas from login panel in another class

    I am getting datas from user and checking it with database (MS SQL ) if it fits it is sweatching to new window. In new window I need to use again my database so I need to add connecting datas again. I would like to get them from login window. How to do that? I know theory but when I am writting code nothing works. Here is working code for login panel :

    /*import java.awt.BorderLayout;

    import javax.swing.*;

    public class Login extends JFrame {
    public String url;
    public static void main(String[] args) {
    Log frameTabel = new Log();
    }

    JButton log = new Jbutton("Log");

    JPanel panel = new JPanel();

    // --- (….) labels------

    JTextField DB = new JTextField(15);
    JTextField user = new JTextField(15);
    JPasswordField password = new JPasswordField(15);

    Login(){
    super("Login");
    setSize(400,300);
    setLocation(300,10);
    panel.setLayout (null);

    DB.setBounds(50,100,261,25);
    user.setBounds(50,135,261,25);
    password.setBounds(50,170,261,25);

    log.setBounds(50,213,150,25);

    panel.add(DB);
    panel.add(user);
    panel.add(password);
    panel.add(log);

    DB.setDocument(new LogLimit(10));
    user.setDocument(new LogLimit(10));
    password.setDocument(new LogLimit(10));

    getContentPane().add(panel);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);
    actionlogin(); }

    public void actionlogin(){
    loguj.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent ae) {

    String aip1 = // add;
    String aserver = // add;
    String aDB = DBy.getText();
    String auser = user.getText();
    String apassword = password.getText();

    Connection connection = null;

    Class.forName("com.microsoft.sqlserver.jdbc.SQLSer verDriver");

    String url = "jdbc:sqlserver://"+ aip +
    "databaseName="+aDB+";user="+auser+";
    password="+apassword+";";;

    connection = DriverManager.getConnection(url);

    NextWindow regFace =new NextWindow();
    regFace.setVisible(true);
    dispose();

    }
    catch (ClassNotFoundException e) {

    System.out.println("Engine not found" + e.getMessage());

    JoptionPane.showMessageDialog(null,"Can not find engine ");
    DB.setText("");
    user.setText("");
    password.setText("");
    user.requestFocus();
    }
    catch (SQLException e) {

    System.out.println("Can not conncet " + e.getMessage());

    JoptionPane.showMessageDialog(null,"Can not conncet ");

    DB.setText("");
    user.setText("");
    password.setText("");
    user.requestFocus();
    }}});
    }}
    Last edited by mmxmp; 08-05-2014 at 12:26 AM.

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    843
    Rep Power
    6

    Default Re: How to use datas from login panel in another class

    you have to post the code with code tag.il
    There are lot of issues in your code and what you posted is not complete.
    1. where is your Log class?
    2.within actionperformed event you are opening your connection that too local to the meth....if u click multiple times,then multiple times connection will be opened .
    and no close opration .
    3. if the user not entering anything in textfield then what will you do?

    4.before getting any values check for null and empty.

    post the code with comments
    Ramya:cool:

Similar Threads

  1. Replies: 4
    Last Post: 03-19-2013, 03:11 PM
  2. Replies: 6
    Last Post: 10-22-2012, 03:12 PM
  3. how to add to a panel from in a different class
    By dizzymj17 in forum New To Java
    Replies: 1
    Last Post: 04-18-2011, 11:17 PM
  4. Add datas to cells of JTable ???
    By bilgohan in forum AWT / Swing
    Replies: 5
    Last Post: 02-22-2010, 10:56 AM
  5. No datas in added to arraylist
    By Preethi in forum New To Java
    Replies: 0
    Last Post: 02-15-2008, 12:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •