Event snooping in the Java Gui design pattern

Source: Internet
Author: User
Tags gettext

    • Button tap to listen

Trigger a listener event by clicking the button

1Button_20 =NewJButton ("20");//Create a Button object Button_202Button_20.addactionlistener (NewActionListener () {//To Add a button listener event3              Public voidactionperformed (ActionEvent e) {4                 if(Textfield_6.gettext (). Equals ("")) {5Textfield_6.settext ("20"); //Add content to the target text box 6}Else{7                     intsum = Integer.parseint (Textfield_6.gettext ()) +20;8 textfield_6.settext (string.valueof (sum));9                 }Ten             } One});

  

    • Mouse click to listen

Trigger a listener event by clicking the left mouse button

  

Combobox.addmouselistener (NewMouseadapter () {//Add mouse listener events for our elements             Public voidmouseclicked (MouseEvent e) {//left mouse button click (target table)                           intR= Table_2.getselectedrow ();//get the row where the cell is located              intC= Table_2.getselectedcolumn ();//get the column where the cell is locatedObject value=Table_2.getvalueat (R, c); //get the value of the clicked cell                      intA = Integer.parseint (String.valueof (Table_2.getvalueat (R, 3))); intb = Integer.parseint (String.valueof (Table_2.getvalueat (R, 2))); intres = A *b;//int a = (int) table_2.getvalueat (r, 3) * (int) table_2.getvalueat (r, 2);Table_2.setvalueat (Res, R, 4); //Implement the functionality we need (modify parameters for another cell in a different column of your peers)System.out.println (info);                                 }        }); 

Event snooping in the Java Gui design pattern

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.