Nu fungerar det bra
https://i.imgur.com/xc1X0Tc.jpg
och sedan efter kunden är skapad och inputfälten rensas:
https://i.imgur.com/VbzXuBI.jpg
Sedan hur man gör samma för kortnr får du klura på själv
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Bankapplikation {
private Controller controller;
private Kundregister kundregister;
private JLabel lblNewLabel_1;
private JFrame frame;
private JButton btnRemoveCustomer;
private JButton btnAddCustomer;
private JTextField customerNameTextField;
private JTextField customerNbrTextField;
private JTextField CardNbrTextField;
private JTextField cardTypeTextField;
/**
* Launch the application.
*/
/**
* Create the application.
*/
public Bankapplikation() {
initialize(); }
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JLabel lblNamn = new JLabel("Namn:");
lblNamn.setBounds(6, 16, 61, 16);
frame.getContentPane().add(lblNamn);
JLabel lblKundnr = new JLabel("Kundnr:");
lblKundnr.setBounds(6, 44, 61, 16);
frame.getContentPane().add(lblKundnr);
JLabel lblNewKund = new JLabel("");
lblNewKund.setBounds(220, 44, 80, 16);
frame.getContentPane().add(lblNewKund);
kundregister = new Kundregister();
controller = new Controller (kundregister, frame);
customerNameTextField = new JTextField();
customerNameTextField.setBounds(58, 11, 130, 26);
frame.getContentPane().add(customerNameTextField);
customerNameTextField.setColumns(10);
customerNbrTextField = new JTextField();
customerNbrTextField.setBounds(58, 39, 130, 26);
frame.getContentPane().add(customerNbrTextField);
customerNbrTextField.setColumns(10);
//ADD COSTUMER --------------------------------------------------------------
btnAddCustomer = new JButton("Lägg till kund");
btnAddCustomer.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String nbr = customerNbrTextField.getText(); {
String name = customerNameTextField.getText(); {
String cardN = CardNbrTextField.getText(); {
String cardT = cardTypeTextField.getText(); {
controller.addCustomer(nbr, name, cardN, cardT);
lblNewKund.setText("Kund tillagd");
customerNbrTextField.setText("");
customerNameTextField.setText("");
}
}
}
}
}
});
btnAddCustomer.setBounds(0, 72, 117, 29);
frame.getContentPane().add(btnAddCustomer);
//REMOVE CUSTOMER--------------------------------------------------------------
btnRemoveCustomer = new JButton("Ta bort kund");
btnRemoveCustomer.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String cNumberFind = customerNbrTextField.getText(); {
String [] tmpCustomer = controller.findCustomer(cNumberFind);
lblNewLabel_1 = new JLabel("");
if (tmpCustomer !=null) {
controller.removeCustomer(cNumberFind);
lblNewLabel_1.setText("Kund borttagen");
} else {
lblNewLabel_1.setText("Kund hittades inte");
}
}
}
});
btnRemoveCustomer.setBounds(107, 72, 117, 29);
frame.getContentPane().add(btnRemoveCustomer);
//FIND CUSTOMER-------------------------------------------------------
JButton btnFindCustomer = new JButton("Hitta kund");
btnFindCustomer.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String cNumberFind = customerNbrTextField.getText(); {
String [] aCust = controller.findCustomer(cNumberFind);
if (aCust !=null) {
lblNewLabel_1 = new JLabel("");
lblNewLabel_1.setText("Kund hittad");
if (aCust.length==4) {
customerNbrTextField.setText(aCust[0]);
customerNameTextField.setText(aCust[1]);
cardTypeTextField.setText(aCust[2]);
CardNbrTextField.setText(aCust[3]);
}else if (aCust.length==2) {
customerNbrTextField.setText(aCust[0]);
customerNameTextField.setText(aCust[1]);
cardTypeTextField.setText("");
CardNbrTextField.setText("");
}
}
}
}
});
btnFindCustomer.setBounds(216, 72, 117, 29);
frame.getContentPane().add(btnFindCustomer);
JButton btnNewName = new JButton("Nytt namn");
btnNewName.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String cNumber = customerNbrTextField.getText();
String [] aCustomer = controller.findCustomer(cNumber);
if(aCustomer!=null) {
lblNewLabel_1 = new JLabel("");
lblNewLabel_1.setText("Välj ett nytt namn");
String newCName = customerNameTextField.getText();
controller.updateCustomerName(cNumber, newCName);
}
}
});
btnNewName.setBounds(327, 72, 117, 29);
frame.getContentPane().add(btnNewName);
JLabel lblKortnr = new JLabel("Kortnr:");
lblKortnr.setBounds(6, 113, 61, 16);
frame.getContentPane().add(lblKortnr);
JLabel lblKorttyp = new JLabel("Korttyp:");
lblKorttyp.setBounds(6, 147, 61, 16);
frame.getContentPane().add(lblKorttyp);
CardNbrTextField = new JTextField();
CardNbrTextField.setBounds(58, 108, 130, 26);
frame.getContentPane().add(CardNbrTextField);
CardNbrTextField.setColumns(10);
cardTypeTextField = new JTextField();
cardTypeTextField.setBounds(58, 142, 130, 26);
frame.getContentPane().add(cardTypeTextField);
cardTypeTextField.setColumns(10);
JButton btnAddCard = new JButton("Lägg till kort");
btnAddCard.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
btnAddCard.setBounds(0, 175, 111, 29);
frame.getContentPane().add(btnAddCard);
JButton btnRemoveCard = new JButton("Ta bort kort");
btnRemoveCard.setBounds(107, 175, 117, 29);
frame.getContentPane().add(btnRemoveCard);
JButton btnFindCard = new JButton("Hitta kort");
btnFindCard.setBounds(216, 175, 117, 29);
frame.getContentPane().add(btnFindCard);
JLabel lblNewLabel_1 = new JLabel("New label");
lblNewLabel_1.setBounds(216, 256, 61, 16);
frame.getContentPane().add(lblNewLabel_1);
}
//ENTRY-POINT
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Bankapplikation window = new Bankapplikation();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
wow va grymt!! tack så mycket för din hjälp!!