Java Learning Notes (ii)

Source: Internet
Author: User

A simple login interface was created to add an event response.
Import javax.swing.*;
Import java.awt.*;
Import java.awt.event.*;
public class Jtextfielddemo extends JFrame implements actionlistener{

JTextField jtf=new JTextField (10);
JPasswordField jpf=new JPasswordField (10);//Create Password box
JButton jb=new JButton ("submit");//Create button
JLabel jl=new JLabel ("User name");//Create label
JLabel j2=new JLabel ("password");//Create label
JLabel j3=new JLabel ("Waiting for your landing!") ");//Create a label
JPanel jp=new JPanel ();//Create panel
JPanel q1=new JPanel ();
Jcheckbox C1 = new Jcheckbox ("Remember Password");
Defining constructors
Public Jtextfielddemo ()
{
This.settitle ("Landing system");
Jp.setlayout (null);//Use empty layout
Jl.setbounds (30,20,80,30);//Setting the position and size of label 1
Jp.add (JL);
J2.setbounds (30,70,80,30);//Setting the position and size of label 2
Jp.add (J2);
Jtf.setbounds (80,20,180,30);//Set the position and size of the text box
Jp.add (JTF);
Jpf.setbounds (80,70,180,30);//Set the location and size of the password box
Jp.add (JPF);
Jb.setbounds (50,130,80,30);//Set the position and size of the button
Jp.add (JB);
J3.setbounds (10,180,300,30);//Setting the position and size of label 3
Jp.add (J3);
Q1.setbounds (80,130,50,30);//Set the position and size of the radio box
C1.add (Q1);
Jb.addactionlistener (this);//Register Listener for text box
This.add (JP);//Add a panel to the window
This.setbounds (300,250,300,300);//Setting the position and size of the window
This.setvisible (TRUE);
}
public void actionperformed (ActionEvent e)
{
String S=jtf.gettext ();//Get the contents of a text box
String S1=new string (Jpf.getpassword ());//Gets the contents of the Password box
if (s.equals ("Java") &&s1.equals ("1234"))
{
J3.settext ("Landing success!") ");
}
Else
{
J3.settext ("Login failed! ");
}
}
public static void Main (string[] args) {
TODO auto-generated Method Stub
Jtextfielddemo f=new Jtextfielddemo ();
}}

Java Learning Notes (ii)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.