Java Writing graphical user interface program--Example 2: Happy Mother's Day! ^_^ o~ efforts!

Source: Internet
Author: User
Tags gettext

More and more less recently, but also prepared to save the race, but also to prepare for class four!

As a true "rural baby", "computer slag", as a student outside, not for the mother in her holiday for gifts, personally accompany her, now can only silently make a small program to send blessing,

The recent time is very few, learned the thing not much ^_^ o~ diligently! , every point of growth for me is a valuable effort!

Import java.awt.*;import javax.swing.*;import java.awt.event.*;p ublic class Simple instance 2 {public static void main (String args[] {Final char c= ' "; JFrame jf=new JFrame ("simple Example 2"); JLabel lab1=new JLabel ("problem"); JLabel lab2=new JLabel ("Answer"), Final JLabel lab3=new JLabel (""); final JLabel lab4=new JLabel (""); final JLabel lab5=new JLa Bel (""); JTextField txf1=new JTextField ("What day is it today?") "); final JTextField txf2=new JTextField (" "); JButton submit=new JButton ("submit");//jpasswordfield txf3=new JPasswordField ("123456"); Container Cp=jf.getcontentpane (); jf.setsize (500,300); cp.setlayout (null); Cp.setbackground (Color.pink); Lab1.setbounds, Lab2.setbounds (80,80,40,20); Lab3.setbounds (180,150,200,20); Lab4.setbounds ( 20,180,500,20); Lab5.setbounds (50,200,500,20); Txf1.setbounds (120, 80, 200, 20);// Txf3.setbounds, Txf1.seteditable (false), Cp.add (LAB1); Cp.add (TXF1); Cp.add (LAB2); Cp.add (TXF2); Cp.add (submit); Cp.add (LAB3); Cp.add (LAB4); Cp.add (LAB5); Submit.setbounds (140, Submit.addactionlistener (new ActionListener () {public void actionperformed (ActionEvent ae) {if ("Mother's Day"). Equals (Txf2.gettext (). Trim ())) {Lab3.settext ("accepted!└ (^o^) ┘"); Lab4.settext ("Blessing: Mother hard, as a college student outside, not ready for what gift, Only a small program "); Lab5.settext (" Bless mother, wish all mothers: Happy Mother's Day! ") ");} else {if ("". Equals (Txf2.gettext (). Trim ())) {Lab3.settext ("Answer cannot be blank"), Lab4.settext (""); Lab5.settext ("");} else {lab3.settext ("wrong anwer! one by one +"), Lab4.settext (""); Lab5.settext ("");}}}); /cp.add (LAB3);//cp.add (Txf3); jf.setvisible (True);}}


Java Writing graphical user interface program--Example 2: Happy Mother's Day! ^_^ o~ efforts!

Related Article

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.