Salve pessoal do GUJ…
Tenho uma classe abaixo representando a VIEW da arquitetura MVC:
1. package telas;
2.
3. import logico.*;
4.
5. import javax.swing.*;
6. import java.awt.*;
7. import java.awt.event.*;
8. import javax.swing.border.*;
9. import banco.*;
10.
11.
12.
13. public class TelaLogin extends JFrame
14. {
15.
16.
17. /**
18. *
19. */
20. private static final long serialVersionUID = 1L;
21. private JTextField txtUsuario;
22. private JPasswordField txtSenha;
23. private JButton entrar, cancelar;
24.
25. public TelaLogin()
26. {
27.
28. super("...");
29.
30. Container tela = getContentPane();
31.
32. BorderLayout layout = new BorderLayout();
33. tela.setLayout(layout);
34.
35. Color cor1 = new Color(139,10,80);
36.
37.
38. JLabel lblUsuario = new JLabel("Usuario:");
39. lblUsuario.setForeground(cor1);
40. JLabel lblSenha = new JLabel("Senha:");
41. lblSenha.setForeground(cor1);
42. txtUsuario = new JTextField(10);
43. txtSenha = new JPasswordField(10);
44.
45. JPanel superior = new JPanel();
46. superior.setLayout(new GridLayout(2, 2, 5, 5));
47. superior.add(lblUsuario);
48. superior.add(txtUsuario);
49. superior.add(lblSenha);
50. superior.add(txtSenha);
51.
52.
53. JPanel superior2 = new JPanel();
54.
55. String titulo = " Informe o Usuario e Senha";
56. Border etched = BorderFactory.createEtchedBorder();
57. Border borda = BorderFactory.createTitledBorder(etched, titulo);
58.
59. superior2.setBorder(borda);
60. superior2.setLayout(new FlowLayout(FlowLayout.LEFT));
61. superior2.add(superior);
62.
63. entrar = new JButton("Entrar ");
64. entrar.setForeground(cor1);
65. getRootPane().setDefaultButton(entrar);
66. entrar.addActionListener(new ActionListener(){
67. public void actionPerformed(ActionEvent e){
68.
69. Usuarios usuarios = new Usuarios();
70.
71. usuarios.setUsuario(txtUsuario.getText());
72. usuarios.setSenha(txtSenha.getText());
73.
74. LogarUsr logarUsr = new LogarUsr();
75. logarUsr.logar();
76.
77. }});
78.
79. cancelar = new JButton("Cancelar");
80. cancelar.setForeground(cor1);
81. cancelar.addActionListener(new ActionListener(){
82. public void actionPerformed(ActionEvent e){
83.
84. String texto = "O Sistema será fechado!";
85. JOptionPane.showMessageDialog(null,texto,"Verifique os Dados Digitados",JOptionPane.WARNING_MESSAGE,null);
86. System.exit(0);
87.
88. }});
89.
90.
91. JPanel inferior = new JPanel();
92. inferior.setLayout(new FlowLayout(FlowLayout.CENTER));
93. inferior.add(entrar);
94. inferior.add(cancelar);
95.
96. tela.add(BorderLayout.NORTH, superior2);
97. tela.add(BorderLayout.SOUTH, inferior);
98.
99. setSize(300,180);
100. setVisible(true);
101. setResizable(false);
102. setLocationRelativeTo(null);
103. }
104.
105. }
Tenho outra classe abaixo representando o MODEL da arquitetura MVC:
1. package logico;
2.
3. public class Usuarios {
4.
5. private String usuario;
6.
7. private String senha;
8.
9. public void setUsuario(String usuario) {
10.
11.
12. }
13.
14. public String getUsuario() {
15. return this.usuario;
16.
17. }
18.
19. public void setSenha(String senha) {
20. this.senha = senha;
21.
22. }
23.
24. public String getSenha() {
25. return this.senha;
26.
27. }
28.
29. }
E por final tenho outra classe representando a CONTROLLER da arquitetura MVC…
1. package banco;
2.
3. import inicial.*;
4. import telas.*;
5. import logico.*;
6. import java.sql.*;
7. import javax.swing.*;
8.
9. public class LogarUsr {
10.
11. private static final long serialVersionUID = 1L;
12.
13. public void logar()
14. {
15.
16. try
17. {
18. ConectarBanco con = new ConectarBanco();
19. con.conectar();
20.
21. String sql = "select * from usuarios where nome='"+"admin"+"' and senha=md5('"+"zero"+"')";
22. ResultSet resultado = con.comando.executeQuery(sql);
23.
24.
25. if(resultado.first()==false)
26. {
27.
28. String texto =" Acesso Negado!";
29. JOptionPane.showMessageDialog(null,texto,"Verifique os Dados Digitados",JOptionPane.ERROR_MESSAGE,null);
30. }
31. else
32. {
33. Main.login.dispose();
34. MenuPrincipal menu = new MenuPrincipal();
35. menu.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
36. }
37.
38. }
39.
40. catch(SQLException eSql)
41. {
42. System.out.println(eSql.getMessage() );
43. }
44.
45.
46. }
47. }
E minha duvida é a seguinte, como passar os parametro da classe TelaLogin(VIEW) para classe LogaUsr(CONTROLLER)???
Obrigado !!!