Example 1-Hello world!

Source: Internet
Author: User

In FB, create an ActionScript class file in the newly created ActionScript project. Enter the followingCode.

 
Package {
Import flash. display. Sprite;

Import org. aswing. aswingmanager;
Import org. aswing. flowlayout;
Import org. aswing. jbutton;
Import org. aswing. jframe;
Import org. aswing. joptionpane;
Import org. aswing. event. awevent;
Public class aswingtest1 extends Sprite
{
Private var myframe: jframe;
Private var mybutton: jbutton;
Public Function aswingtest1 ()
{
Aswingmanager. initasstandard (this); // use aswing Program Previously called this method, which encapsulates some common functions

Mybutton = new jbutton ("Click me"); // create a Button Object
Mybutton. addactionlistener (_ buttonclicked); // Add a button listener to the object

Myframe = new jframe (this, "my frame"); // create a widget for the window
Myframe. getcontentpane (). setlayout (New flowlayout (); // sets the layout mode.
Myframe. getcontentpane (). append (mybutton); // call the container's append method to add the button to the jframe container.

Myframe. setsizewh (300,200); // you can specify the size of the display window.
Myframe. Show (); // set to visible
}
Private function _ buttonclicked (E: awevent): void {
Joptionpane. showmessagedialog ("hello", "Hello, world! "); // Display a message box
}
}
}

If Flash CS3 is used, you can create an ActionScript file, enter the code, and save it as helloaswing. as, and then create a new flash (actionscript3.0) file, save the FLA file to helloaswing. and set the FLA document class to helloaswing.

After running the window, you can see an interface like this. You can try to perform various operations on the window.

This is a very simple instance program that uses aswing to create the UI component. Next we will briefly analyze the code of this program.

Detailed instance analysis

With aswing, the main program does not need to be based on any application framework. The aswing UI components are extended from the flash native Sprite, therefore, almost every aswing component can be put into displayobjectcontainer and used properly.
Our main program only needs to inherit Sprite. The following analyzes the code in the constructor.

Aswingmanager. initasstandard (this );

We recommend that you call this method before using the aswing program. This method encapsulates some common functions and callsAswingmanagerThe setroot method is used to set the container to accommodate the aswing component. This indicates the root of the current aswing component. In addition, system parameters such as align and scalemode are also set.

Mybutton = new jbutton ("Click me ");
Mybutton. addactionlistener (_ buttonclicked );

Jbutton is a basic button component in aswing. A jbutton instance is created and the label of the button is set. The second Code adds an event listener to the button, after clicking the button, it will trigger.AddactionlistenerAswing is designed to simplify the writing of event listening. Of course, it can also be written like this.Mybutton. addeventlistener (awevent. Act,_ Buttonclicked );.
Awevent
Is the most basic event class in aswing. The Act event type indicates the trigger event type of some basic components, such as the jbutton mouse click event and jtextfield carriage return event. Click here to execute_ ButtonclickedThe event processing function. The code in the function will be discussed later.

Myframe = new jframe (this, "my frame ");
Myframe. getcontentpane (). setlayout (New flowlayout ());
Myframe. getcontentpane (). append (mybutton );

Jframe is a commonly used window component. It has basic features similar to operating system windows, such as min/dashboard, close, zoom, and drag functions. The first parameter of jframe indicates the container of the window, and the second parameter sets the label (title) of the window header ).
Getcontentpane ()Method To Get The jframe container that can accommodate other components. Do not call it directly when adding a component to the jframe.JframeOfAppendMethod, jframe actually holds other components, not itself, but a container inside it.Getcontentpane ()Method acquisition.
The layout of each container is controlled by layout. setlayout is used to set the layout of containers. For details about the layout, see aswing deployment management.
Then, the container append method is called to add the button to the jframe container.

Myframe. setsizewh (300,200 );
Myframe. Show ();

The two codes are relatively simple. Set the size of the jframe and display the jframe. You may find that the addchild method is not used. It doesn't matter. jframe inherits jpopup. All jpopup-based components, aswing will automatically add to displaylist for you and call show () the method can be set to visible.

Next, let's take a look at the simple event processing functions.

Private function _ buttonclicked (E: awevent): void {
Joptionpane. showmessagedialog ("hello", "Hello, world! ");
}

JoptionpaneIs a component similar to alert,Showmessagedialog ()A message box is displayed. The first parameter is the title of the message box, and the second parameter sets the message content characters.

Conclusion

Nowadays, the Flash Player-based Ria technology is very popular. To develop such applications, you will inevitably use the UI components that interact with users. aswing is such a powerful component library, provides common basic components, and developers may easily expand their own special components. The flexibility of aswing prevents developers from being constrained by specific conditions. You can use aswing as a GUI switching component throughout the project, you can also use only one of aswing components in your project to help you quickly obtain the required UI.
Developers of aswing are constantly improving aswing to make it more powerful and easy to use.
This article only introduces the most basic use of aswing. More powerful performance is waiting for you to explore. Please refer to other aswing related tutorials.

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.