I am a novice programmer and have a basic question against if-else loop. I have a program that only gives else output and does not check my if condition. I guess its a syntax error and I am not able to figure it out.
public class adddeed
{
private User user = new User();
public void showdemo()
{
Form hi = new Form("Deed", BoxLayout.y());
TextField first = new TextField("","Enter Description");
Button b=new Button("Back");
Button g=new Button("Go");
String s=first.getText();
DBHandler db=new DBHandler();
g.addActionListener(e ->
{
if(s.equals(null))
{
Dialog.show(null,"Please Enter a Deed","OK",null);
}
else
{
Dialog.show(null,"Deed Uploaded Successfully","OK",null);
}
});
b.addActionListener(e ->
{
new Home(user).show();
//new adddeed().showdemo();
});
hi.add(first);
hi.add(b);
hi.add(g);
hi.show();
}
}
Expected result should be when I don't enter anything in textfield, and press GO, it should say "please enter a deed." Actual result is every time I press Go whether the textfield is empty or not empty, it shows "Deed Uploaded Successfully".
I was doing it wrong, instead of storing the string in a variable I did it like this
if(first.getText().equals("") )
{
Dialog.show(null,"Please Enter a Deed","OK",null);
}