i need help with building the controller by using MVC pattern
view 1
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class BankView {
JFrame frame;
JPanel one, two;
BankSaving saving = new BankSaving();
BankCurrent current = new BankCurrent();
BankView(){
frame = new JFrame();
one = new JPanel();
JButton b1 = new JButton("Add Account");
b1.addActionListener( new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
frame.setContentPane(two);
two.revalidate();
}
});
JButton b2 = new JButton("Display");
b2.addActionListener( new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
frame.setContentPane(one);
two.revalidate();
}
});
JButton b3 = new JButton("Exit");
b3.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
});
one.add(b1);
one.add(b2);
one.add(b3);
two = new JPanel();
JButton b4 = new JButton("Saving Account");
b4.addActionListener( new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
frame.setContentPane( saving.getContentPane());
two.revalidate(); }
});
JButton b5 = new JButton("Current Account");
b5.addActionListener( new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
frame.setContentPane(current.getContentPane());
two.revalidate();
}
});
two.add(b4);
two.add(b5);
frame.setContentPane(one);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
view saving
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class BankSaving extends JFrame
{
private static final int WIDTH = 500;
private static final int HEIGHT = 400;
private JLabel icL, nameL, addressL,dobL,openL,accL,balanceL;
private JTextField icTF, nameTF, addressTF,dobTF,openTF,accTF,balanceTF;
private JButton inputB, exitB;
//Button handlers:
private ExitButtonHandler ebHandler;
public BankSaving()
{
icL = new JLabel("Customer IC No: ", SwingConstants.RIGHT);
nameL = new JLabel("Customer Name: ", SwingConstants.RIGHT);
addressL = new JLabel("Customer Address: ", SwingConstants.RIGHT);
dobL = new JLabel("Date of Birth: ", SwingConstants.RIGHT);
openL = new JLabel("Date of Account Opening: ", SwingConstants.RIGHT);
accL = new JLabel("Account No: ", SwingConstants.RIGHT);
balanceL = new JLabel("Balance: ", SwingConstants.RIGHT);
icTF = new JTextField(10);
nameTF = new JTextField(10);
addressTF = new JTextField(10);
dobTF = new JTextField(10);
openTF = new JTextField(10);
accTF = new JTextField(10);
balanceTF = new JTextField(10);
inputB = new JButton("Save");
exitB = new JButton("Exit");
ebHandler = new ExitButtonHandler();
exitB.addActionListener(ebHandler);
Container pane = getContentPane();
pane.setLayout(new GridLayout(8,2));
//panel menu
pane.add(icL);
pane.add(icTF);
pane.add(nameL);
pane.add(nameTF);
pane.add(addressL);
pane.add(addressTF);
pane.add(dobL);
pane.add(dobTF);
pane.add(openL);
pane.add(openTF);
pane.add(accL);
pane.add(accTF);
pane.add(balanceL);
pane.add(balanceTF);
pane.add(inputB);
pane.add(exitB);
setSize(WIDTH, HEIGHT);
setVisible(false);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public String geticTF() {
return icTF.getText();
}
public String getnameTF() {
return nameTF.getText();
}
public String getaddressTF() {
return dobTF.getText();
}
public String getdobTF() {
return dobTF.getText();
}
public String getopenTF() {
return openTF.getText();
}
public String getaccTF() {
return accTF.getText();
}
public String getbalanceTF() {
return balanceTF.getText();
}
public class ExitButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
}
controller
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class BankController {
private BankModel model;
private BankSaving view;
private BankCurrent vieww;
public BankController(BankModel m, BankSaving s, BankSaving c) {
this.model = m;
this.view = s;
this.view = c;
}
}
im stuck here, how i suppose to build a controller?