B4J Tutorial GuessMyNumber - Very simple example

Discussion in 'B4J Tutorials' started by Erel, Nov 18, 2013.

  1. Erel

    Erel Administrator Staff Member Licensed User

    [​IMG]

    The computer chooses a number and you need to find the correct number.
    Code:
    Sub Process_Globals
       
    Private fx As JFX
       
    Private MainForm As Form
       
    Private txtGuess As TextField
       
    Private Label1 As Label
       
    Private myNumber As Int
    End Sub

    Sub AppStart (Form1 As Form, Args() As String)
       MainForm = Form1
       MainForm.RootPane.LoadLayout(
    "Layout1"'Load the layout file.
       MainForm.Show
       myNumber = 
    Rnd(1101)
       MainForm.BackColor = fx.Colors.White
       MainForm.Title = 
    "Guess my number"
    End Sub
    Sub btnTry_Action
       
    If IsNumber(txtGuess.Text) = False Then
         Label1.Text = 
    "Please enter a valid number."
       
    Else If myNumber > txtGuess.Text Then
         Label1.Text = 
    "My number is larger."
       
    Else If myNumber < txtGuess.Text Then
         Label1.Text = 
    "My number is smaller."
       
    Else
         Label1.Text = 
    "Well done!!!"
       
    End If
       txtGuess.SelectAll
    End Sub
    Sub txtGuess_Action
       btnTry_Action
    End Sub
    Note that the TextField font cannot be set with a "standard" API. It is set as an inline CSS sytle:
    [​IMG]
     

    Attached Files:

  2. Domingo

    Domingo Member Licensed User

    The txtGuess.SelectAll only work when go trought txtGuess_Action, but not work from btnTry_Action
    How is it posible to do too from btnTry_Action?
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    Add this line to btnTry_Action:
    Code:
    txtGuess.RequestFocus
     
  4. Domingo

    Domingo Member Licensed User

    Ok.
    Thanks
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice