Skip to content
Snippets Groups Projects
Commit d695e149 authored by jonschi's avatar jonschi
Browse files

hecho vista cambiar pin

parent 3f219ab7
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,8 @@ package componentes;
import javax.swing.JFrame;
import modelo.Cuenta;
import modelo.Datos;
import vista.VistaCambiarPin;
import vista.VistaLogin;
/**
......@@ -17,20 +19,32 @@ public class StateMachine {
private Cuenta modelo;
public StateMachine() {
modelo = new Cuenta();
abrirVentanaLogin();
// abrirVentanaLogin();
// TODO change back
modelo = Datos.findCuentaConPin("2222");
abrirVistaCambiarPin();
}
public void abrirVentanaLogin() {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
private void disposeCurrentVista() {
if (currentState!=null){
currentState.setVisible(false);
currentState.dispose();
}
currentState = new VistaLogin(modelo);
}
public void abrirVentanaLogin() {
java.awt.EventQueue.invokeLater(() -> {
disposeCurrentVista();
currentState = new VistaLogin();
currentState.setVisible(true);
});
}
public void abrirVistaCambiarPin() {
java.awt.EventQueue.invokeLater(() -> {
disposeCurrentVista();
currentState = new VistaCambiarPin(modelo);
currentState.setVisible(true);
});
}
}
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package controlador;
import modelo.Cuenta;
import vista.VistaCambiarPin;
import vista.VistaCambiarPin.Resultado;
/**
*
* @author jonas.schiefner
*/
public class ControladorCambiarPin {
private VistaCambiarPin vista;
private Cuenta cuenta;
public ControladorCambiarPin(VistaCambiarPin vista, Cuenta cuenta) {
this.vista = vista;
this.cuenta = cuenta;
}
public void cambiarPin(String text) {
if (text.length() == 4) {
cuenta.setPin(text);
vista.setResultado(Resultado.EXITO);
} else {
vista.setResultado(Resultado.ERROR);
}
}
}
......@@ -43,6 +43,10 @@ public class Cuenta {
return transaccionesEntrantes;
}
public void setPin(String pin) {
this.pin = pin;
}
public Boolean retirarDinero(int saldo) {
if (saldo > this.saldo || saldo % 10 != 0) {
return false;
......
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="3"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace pref="101" max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="labelResultado" alignment="0" min="-2" pref="406" max="-2" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="108" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="labelTop" min="-2" max="-2" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="64" max="-2" attributes="0"/>
<Component id="labelNuevoPin" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="11" max="-2" attributes="0"/>
<Component id="textFieldPin" min="-2" pref="169" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
<Group type="102" alignment="1" attributes="0">
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="botonVolver" max="32767" attributes="0"/>
<Component id="botonCambiar" min="-2" pref="83" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="159" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace pref="94" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="57" max="-2" attributes="0"/>
<Component id="labelTop" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="71" max="-2" attributes="0"/>
<Component id="labelNuevoPin" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="textFieldPin" min="-2" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="labelResultado" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="169" max="32767" attributes="0"/>
<Component id="botonCambiar" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="botonVolver" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="44" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="labelTop">
<Properties>
<Property name="text" type="java.lang.String" value="Cambia el Pin de su cuenta aqui"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="textFieldPin">
</Component>
<Component class="javax.swing.JLabel" name="labelNuevoPin">
<Properties>
<Property name="text" type="java.lang.String" value="Nuevo Pin:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="labelResultado">
<Properties>
<Property name="horizontalAlignment" type="int" value="0"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="botonVolver">
<Properties>
<Property name="text" type="java.lang.String" value="Volver"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="botonVolverActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="botonCambiar">
<Properties>
<Property name="text" type="java.lang.String" value="Cambiar"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="botonCambiarActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Form>
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
*/
package vista;
import componentes.Main;
import controlador.ControladorCambiarPin;
import java.awt.Color;
import modelo.Cuenta;
/**
*
* @author jonas.schiefner
*/
public class VistaCambiarPin extends javax.swing.JFrame {
public enum Resultado {
EXITO, ERROR
}
ControladorCambiarPin controlador;
private static Color colorLabelDefecto;
private static Color colorError = new Color(255, 0, 0);
/**
* Creates new form VistaCambiarPin
*/
public VistaCambiarPin(Cuenta cuenta) {
initComponents();
controlador = new ControladorCambiarPin(this, cuenta);
colorLabelDefecto = labelResultado.getForeground();
}
/**
* 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">//GEN-BEGIN:initComponents
private void initComponents() {
labelTop = new javax.swing.JLabel();
textFieldPin = new javax.swing.JTextField();
labelNuevoPin = new javax.swing.JLabel();
labelResultado = new javax.swing.JLabel();
botonVolver = new javax.swing.JButton();
botonCambiar = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
labelTop.setText("Cambia el Pin de su cuenta aqui");
labelNuevoPin.setText("Nuevo Pin:");
labelResultado.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
botonVolver.setText("Volver");
botonVolver.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
botonVolverActionPerformed(evt);
}
});
botonCambiar.setText("Cambiar");
botonCambiar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
botonCambiarActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap(101, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(labelResultado, javax.swing.GroupLayout.PREFERRED_SIZE, 406, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGap(108, 108, 108)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(labelTop)
.addGroup(layout.createSequentialGroup()
.addGap(64, 64, 64)
.addComponent(labelNuevoPin))
.addGroup(layout.createSequentialGroup()
.addGap(11, 11, 11)
.addComponent(textFieldPin, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(botonVolver, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(botonCambiar, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(159, 159, 159)))
.addContainerGap(94, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(57, 57, 57)
.addComponent(labelTop)
.addGap(71, 71, 71)
.addComponent(labelNuevoPin)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(textFieldPin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(labelResultado)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 169, Short.MAX_VALUE)
.addComponent(botonCambiar)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(botonVolver)
.addGap(44, 44, 44))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void botonVolverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonVolverActionPerformed
Main.getStateMachine().abrirVentanaLogin();
}//GEN-LAST:event_botonVolverActionPerformed
private void botonCambiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonCambiarActionPerformed
controlador.cambiarPin(textFieldPin.getText());
}//GEN-LAST:event_botonCambiarActionPerformed
public void setResultado(Resultado resultado) {
switch (resultado) {
case EXITO: {
labelResultado.setForeground(colorLabelDefecto);
labelResultado.setText("Hecho");
break;
} case ERROR: {
labelResultado.setForeground(colorError);
labelResultado.setText("El pin debe ser exactamente de 4 letras");
break;
}
}
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton botonCambiar;
private javax.swing.JButton botonVolver;
private javax.swing.JLabel labelNuevoPin;
private javax.swing.JLabel labelResultado;
private javax.swing.JLabel labelTop;
private javax.swing.JTextField textFieldPin;
// End of variables declaration//GEN-END:variables
}
......@@ -4,21 +4,18 @@
*/
package vista;
import modelo.Cuenta;
/**
*
* @author jonas.schiefner
*/
public class VistaLogin extends javax.swing.JFrame {
private Cuenta modelo;
/**
* Creates new form VistaPin
*/
public VistaLogin(Cuenta modelo) {
public VistaLogin() {
initComponents();
this.modelo = modelo;
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment