
Ayuda programa JAVA
Publicado por Jose Fernando (1 intervención) el 02/06/2016 01:39:58
Hola, necesito algo de ayuda, estoy en un Curso de Java de la universidad y me he quedado algo atascado en esta actividad, y la verdad no se como hacer que al hace click en el boton "entrar" compruebe el programa si hay datos en los paneles de nombre y password. Os paso el codigo que llevo ya hecho para que le echeis un vistazo a ver si sabeis donde esta el fallo, y la actividad que tengo que realizar a ver si podeis darme alguna indicacion de por donde seguir.
CLASE PRIMCIPAL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package imterfaz;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.Component;
import java.awt.Font;
import javax.swing.SwingConstants;
import javax.swing.JPanel;
import java.awt.SystemColor;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class imtro {
private JFrame frame;
private JTextField nombre;
private JTextField password;
private Persona P= null;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
imtro window = new imtro();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public imtro() {
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 lblTrogol = new JLabel("TROGOLS");
lblTrogol.setHorizontalAlignment(SwingConstants.CENTER);
lblTrogol.setFont(new Font("Trebuchet MS", Font.BOLD, 29));
lblTrogol.setAlignmentX(Component.CENTER_ALIGNMENT);
lblTrogol.setBounds(78, 0, 259, 50);
frame.getContentPane().add(lblTrogol);
JLabel lblAutorJoseFer = new JLabel("Autor: Jose Fernando N\u00FA\u00F1ez Gata");
lblAutorJoseFer.setBounds(116, 45, 183, 28);
frame.getContentPane().add(lblAutorJoseFer);
JPanel panel = new JPanel();
panel.setBackground(SystemColor.activeCaption);
panel.setBounds(32, 77, 380, 111);
frame.getContentPane().add(panel);
panel.setLayout(null);
JLabel lblLogi = new JLabel("Login");
lblLogi.setFont(new Font("Tahoma", Font.BOLD, 11));
lblLogi.setBounds(166, 11, 46, 14);
panel.add(lblLogi);
JLabel lblNewLabel = new JLabel("Nombre");
lblNewLabel.setBounds(10, 38, 46, 14);
panel.add(lblNewLabel);
JLabel lblPassword = new JLabel("Password");
lblPassword.setBounds(10, 77, 46, 14);
panel.add(lblPassword);
nombre = new JTextField();
nombre.setBounds(80, 35, 202, 20);
panel.add(nombre);
nombre.setColumns(10);
password = new JTextField();
password.setBounds(79, 74, 203, 20);
panel.add(password);
password.setColumns(10);
JButton btnNewButton = new JButton("Entrar");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
}
});
btnNewButton.addMouseListener(new MouseAdapter() {
});
btnNewButton.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
btnNewButton.setBounds(165, 199, 89, 23);
frame.getContentPane().add(btnNewButton);
JLabel lblNewLabel_1 = new JLabel("Bienvenido");
lblNewLabel_1.setForeground(Color.RED);
lblNewLabel_1.setBounds(187, 237, 79, 14);
frame.getContentPane().add(lblNewLabel_1);
JLabel lblCursoJava = new JLabel("Curso Java");
lblCursoJava.setForeground(Color.GRAY);
lblCursoJava.setBounds(353, 221, 59, 14);
frame.getContentPane().add(lblCursoJava);
JLabel lblNewLabel_2 = new JLabel("Universidad de Extremadura");
lblNewLabel_2.setForeground(Color.GRAY);
lblNewLabel_2.setBounds(276, 237, 136, 14);
frame.getContentPane().add(lblNewLabel_2);
}
}
CLASE PERSOMA
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package imterfaz;
public class Persona {
private Informacion Datos=null;
//Constructor
public String EntrarDatos()
{
String cad;
if(this.Datos!=null)
cad=Datos.Nombre()+" "+Datos.Contrasena();
else
cad="Error.";
return(cad);
}
}
clase imformaciom
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package imterfaz;
public class Informacion {
private String contrasena,nombre;
Informacion(String contrasena,String nombre)
{
this.contrasena=contrasena;
this.nombre=nombre;
}
public String Nombre()
{
return(this.nombre);
}
public String Contrasena()
{
return(this.contrasena);
}
}
- Sesion-1.rar(1,9 MB)
Valora esta pregunta


0