SetVisible(true) // "super" Frame shows // (this) // (lblCount) // (tfCount) // System.out. SetSize(300, 100) // "super" Frame sets its initial window size // For inspecting the Container/Components objects // (this) // (lblCount) // (tfCount) // (btnCount) SetTitle("AWT Counter") // "super" Frame sets its title Clicking "Count" button calls back actionPerformed(). The source object adds an instance of BtnCountListener as an ActionEvent listener, // which provides an ActionEvent handler called actionPerformed(). "btnCount" is the source object that fires an ActionEvent when clicked. tEditable(false) // set to read-onlyĪdd(tfCount) // "super" Frame container adds TextField componentītnCount = new Button("Count") // construct the Button componentĪdd(btnCount) // "super" Frame container adds Button componentītnCountListener listener = new BtnCountListener() TfCount = new TextField(count + "", 10) // construct the TextField component with initial text LblCount = new Label("Counter") // construct the Label componentĪdd(lblCount) // "super" Frame container adds Label component ![]() "super" Frame, which is a Container, sets its layout to FlowLayout to arrange // the components from left-to-right, and flow to next row from top-to-bottom. Private int count = 0 // Counter's value // Constructor to setup GUI components and event handlers Private Button btnCount // Declare a Button component Private TextField tfCount // Declare a TextField component Private Label lblCount // Declare a Label component Import .* // Using AWT event classes and listener interfaces // An AWT program inherits from the top-level container Constructors : FlowLayout (): It will Construct a new FlowLayout with centered alignment.The horizontal and vertical gap will be 5 pixels. ![]() The default layout of applet and panel is FlowLayout. Import java.awt.* // Using AWT container and component classes FlowLayout is used to arrange components in a sequence one after the other. The components are placed inside the top-level AWT container, arranged in FlowLayout.
0 Comments
Leave a Reply. |