Java implementation of GUI graphical interface

Source: Internet
Author: User

Java graphical tools: Java Graphical package java.awt:Abstract Window ToolKit, you need to call the local system method to implement the function javax. Swing: On the basis of AWT, more components are available, which enhances portability. Componnet:button: Button Label: Component Object checkbox: CheckBox (Tick box) TextComponent: Text area container: As a container, you can add components to it window: Windows Frame: Frame Dialog : dialog box FileDialog: File Dialog  panel: Panel layout manager: FlowLayout (streaming layout manager) left-to-right order panel default layout manager borderlayout (Boundary layout manager) In the middle of the frame default layout manager GridLayout (Grid layout manager) Rule Matrix CardLayout (Card layout manager) tab gridbaglayout (Grid layout manager) irregular matrix window build frame f= new Frame ("My AWT"); F.setsize (500,400);//Set Window size f.setlocation (300, 200);//Set Window position f.setlayout (new FlowLayout ());//Set Layout management  button B = New button ("I am a button");//new Buttons F.add (b);//Add button  textfield tf = new TextField (20);//Create a new text input window  // Listen action, implement 7 actions in Windowadapter class, F.addwindowlistener in Java.awt.* package (new Windowadapter () {//close window to call public void Windowclosing (WindowEvent e) {System.out.println ("window closing-----" +e.tostring ()); System.exit (0);} Call public void Windowactivater (WindowEvent e) {System.out.println ("active") as soon as the window is activated;} Open the window and call public void windowopened (WindowEvent e) {System.out.priNtln ("Dakai,hahah");}); /Add function to button B.addactionlistener (new ActionListener () {public void actionperformed (ActionEvent e) {system.exit (0);}}); /mouse function B.addmouselistener (new Mouseadapter () {private int count = 1;private int clickcount = 1;public void mouseentered (Mous Eevent e) {System.out.println ("mouse enters into this event");} public void mouseclicked (MouseEvent e) {if (E.getclickcount () ==2) System.out.println ("Double-click action" +clickcount++);}); /Text Window function Tf.addkeylistener (new Keyadapter () {public void keypressed (KeyEvent e) {int code = E.getkeycode (); if (code>= Keyevent.vk_0&&code<=keyevent.vk_9) {System.out.println (code+ "... E.consume ();//Let E event not occur neither type text box} }});  f.setvisible (true);//Display window

GUI graphical interface Java implementation

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.