I need to create java interface that prompts users to imput their username and password to access a component database using access or text file. then i need tohave search fields and buy field and then a contact us.....aahhh im trying but im reqal frustrated aaaaaa

Recommended Answers

All 9 Replies

As above, more information would help.

Have you started anything yet? If so, what have you done, and where are you doing wrong?

Also, there are many sites that have tutorials on how to make an interface(I'm assuming you mean a GUI?)

Start by looking at those sites, and just make the GUI. After that, read up on how to make those buttons you put on the GUI work.

I had the same problem as you - I didn't know where to start.

Bottom line: Google is your friend

thanks guys i got the window up i need to read from my database now
this is where i am
and alse define my functions i just added from alot of google links

/****************************************************************/  
/*                          login                               */
/*                                                              */
/****************************************************************/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


public class login extends JFrame
{
    // Variables declaration
    private JLabel jLabel1;
    private JLabel jLabel2;
    private JLabel jLabel3;
    private JTextField jTextField1;
    private JPasswordField jPasswordField1;
    private JButton jButton1;
    private JPanel contentPane;
    
    // End of variables declaration


    public login()
    {
        super();
        create();
        this.setVisible(true);
    }

    
    private void create()
    {
        jLabel1 = new JLabel();
        jLabel2 = new JLabel();
        jLabel3 = new JLabel();
        jTextField1 = new JTextField();
        jPasswordField1 = new JPasswordField();
        jButton1 = new JButton();
        contentPane = (JPanel)this.getContentPane();

        //
        // jLabel1
        //
        jLabel1.setHorizontalAlignment(SwingConstants.LEFT);
        jLabel1.setForeground(new Color(0, 0, 100));
        jLabel1.setText("username:");
        //
        // jLabel2
        //
        jLabel2.setHorizontalAlignment(SwingConstants.LEFT);
        jLabel2.setForeground(new Color(0, 0, 255));
        jLabel2.setText("password:");
        //
        // jLabel3
        //
        jLabel3.setHorizontalAlignment(SwingConstants.LEFT);
        jLabel3.setForeground(new Color(0, 0, 255));
        jLabel3.setText("Welcome to COMCAT Software Engineers");
        //
        // jTextField1
        //
        jTextField1.setForeground(new Color(0, 0, 255));
        jTextField1.setSelectedTextColor(new Color(0, 0, 255));
        jTextField1.setToolTipText("Enter your username");
        jTextField1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e)
            {
                jTextField1_actionPerformed(e);
            }

        });
        //
        // jPasswordField1
        //
        jPasswordField1.setForeground(new Color(0, 0, 255));
        jPasswordField1.setToolTipText("Enter your password");
        jPasswordField1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e)
            {
                jPasswordField1_actionPerformed(e);
            }

        });
        
        //
        // jButton1
        //
        jButton1.setBackground(new Color(204, 204, 204));
        jButton1.setForeground(new Color(0, 0, 255));
        jButton1.setText("Login");
        jButton1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e)
            {
                jButton1_actionPerformed(e);
            }
            
        });
        
        //
        //creates menubar for frame
        //
            JMenuBar menuBar = new JMenuBar();
            
        //
        //adds the menubar to the frame
        //
            setJMenuBar(menuBar);
            
        //
        //define and add two drop down menu to the menubar
        //
            JMenu fileMenu = new JMenu("File");
            JMenu editMenu = new JMenu("Edit");
            menuBar.add(fileMenu);
            menuBar.add(editMenu);
            
        //
        //create and add simple menu item to one of the drop down menu
        //
            JMenuItem newAction = new JMenuItem("New");
            JMenuItem openAction = new JMenuItem("Open");
            JMenuItem exitAction = new JMenuItem("Exit");
            JMenuItem cutAction = new JMenuItem("Cut");
            JMenuItem copyAction = new JMenuItem("Copy");
            JMenuItem pasteAction = new JMenuItem("Paste");
            
        //
        //adding menubar
        //
        fileMenu.add(newAction);
        fileMenu.add(openAction);
        fileMenu.addSeparator();
        fileMenu.add(exitAction);
        editMenu.add(cutAction);
        editMenu.add(copyAction);
        editMenu.add(pasteAction);
        editMenu.addSeparator();
       
        
            
        //
        // contentPane
        //
        contentPane.setLayout(null);
        contentPane.setBorder(BorderFactory.createEtchedBorder());
        contentPane.setBackground(new Color(76, 200, 155));
        addComponent(contentPane, jLabel1, 1000,600,106,18);
        addComponent(contentPane, jLabel2, 1000,650,97,18);
        addComponent(contentPane, jLabel3, 350,20,970,180);
        addComponent(contentPane, jTextField1, 1000,620,183,22);
        addComponent(contentPane, jPasswordField1, 1000,670,183,22);
        addComponent(contentPane, jButton1, 1000,700,83,28);
        //
        // login
        //
        this.setTitle("COMCAT Software Engineering");
        this.setLocation(new Point(76, 182));
        this.setSize(new Dimension(1200, 800));
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        this.setResizable(false);
    }

    /** Add Component Without a Layout Manager (Absolute Positioning) */
    private void addComponent(Container container,Component c,int x,int y,int width,int height)
    {
        c.setBounds(x,y,width,height);
        container.add(c);
    }

    
    private void jTextField1_actionPerformed(ActionEvent e)
    {
        

    }

    private void jPasswordField1_actionPerformed(ActionEvent e)
    {
        
    }

    private void jButton1_actionPerformed(ActionEvent e)
    {
        System.out.println("\njButton1_actionPerformed(ActionEvent e) called.");
        String username = new String(jTextField1.getText());
        String password = new String(jPasswordField1.getText());
        
        if(username.equals("") || password.equals("")) // If password and username is empty > Do this >>>
                {
                    jButton1.setEnabled(false);
                JLabel errorFields = new JLabel("<HTML><FONT COLOR = Blue>You must enter a username and password to login.</FONT></HTML>"); 
                JOptionPane.showMessageDialog(null,errorFields); 
                jTextField1.setText("");
                jPasswordField1.setText("");
                jButton1.setEnabled(true);
                this.setVisible(true);
                }
                else
                {
        JLabel optionLabel = new JLabel("<HTML><FONT COLOR = Blue>You entered</FONT><FONT COLOR = RED> <B>"+username+"</B></FONT> <FONT COLOR = Blue>as your username.<BR> Is this correct?</FONT></HTML>");
int confirm =JOptionPane.showConfirmDialog(null,optionLabel);
switch(confirm){       // Switch > Case
        case JOptionPane.YES_OPTION:  // Attempt to Login user
        jButton1.setEnabled(false);   // Set button enable to false to prevent 2 login attempts
        break;

            case JOptionPane.NO_OPTION:   // No Case.(Go back. Set text to 0)
            jButton1.setEnabled(false);
            jTextField1.setText("");
            jPasswordField1.setText("");
            jButton1.setEnabled(true);
            break;
            
            case JOptionPane.CANCEL_OPTION:  // Cancel Case.(Go back. Set text to 0)
            jButton1.setEnabled(false);
            jTextField1.setText("");
            jPasswordField1.setText("");
            jButton1.setEnabled(true);
            break;
        
        }   // End Switch > Case
           
      
       }
       }
        


    



    public static void main(String[] args)
    {
        JFrame.setDefaultLookAndFeelDecorated(true);
        JDialog.setDefaultLookAndFeelDecorated(true);
        try
        {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        }
        catch (Exception ex)
        {
            System.out.println("Failed loading L&F: ");
            System.out.println(ex);
        }
        new login();
    };



}

what i dont know how to do and the forums kinda confusing me is this.
I want to be able to create a txt to serve as my database then call that txt that has all the information to use in the login pane so that i can verify the username and password part... another group memeber is doing the login thing

Do you have to use a .txt file? In my experience(I don't have that much though ^^), using SQL or even MS Access is so much easier.

If you want to use a .txt file, and you find databases difficult find examples on how to read files in this forum using the Scanner class or the BufferedReader class.
After you read the file into a Vector or ArrayList check the username and password entered to see if they exist in the data read from the file.

For databases and how to login, check the jsp forum. There is an example on top called MVC. You can read and take the database and validation part.

adding pictures wud be awesome...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.