Test Event Response Modify interface content

Source: Internet
Author: User

 PackageCom.swing.demo;Importjava.awt.BorderLayout;ImportJava.awt.Color;ImportJava.awt.Container;Importjava.awt.event.ActionEvent;ImportJava.awt.event.ActionListener;ImportJavax.swing.JButton;ImportJavax.swing.JFrame;ImportJavax.swing.JTextArea;/*** Test Event Response Modification interface content *@authorAdministrator **/ Public classActionlistenertest { Public Static voidMain (string[] args) {Actionlistenertest instance=Newactionlistenertest ();    Instance.show (); }    Private voidShow () {JFrame frame=NewJFrame ("form"); Container ContentPane=Frame.getcontentpane (); JButton btn=NewJButton ("button"); JTextArea TextArea=NewJTextArea ();        Textarea.setbackground (Color.White); Textarea.setrows (10); Myactionlistener Listener=NewMyactionlistener ();        LISTENER.SETBTN (BTN);        Listener.settextarea (TextArea);        Btn.addactionlistener (listener);        Contentpane.add (BTN, Borderlayout.north);        Contentpane.add (TextArea, Borderlayout.south);        Frame.pack (); Frame.setvisible (true);        Frame.requestfocus (); Frame.setsize (400, 300); Frame.setlocationrelativeto (NULL);    Frame.setdefaultcloseoperation (Jframe.exit_on_close); }    Private classMyactionlistenerImplementsActionListener {PrivateJButton btn; PrivateJTextArea TextArea;  Public voidsetbtn (JButton btn) { This. btn =btn; }         Public voidSettextarea (JTextArea textArea) { This. TextArea =TextArea; } @Override Public voidactionperformed (ActionEvent e) {Btn.settext ("Hello World"); Textarea.settext (Textarea.gettext ()+ "new000" + "\ r \ n"); }    }}

Test Event Response Modify interface content

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.