Next Generation BS Development Framework - Echo Tutorial (3)

zhaozj2021-02-11  230

Next Generation B / S Development Framework - Echo Tutorial (3)

HelloWorld

Write an Echo application, just a servlet and an instance, the rest is the development page.

/***********MAINSERVLET.JAVA************

* Main servlet, unique URL entry

* /

Import nextApp.echo. *;

Import nextapp.echoservlet.echoserver;

Public class mainservlet extends echoserver {

Public echoinstance newinstance () {

Return new maininstance ();

}

}

/***********MAININSTANCE.JAVA************

* Represents this session for MainServelet call

* /

Import nextApp.echo. *;

Public class maininstance extends echoinstance {

/ / Return to Window Representing Homepage

Public window init () {

Return new helloworldwindow ();

}

}

/************HELLOWORLDWINDOW.JAVA************

* User Window, customized according to their own needs Here we demonstrate some of the commonly used controls * / import nextapp.echo *;.. Public class HelloWorldWindow extends Window {public Label label = new Label ( "Hello world"); public HelloWorldWindow () {ContentPane content = New ContentPane (); setContent (Content); Grid Grid = new grid (); content.add (grid); grid.add (0,0, label); grid.add (0,1, new button ("Hello World ")); Grid.Add (0, 2, New Radiobutton (" Hello World ")); Grid.Add (0,3, New Checkbox (" Hello World ")); Grid.Add (0, 4, New Selectfield (new string "); grid.add (0,5, new textfield (" Hello World ")); Grid.Add (0,6, new textarea (" Hello World ")) }}

/ / ======== Web.xml configuration =======

echo mainservlet echo / echo

Run, write html in pure Java!

Let us see the event handle:

/***********Test1Window.java************ Demo Event Processing

* Please return this new test1window in the MAININSTANCE class.

* /

Import nextApp.echo. *;

Import nextapp.echo.event. *;

Public Class Test1Window Extends WINDOW IMPLEments ActionListener {

TextField txtinput = new textfield ("some worlds");

Button btnupdate = new button ("update");

Button btnclose = New Button ("Close Window");

HelloWorldWindow Win = New HelloWindWindow ();

Public Test1Window () {

ContentPane Content = New ContentPane ();

SetContent (Content);

Content.add (txtinput);

// Increase event monitoring

btnupdate.addactionListener (this);

BtnClose.AddActionListener (this);

Content.add (btnupdate);

Content.add (btnClose);

Win.SetWidth (200);

Win.SetHeight (400);

}

// Event processing

Public Void ActionPerformed (ActionEvent E) {

IF (E.getsource () == btnupdate) {

GetechoinStance (). Addwindow (win); // Register a new window

Win.Label.Settext (txtinput.getText ()); // Set the text inside

}

Else if (E.GetSource () == btnclose)

Win.Dispose (); // Close window

Dispose ();

}

}

}

From the above example you can see:

The event response is an ActionListener that adds the listener (ActionListener), which is responsible for the corresponding event response. The new window is open to get EchoinStance, where you register a new window, that is, add the controls in the window to the session. If you are off Remove the new window, it will also pop up unless you press the main window of the Close button. Description In the session, this window is not destroyed.

转载请注明原文地址:https://www.9cbs.com/read-5844.html

New Post(0)