0

I am not getting this program since i beginner to applet programming

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

/*<applet code=Login height=500 width=300></applet>*/

public class Login extends JApplet implements ActionListener
{
JLabel jl1,jl2,jl3,jl4,jl5;
JTextField jt;
JPasswordField jp1,jp2;
JButton jb;
public void init()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
jl1=new JLabel("Username : ");
jl2=new JLabel("Password : ");
jl3=new JLabel("Confirm password : ");
jl4=new JLabel();
jl5=new JLabel();
jt=new JTextField(20);
jp1=new JPasswordField(20);
jp2=new JPasswordField(20);
jb=new JButton("Login");
jb.addActionListener(this);
c.add(jl1);
c.add(jt);
c.add(jl2);
c.add(jp1);
c.add(jl3);
c.add(jp2);
c.add(jb);
c.add(jl4);
c.add(jl5);
}
public void actionPerformed(ActionEvent ae)
{
String s=ae.getActionCommand();
String p1,p2;
if(jp1==jp2)
{
    jl4.setText("Welcome");
}
else
{
    jl4.setText("Password Mismatch");
}
}
}

everytime i check my program it shows else condition
whether password fields are same or different

is there anyone who can help me?

4
Contributors
12
Replies
15
Views
4 Years
Discussion Span
Last Post by vinnitro
Featured Replies
  • 1

    You should use the equals() method to compare Strings. Your if test using == compares two variables to see it they both refer to the same object. You want to get the contents of those objects as Strings and compare them. Read More

  • that's not an error, it's a warning. Read More

  • 1

    > anyway to solve this in this program Please explain what the problem is now. What does the program do that you want to change. Read More

  • 1

    The compiler is asking you to add the -Xlint option to the command line for the compiler so that it will display the full text of all the warning messages. Your program must have some code that the compiler thinks could be a problem. Add the the -Xlint option to … Read More

  • its basically telling you that you are using a deprecated api.. meaning : its an older class or method and that it might cause an error like a buffer overflow... http://www.javacoffeebreak.com/faq/faq0008.html my netbeans says: getText() is "Deprecated. As of Java 2 platform v1.2, replaced by getPassword." for lines 39 & … Read More

1

You should use the equals() method to compare Strings.

Your if test using == compares two variables to see it they both refer to the same object. You want to get the contents of those objects as Strings and compare them.

0

I totally forgot about equals() method concept in java

i got the output thnx for the help

Note: Login.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

how to solve this issue

0
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

/*<applet code=Login height=500 width=300></applet>*/

public class Login extends JApplet implements ActionListener
{
JLabel jl1,jl2,jl3,jl4;
JTextField jt;
JPasswordField jp1,jp2;
JButton jb;
public void init()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
jl1=new JLabel("Username : ");
jl2=new JLabel("Password : ");
jl3=new JLabel("Confirm : ");
jl4=new JLabel();
jt=new JTextField(15);
jp1=new JPasswordField(15);
jp2=new JPasswordField(15);
jb=new JButton("Login");
jb.addActionListener(this);
c.add(jl1);
c.add(jt);
c.add(jl2);
c.add(jp1);
c.add(jl3);
c.add(jp2);
c.add(jb);
c.add(jl4);
}
public void actionPerformed(ActionEvent ae)
{
String s=ae.getActionCommand();
String p1,p2;
p1=jp1.getText();
p2=jp2.getText();
if(p1.equals(p2))
{
    jl4.setText("Welcome, "+jt.getText());
}
else
{
    jl4.setText("Password Mismatch");
}
}
}

but is there anyway to solve this in this program

1

anyway to solve this in this program

Please explain what the problem is now. What does the program do that you want to change.

0

Note: Login.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

this program gives this warning how to solve it

1

The compiler is asking you to add the -Xlint option to the command line for the compiler so that it will display the full text of all the warning messages.
Your program must have some code that the compiler thinks could be a problem.
Add the the -Xlint option to get the full details. Here is the commandline I use for compiling:
F:\Java\jdk1.6.0_29\bin\javac.exe -Xlint -g -deprecation -classpath D:\JavaDevelopment\;.;... SnowMen.java

0

can u plz give me full details since i am new to applet programming
& never seen such kind of error or warning

Comments
NormR1 has already explained what you are asking in this post.
0

F:\Java\jdk1.6.0_29\bin\javac.exe -Xlint ...

Change your compiler command line to include the -Xlint option as shown above.

0

Thnx for the help NormR1 & cOrRuPtG3t!x for helping me
now question is solved

This question has already been answered. Start a new discussion instead.
Be sure to adhere to our posting rules.