Eu estou tentando praticar um pouco MVC porém estou com algumas dificuldades
Eu tenho meu controller:
public class ControllerLogin implements ActionListener {
//view
ViewLogin loginView;
FuncionarioDAO funcionario;
public ControllerLogin(FuncionarioDAO f, ViewLogin l) {
loginView = l;
funcionario = f;
actionListener(this);
}
// getters and setters do controller
public ViewLogin getLoginView() {
return loginView;
}
public void setLoginView(ViewLogin loginView) {
this.loginView = loginView;
}
@SuppressWarnings("unused")
@Override
public void actionPerformed(ActionEvent e) {
try
{
//retrieve the input from View
@SuppressWarnings("unused")
String a=loginView.getLogin().getText();
@SuppressWarnings("deprecation")
String b=loginView.getPassword().getText();
boolean bx = funcionario.Autenticar(a, b);
}
catch(Exception ee)
{
ee.printStackTrace();
}
}
public void actionListener(ActionListener ae)
{
loginView.getEntrar().addActionListener(ae);
}
}
meu view:
public class ViewLogin extends JFrame {
Container con;
private static final int FRAME_WIDTH = 400;
static final int FRAME_HEIGHT = 350;
static final int FRAME_X_ORIGIN = 150;
static final int FRAME_Y_ORIGIN = 150;
static final int BUTTON_WIDTH = 90;
static final int BUTTON_HEIGHT = 30;
JPanel Logo;
JPanel Items;
JPanel Footer;
JLabel label1,label2;
private JTextField login;
private JPasswordField password;
private JButton entrar;
JButton registrar;
/**
* Create the frame.
*/
public ViewLogin() {
con=getContentPane();
//Set the frame properties
setSize (FRAME_WIDTH, FRAME_HEIGHT);
// setResizable (false);
setTitle ("market v1");
setLocation (FRAME_X_ORIGIN, FRAME_Y_ORIGIN);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout());
setLogin(new JTextField("",10));
setPassword(new JPasswordField("",10));
Items = new JPanel(new GridLayout(3,1));
setEntrar(new JButton("Entrar"));
getEntrar().setBounds(100, 285, BUTTON_WIDTH, BUTTON_HEIGHT);
registrar = new JButton("Registrar");
registrar.setBounds(195, 285, BUTTON_WIDTH, BUTTON_HEIGHT);
label1 = new JLabel();
label1.setText("Username:");
label2 = new JLabel();
label2.setText("Password:");
Items.add(label1);
Items.add(getLogin());
Items.add(label2);
Items.add(getPassword());
Items.add(getEntrar());
Items.add(registrar);
add(Items,BorderLayout.CENTER);
setVisible(true);
}
public JTextField getLogin() {
return login;
}
public void setLogin(JTextField login) {
this.login = login;
}
public JPasswordField getPassword() {
return password;
}
public void setPassword(JPasswordField password) {
this.password = password;
}
public JButton getEntrar() {
return entrar;
}
public void setEntrar(JButton entrar) {
this.entrar = entrar;
}
}
creio que não seja preciso meu model
isso funcionou em partes:
porém os eventos do button eu não sei como por
eu tenho um button entrar que irá validar o login
alguém poderia me ajuda? como adicionar esse evento pelo controller ( e como pegar o que é digitado pelo user .)
