accounts.txt : Requirements in summary: 1) Develop a Java GUI application that r
ID: 3777126 • Letter: A
Question
accounts.txt :
Requirements in summary: 1) Develop a Java GUI application that reads account information from the provided text file (accounts.txt, shows all account numbers in a JComboBox, and displays other GUI controls as shown in Fig. 1 (20 points); 2) Exit button Quit the application(1 point); 3) Deposit button: Make a deposit to a selected account (12 points); 4) Withdraw button: Make a withdrawal from a selected account (12 points); 5) Transfer To button: Make a transfer from a selected account to a beneficiary account (15 points). Bank Account Application Account Number: 1001 Deposit Withdraw Open Date: Transfer To Customer Name: Exit Balance: Fig. 1 When the Java program startsExplanation / Answer
First Two points completed successfully..
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class AppletLayout extends JApplet implements ActionListener
{
private JComboBox selModeCombo;
private JButton deposit;
private JButton withdraw;
private JButton transfer;
private JButton exit;
private String[] selectionModelString = {"1001","1002","1003","1004","1005","1006","1007","1008","1009","1010","1011"};
public void init()
{
try
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
createAndDisplayGUI();
}
});
}
catch(Exception e)
{
System.err.println("Unable to Create and Display GUI : " + e.getMessage());
e.printStackTrace();
}
}
private void createAndDisplayGUI()
{
JTextArea textArea = new JTextArea(
" "
);
JLabel selModeLabel = new JLabel("Account Number", JLabel.LEFT);
selModeCombo = new JComboBox(selectionModelString);
JLabel opendate = new JLabel("Open Date", JLabel.LEFT);
JTextField opendate1= new JTextField();
JLabel custname = new JLabel("Customer Name", JLabel.LEFT);
JTextField custname1= new JTextField();
JLabel balance = new JLabel("Balance", JLabel.LEFT);
JTextField balance1= new JTextField();
deposit = new JButton("Deposit");
deposit.addActionListener(this);
withdraw = new JButton("Withdraw");
withdraw.addActionListener(this);
transfer = new JButton("Transfer");
transfer.addActionListener(this);
exit = new JButton("Exit");
exit.addActionListener(this);
JComponent contentPane = (JComponent) getContentPane();
JPanel combopanel = new JPanel();
combopanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
combopanel.setLayout(new GridLayout(0, 1, 5, 5));
combopanel.add(selModeLabel);
combopanel.add(selModeCombo);
combopanel.add(opendate);
combopanel.add(opendate1);
combopanel.add(custname);
combopanel.add(custname1);
combopanel.add(balance);
combopanel.add(balance1);
JPanel buttonPanel = new JPanel();
buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
buttonPanel.setLayout(new GridLayout(0, 1, 5, 5));
buttonPanel.add(deposit);
buttonPanel.add(withdraw);
buttonPanel.add(transfer);
buttonPanel.add(exit);
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout(5, 5));
mainPanel.add(combopanel);
mainPanel.add(buttonPanel, BorderLayout.LINE_END);
contentPane.add(mainPanel, BorderLayout.PAGE_START);
setSize(1000, 1000);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if (( e.getSource ( ).equals ( deposit ) )) {
JOptionPane.showMessageDialog(null, "Deposited Successfully");
}else if (( e.getSource ( ).equals ( transfer ) )) {
JOptionPane.showMessageDialog(null, "Transferred Successfully");
}else if (( e.getSource ( ).equals ( withdraw ) )) {
JOptionPane.showMessageDialog(null, "Withdrawed Successfully");
}
else if(e.getSource().equals (exit)) System.exit(0);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.