Hi All,
I know this is probably a really basic question, however, I am making my first entry into Java programming and I am struggling a little with the coding and errors I'm getting.
My main issue is with this piece of code:
It tells me that getText() is deprecated, but a) I'm not sure exactly what that means and b) what I'm supposed to do about it.
Also, if someone has a second, can you have a look over my code and see if I am doing this to the proper standards or have I missed something simple.
Many thanks for ANY help or support you can provide. I'm new to Java, have done some eTraining, but it's still a mystery.
Truely, Many Thanks,
Fitz
Fitz
Did you know, there are 10 types of people in this world:
* Those who understand binary
and
* Those who Don't!!
I know this is probably a really basic question, however, I am making my first entry into Java programming and I am struggling a little with the coding and errors I'm getting.
My main issue is with this piece of code:
Code:
if(txtPassword.getText().equals("")||txtPassword.getText().equals(null))
It tells me that getText() is deprecated, but a) I'm not sure exactly what that means and b) what I'm supposed to do about it.
Also, if someone has a second, can you have a look over my code and see if I am doing this to the proper standards or have I missed something simple.
Code:
package Forms;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JPasswordField;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.Color;
import javax.swing.SwingConstants;
public class frmLogon {
private JFrame frmLogon;
private JTextField txtUserID;
private JPasswordField txtPassword;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
frmLogon window = new frmLogon();
window.frmLogon.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public frmLogon() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frmLogon = new JFrame();
frmLogon.setTitle("Logon");
frmLogon.setBounds(100, 100, 253, 171);
frmLogon.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frmLogon.getContentPane().setLayout(null);
txtUserID = new JTextField();
txtUserID.setBounds(77, 11, 152, 20);
frmLogon.getContentPane().add(txtUserID);
txtUserID.setColumns(10);
txtPassword = new JPasswordField();
txtPassword.setBounds(77, 42, 152, 20);
frmLogon.getContentPane().add(txtPassword);
JLabel lblUserId = new JLabel("User ID:");
lblUserId.setBounds(10, 14, 57, 14);
frmLogon.getContentPane().add(lblUserId);
JLabel lblPassword = new JLabel("Password:");
lblPassword.setBounds(10, 42, 57, 14);
frmLogon.getContentPane().add(lblPassword);
final JLabel lblError = new JLabel(" ");
lblError.setHorizontalAlignment(SwingConstants.CENTER);
lblError.setForeground(Color.RED);
lblError.setBounds(10, 73, 219, 14);
frmLogon.getContentPane().add(lblError);
JButton btnLogon = new JButton("Logon");
btnLogon.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
//public final Boolean isEmpty()
if(txtUserID.getText().equals("")||txtUserID.getText().equals(null))
{
System.out.println("No User ID");
lblError.setText("Please Enter A User ID");
}
else
{
if(txtPassword.getText().equals("")||txtPassword.getText().equals(null))
{
System.out.println("No Password");
lblError.setText("Please Enter A Password");
}
else
{
System.out.println("This is the value: xx" + txtUserID.getText() + "xx");
System.out.println("This is the value: xx" + txtPassword.getText() + "xx");
lblError.setText(" ");
}
}
}
});
btnLogon.setBounds(20, 98, 89, 23);
frmLogon.getContentPane().add(btnLogon);
JButton btnQuit = new JButton("Quit");
btnQuit.setBounds(119, 98, 89, 23);
frmLogon.getContentPane().add(btnQuit);
}
}
Many thanks for ANY help or support you can provide. I'm new to Java, have done some eTraining, but it's still a mystery.
Truely, Many Thanks,
Fitz
Fitz
Did you know, there are 10 types of people in this world:
* Those who understand binary
and
* Those who Don't!!