Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Hide forms in java application

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Hide forms in java application

    I have a login form that doesn't hide when a user logs in successfully. what might be the problem?

    code

    package employeeinformationandpayrollsystem;

    import javax.swing.*;
    import javax.swing.ImageIcon.*;
    import javax.swing.JPanel.*;
    import javax.swing.JOptionPane;
    import java.awt.*;
    import java.awt.event.*;
    import java.lang.*;
    import javax.swing.border.*;
    import java.sql.*;
    public class UserLogin implements ActionListener,WindowListener
    {
    JButton ok,cancel;
    String userId,password,status;
    JPasswordField passwordInput;
    JTextField f1,f2;

    boolean flag=false;
    String pass1="admin";
    String pass2="muthee";
    //char englishStr[]={'m','u','t','h','e','e'};
    //char urduStr[]={'j','o','n','n','y'};
    static JFrame aWindow=new JFrame("UserLOGIN ");
    public UserLogin(String title)
    {


    aWindow.setDefaultCloseOperation(JFrame.HIDE_ON_CL OSE);
    Toolkit theKit=aWindow.getToolkit();
    Dimension wndSize=theKit.getScreenSize();
    aWindow.setBounds(wndSize.width/4,wndSize.height/4,wndSize.width/2,wndSize.height/2);
    FlowLayout flow=new FlowLayout();
    Container content=aWindow.getContentPane();
    content.setLayout(flow);




    JLabel l1=new JLabel("USER NAME");
    f1=new JTextField(userId);

    JLabel l2=new JLabel("PASSWORD");
    passwordInput=new JPasswordField(password);

    JLabel l3=new JLabel("Status");
    f2=new JTextField(status);


    ok=new JButton("OK");
    cancel=new JButton("Cancel");
    Dimension size=new Dimension(80,20);
    f1.setPreferredSize(size);
    passwordInput.setPreferredSize(size);
    f2.setPreferredSize(size);
    content.add(l1);
    content.add(f1);
    content.add(l2);
    content.add(passwordInput);
    //content.add(l3);
    content.add(f2);
    content.add(l3);
    content.add(ok);
    content.add(cancel);


    aWindow.setVisible(true);



    //f1.addActionListener(this);
    passwordInput.addActionListener(this);
    ok.addActionListener(this);
    cancel.addActionListener(this);
    aWindow.addWindowListener(this);


    }//end of constructor

    /*public void keyPressed(KeyEvent ke)
    {
    for(int ii=0;ii<35;ii++)
    {
    if (ke.getKeyCode()==englishStr[ii])
    {

    f1.append(String.valueOf(urduStr[ii]));
    }
    }
    }
    public void keyReleased(KeyEvent ke){
    }
    public void keyTyped(KeyEvent ke){

    //System.out.println("key is pressed");
    }*/


    //handler for window closing event
    public void windowClosing(WindowEvent e)
    {
    aWindow.dispose();

    }
    //listener interface functions we must implement
    public void windowOpened(WindowEvent e){}
    public void windowClosed(WindowEvent e){}
    public void windowIconified(WindowEvent e){}
    public void windowDeiconified(WindowEvent e){}
    public void windowActivated(WindowEvent e){}
    public void windowDeactivated(WindowEvent e){}


    public void actionPerformed(ActionEvent ae)


    {
    Object source=ae.getSource();


    if (ae.getActionCommand().equals("Cancel")||source==c ancel)
    {
    System.exit(0);
    }
    else if(ae.getActionCommand().equals("OK")||source==ok)

    {

    //textfieldPas
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    String sourceURL="jdbcdbc:database";
    Connection databaseConnection=DriverManager.getConnection(sou rceURL);

    Statement statement=databaseConnection.createStatement();
    String str = "SELECT User,Password FROM Login WHERE user='" + f1.getText() + "' AND password='" + passwordInput.getText() + "'AND status='"+f2.getText()+"'";
    ResultSet authorNames=statement.executeQuery(str);
    if (authorNames.next())
    {
    switch (f2.getText()) {
    case "admin":
    UserChoice us=new UserChoice("Admin choice");
    break;
    case "user":
    UserChoice1 us1=new UserChoice1("User Choice");
    break;
    }


    }
    else {
    JOptionPane.showMessageDialog(null,"Invalid Password/User Name/Status");
    }


    }
    catch(Exception cnfe)
    {
    System.err.println(cnfe);
    }

    }
    }
    //action performed
    public static void main(String arg[])
    {
    UserLogin lola=new UserLogin("User Login");
    }

    }//UserLogin end}//UserLogin end


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,130
    Thanks
    52
    Thanked 2,286 Times in 2,257 Posts

    Default Re: Hide forms in java application

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

    Does the code call the setVisible() method?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Hide forms in java application

    Yes it does but still doesn't hide when i login

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,130
    Thanks
    52
    Thanked 2,286 Times in 2,257 Posts

    Default Re: Hide forms in java application

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.


    Where is the code that is supposed to "hide the form"?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Java Forms Using Netbeans
    By oneeye_dragon in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 29th, 2012, 08:08 AM
  2. how to hide jtable in jframe
    By vitiazaltair in forum AWT / Java Swing
    Replies: 2
    Last Post: February 7th, 2012, 10:12 AM
  3. New beginner textfile and forms etc.
    By AnnieViola in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: October 18th, 2011, 07:29 AM
  4. Hide/Show Form?
    By chickenhawk in forum What's Wrong With My Code?
    Replies: 11
    Last Post: July 1st, 2011, 06:26 AM
  5. Continuous Forms
    By adam1305 in forum AWT / Java Swing
    Replies: 0
    Last Post: March 3rd, 2010, 12:04 PM