Other Quiz #10 - 2000 buttons quiz

Erel

Administrator
Staff member
Licensed User
B4J solution:



B4X:
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Private views As Map
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.Show
   views.Initialize
   For i = 1 To 2000
     Dim b As Button
     b.Initialize("b")
     b.Text = Rnd(1, 101)
     MainForm.RootPane.AddNode(b, Rnd(0, 600dip), Rnd(0, 400dip), 100dip, 100dip)
     Dim l1 As List
     If views.ContainsKey(b.Text) Then
       l1 = views.Get(b.Text)
     Else
       l1.Initialize
       views.Put(b.Text, l1)
     End If
     l1.Add(b)
   Next
End Sub

Sub b_MouseClicked (EventData As MouseEvent)
   Dim b As Button = Sender
   Dim l1 As List = views.Get(b.Text)
   For Each bb As Button In l1
     bb.RemoveNodeFromParent
     MainForm.RootPane.AddNode(bb, bb.Left, bb.Top, bb.Width, bb.Height)
   Next
End Sub
 
Top