Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package loginapp;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.*;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- public class Login_App extends JFrame {
- public static void main(String[] args) {
- JFrame frame = new JFrame("Mo Garage Login");
- //frame setup
- frame.setSize(500, 600);
- frame.setVisible(true);
- //Label and Text boxes
- JLabel usernamelbl = new JLabel("Username");
- usernamelbl.setBounds(100,100, 100,20);
- frame.add(usernamelbl);
- frame.setLayout(null);
- frame.setVisible(true);
- JLabel passwordlbl = new JLabel("Password");
- passwordlbl.setBounds(100,200,100,20);
- frame.add(passwordlbl);
- frame.setLayout(null);
- frame.setVisible(true);
- JTextField username = new JTextField();
- username.setBounds(200,100,100,20);
- frame.add(username);
- frame.setLayout(null);//using no layout managers
- frame.setVisible(true);
- JPasswordField pass = new JPasswordField();
- pass.setBounds(200,200,100,20);
- frame.add(pass);
- frame.setLayout(null);
- frame.setVisible(true);
- //Buttons
- JButton log=new JButton("Login");
- log.setBounds(200,500,100,40);
- frame.add(log);
- frame.setLayout(null);//using no layout managers
- frame.setVisible(true);
- //login button action
- log.addActionListener(new ActionListener() {
- public void actionPerformed (ActionEvent arg0) {
- String uname=username.getText();
- String passwd=pass.getText();
- if (uname.equals("") && passwd.equals(""))
- {
- JOptionPane.showMessageDialog(frame, "Login Successfull");
- MainMenu mainmenu =new MainMenu();
- mainmenu.setVisible(true);
- frame.setVisible(false);
- }
- else {
- JOptionPane.showMessageDialog(frame, "Incorrect Credentials");
- }
- }
- }
- );
- JButton clear=new JButton("Clear");
- clear.setBounds(50,500,100,40);
- frame.add(clear);
- frame.setLayout(null);
- frame.setVisible(true);
- //clear button action
- clear.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- username.setText("");
- pass.setText("");
- }
- }
- );
- }
- }
- package loginapp;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.*;
- public class MainMenu extends JFrame {
- public static void main(String[] args) {
- JFrame frame= new JFrame("Main Menu");
- frame.setSize(500,600);
- frame.setVisible(true);
- JButton client= new JButton("Add new Client");
- client.setBounds(200,100,120,30);
- frame.add(client);
- frame.setLayout(null);
- frame.setVisible(true);
- JButton Mod= new JButton("Update Database");
- Mod.setBounds(190,200,140,30);
- frame.add(Mod);
- frame.setLayout(null);
- frame.setVisible(true);
- JButton info= new JButton("Information");
- info.setBounds(200,300,120,30);
- frame.add(info);
- frame.setLayout(null);
- frame.setVisible(true);
- JButton exit= new JButton("Quit");
- exit.setBounds(200,400,120,30);
- frame.add(exit);
- frame.setLayout(null);
- frame.setVisible(true);
- }
- }
Add Comment
Please, Sign In to add comment