0% found this document useful (0 votes)
2 views8 pages

JVL Exp8

The document contains two Java GUI applications: one for a login dialog (MHSSCE) and another for a bank account application. The MHSSCE class implements a login interface with fields for ID and password, while the BankAccountApplication class provides a user interface for managing bank accounts, including options for deposit, withdrawal, and transfer. Both applications utilize Swing components for their graphical interfaces.

Uploaded by

Arfia Ansari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views8 pages

JVL Exp8

The document contains two Java GUI applications: one for a login dialog (MHSSCE) and another for a bank account application. The MHSSCE class implements a login interface with fields for ID and password, while the BankAccountApplication class provides a user interface for managing bank accounts, including options for deposit, withdrawal, and transfer. Both applications utilize Swing components for their graphical interfaces.

Uploaded by

Arfia Ansari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

/*

* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to
change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JDialog.java to edit this
template
*/
package com.mycompany.mygui;

/**
*
* @author apple
*/
public class MHSSCE extends javax.swing.JDialog {

/**
* Creates new form MHSSCE
*/
public MHSSCE(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
}

/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jLabel1 = new javax.swing.JLabel();


jLabel2 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jLabel3 = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("MHSSCE LOGIN PAGE");

jLabel1.setText("Enter ID");

jLabel2.setText("Password");

jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});

jButton1.setText("Login");

jButton2.setText("Cancel");

jLabel3.setText("forgot password? reset");

javax.swing.GroupLayout layout = new


javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING)
.addGroup(layout.createSequentialGroup()
.addGap(98, 98, 98)
.addComponent(jButton1)
.addGap(40, 40, 40)
.addComponent(jButton2))
.addGroup(layout.createSequentialGroup()
.addGap(76, 76, 76)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment
.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2))
.addGap(54, 54, 54)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment
.LEADING)
.addComponent(jLabel3)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignme
nt.LEADING, false)
.addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE,
180, Short.MAX_VALUE)
.addComponent(jTextField1)))))
.addContainerGap(32, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(73, 73, 73)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BA
SELINE)
.addComponent(jLabel1)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(27, 27, 27)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TR
AILING)
.addComponent(jLabel2)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel3)
.addGap(32, 32, 32)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BA
SELINE)
.addComponent(jButton1)
.addComponent(jButton2))
.addContainerGap(76, Short.MAX_VALUE))
);

pack();
}// </editor-fold>

private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
String uID="mhssce";
String pass="saboo";
String userID = jTextField1.getText() .toString();
String userpass=jTextField2.getText() .toString();
if (uID.equals(userID) && (pass.equals(userpass)))
{
jLabel3.setText("Login Successfully");
}
else
{
jLabel3.setText("Login Failed");
}
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional)
">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and
feel.
* For details see
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {

java.util.logging.Logger.getLogger(MHSSCE.class.getName()).log(java.util.logging.Level
.SEVERE, null, ex);
} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(MHSSCE.class.getName()).log(java.util.logging.Level
.SEVERE, null, ex);
} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(MHSSCE.class.getName()).log(java.util.logging.Level
.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(MHSSCE.class.getName()).log(java.util.logging.Level
.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the dialog */


java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
MHSSCE dialog = new MHSSCE(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}

// Variables declaration - do not modify


private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
// End of variables declaration
}

b. Bank User UI with AWT/ Swing API.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class BankAccountApplication extends JFrame implements ActionListener {
private JComboBox<String> accountNumberComboBox;
private JTextField openDateTextField, customerNameTextField, balanceTextField;
private JButton depositButton, withdrawButton, transferButton, exitButton;
public BankAccountApplication() {
// Set up the main frame
setTitle("Bank Account Application");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new GridBagLayout());
// Create and add components
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(5, 5, 5, 5);
// Account Number
gbc.gridx = 0;
gbc.gridy = 0;
add(new JLabel("Account Number:"), gbc);
gbc.gridx = 1;
String[] accountNumbers = {"1231", "1232", "1233"}; // Replace with actual account
numbers
accountNumberComboBox = new JComboBox<>(accountNumbers);
add(accountNumberComboBox, gbc)
// Open Date
gbc.gridx = 0;
gbc.gridy = 1;
add(new JLabel("Open Date:"), gbc);
gbc.gridx = 1;
openDateTextField = new JTextField(20);
add(openDateTextField, gbc);
// Customer Name
gbc.gridx = 0;
gbc.gridy = 2;
add(new JLabel("Customer Name:"), gbc);
gbc.gridx = 1;
customerNameTextField = new JTextField(20);
add(customerNameTextField, gbc);
// Balance
gbc.gridx = 0;
gbc.gridy = 3;
add(new JLabel("Balance:"), gbc);
gbc.gridx = 1;
balanceTextField = new JTextField(20);
balanceTextField.setEditable(false); // Make balance field read-only
add(balanceTextField, gbc);
// Buttons
gbc.gridx = 0;
gbc.gridy = 4;
gbc.gridwidth = 2;
add(depositButton = new JButton("Deposit"), gbc);
gbc.gridy = 5;
add(withdrawButton = new JButton("Withdraw"), gbc);
gbc.gridy = 6;
add(transferButton = new JButton("Transfer To"), gbc);
gbc.gridy = 7;
add(exitButton = new JButton("Exit"), gbc);
// Add event listeners
depositButton.addActionListener(this);
withdrawButton.addActionListener(this);
transferButton.addActionListener(this);
exitButton.addActionListener(this);
// Set frame size and visibility
pack();
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e)
if (e.getSource() == depositButton) {
// Handle deposit action
// ...
} else if (e.getSource() == withdrawButton) {
// Handle withdraw action
// ...
} else if (e.getSource() == transferButton) {
// Handle transfer action
// ...
} else if (e.getSource() == exitButton) {
System.exit(0);
}
}

public static void main(String[] args) {


new BankAccountApplication();
}
}

You might also like