Code Sketch


Bixuu cricket live see
By: Mhalsakant School
Category: Programming
import javax.swing._
import java.awt._
import java.awt.event._
import java.text.SimpleDateFormat
import java.util.Date

// ============================================================
// BIXUU CRICKET LIVE
// SIMPLE + KOJO FRIENDLY + FULL VERSION
// ============================================================


// ============================================================
// CONFIG
// ============================================================

object BixuuConfig {

  val APP_NAME = "BIXUU CRICKET LIVE"

  val PASSWORD = "bixuu@cricketlive"

  val BG_COLOR =
    new Color(10, 14, 22)

  val PANEL_COLOR =
    new Color(20, 27, 40)

  val CARD_COLOR =
    new Color(29, 38, 55)

  val GOLD_COLOR =
    new Color(255, 193, 7)

  val GREEN_COLOR =
    new Color(46, 204, 113)

  val BLUE_COLOR =
    new Color(52, 152, 219)

  val RED_COLOR =
    new Color(231, 76, 60)

  val GRAY_COLOR =
    new Color(180, 190, 205)

  val WHITE_COLOR =
    Color.WHITE

  def normalFont(size: Int): Font = {
    new Font(
      "SansSerif",
      Font.PLAIN,
      size
    )
  }

  def boldFont(size: Int): Font = {
    new Font(
      "SansSerif",
      Font.BOLD,
      size
    )
  }
}


// ============================================================
// MATCH MODEL
// ============================================================

case class BixuuMatch(

  id: Int,

  matchName: String,

  seriesName: String,

  categoryName: String,

  venueName: String,

  dateText: String,

  timeText: String,

  statusText: String,

  teamA: String,

  teamB: String,

  scoreA: String,

  scoreB: String,

  oversA: String,

  oversB: String,

  resultText: String,

  tossText: String,

  infoText: String
)


// ============================================================
// LIVE DATA MODEL
// ============================================================

case class BixuuLiveData(

  status: String,

  innings: String,

  battingTeam: String,

  score: String,

  overs: String,

  otherTeam: String,

  target: String,

  requiredRuns: String,

  requiredRate: String,

  striker: String,

  nonStriker: String,

  bowler: String,

  lastOver: String,

  toss: String,

  venue: String,

  updated: String
)


// ============================================================
// DATABASE
// ============================================================

object BixuuDatabase {

  val matches =
    new scala.collection.mutable.ArrayBuffer[BixuuMatch]()

  def load(): Unit = {

    matches.clear()


    // --------------------------------------------------------
    // INDIA VS WEST INDIES
    // --------------------------------------------------------

    matches += BixuuMatch(

      1,

      "India vs West Indies - 1st ODI",

      "West Indies Tour of India 2026",

      "INDIA",

      "Greenfield International Stadium, Thiruvananthapuram",

      "27 Sep 2026",

      "2:00 PM IST",

      "LIVE",

      "India",

      "West Indies",

      "Yet to Bat",

      "LIVE",

      "-",

      "LIVE",

      "",

      "India won the toss and elected to field",

      "1st ODI - India vs West Indies"
    )


    // --------------------------------------------------------
    // INDIA
    // --------------------------------------------------------

    matches += BixuuMatch(

      2,

      "India vs South Africa",

      "International Cricket",

      "INDIA",

      "India",

      "Upcoming",

      "2:00 PM IST",

      "UPCOMING",

      "India",

      "South Africa",

      "-",

      "-",

      "-",

      "-",

      "",

      "",

      "International cricket fixture"
    )


    matches += BixuuMatch(

      3,

      "India vs New Zealand",

      "International Cricket",

      "INDIA",

      "India",

      "Completed",

      "2:00 PM IST",

      "COMPLETED",

      "India",

      "New Zealand",

      "276/8",

      "270/10",

      "50.0",

      "48.4",

      "India won by 6 runs",

      "",

      "Completed international match"
    )


    // --------------------------------------------------------
    // IPL
    // --------------------------------------------------------

    matches += BixuuMatch(

      4,

      "Mumbai Indians vs Chennai Super Kings",

      "Indian Premier League",

      "IPL",

      "Wankhede Stadium, Mumbai",

      "Upcoming",

      "7:30 PM IST",

      "UPCOMING",

      "Mumbai Indians",

      "Chennai Super Kings",

      "-",

      "-",

      "-",

      "-",

      "",

      "",

      "IPL fixture"
    )


    matches += BixuuMatch(

      5,

      "Royal Challengers Bengaluru vs Kolkata Knight Riders",

      "Indian Premier League",

      "IPL",

      "M. Chinnaswamy Stadium, Bengaluru",

      "Upcoming",

      "7:30 PM IST",

      "UPCOMING",

      "Royal Challengers Bengaluru",

      "Kolkata Knight Riders",

      "-",

      "-",

      "-",

      "-",

      "",

      "",

      "IPL fixture"
    )


    matches += BixuuMatch(

      6,

      "Rajasthan Royals vs Delhi Capitals",

      "Indian Premier League",

      "IPL",

      "India",

      "Upcoming",

      "7:30 PM IST",

      "UPCOMING",

      "Rajasthan Royals",

      "Delhi Capitals",

      "-",

      "-",

      "-",

      "-",

      "",

      "",

      "IPL fixture"
    )


    // --------------------------------------------------------
    // ICC
    // --------------------------------------------------------

    matches += BixuuMatch(

      7,

      "Australia vs England",

      "ICC Cricket",

      "ICC",

      "International",

      "Upcoming",

      "2:00 PM IST",

      "UPCOMING",

      "Australia",

      "England",

      "-",

      "-",

      "-",

      "-",

      "",

      "",

      "ICC fixture"
    )


    matches += BixuuMatch(

      8,

      "Pakistan vs South Africa",

      "ICC Cricket",

      "ICC",

      "International",

      "Upcoming",

      "7:00 PM IST",

      "UPCOMING",

      "Pakistan",

      "South Africa",

      "-",

      "-",

      "-",

      "-",

      "",

      "",

      "ICC fixture"
    )


    matches += BixuuMatch(

      9,

      "New Zealand vs Australia",

      "ICC Cricket",

      "ICC",

      "International",

      "Completed",

      "2:00 PM IST",

      "COMPLETED",

      "New Zealand",

      "Australia",

      "251/9",

      "248/10",

      "50.0",

      "49.2",

      "New Zealand won",

      "",

      "Completed ICC match"
    )
  }


  def findMatch(
    matchId: Int
  ): BixuuMatch = {

    var answer: BixuuMatch = null

    var i = 0

    while (
      i < matches.size
    ) {

      val current =
        matches(i)

      if (
        current.id == matchId
      ) {

        answer = current
      }

      i = i + 1
    }

    answer
  }
}


// ============================================================
// LIVE PROVIDER
// ============================================================

object BixuuLiveProvider {

  def current(): BixuuLiveData = {

    val now =
      new SimpleDateFormat(
        "dd MMM yyyy, hh:mm:ss a"
      ).format(
        new Date()
      )

    BixuuLiveData(

      "LIVE",

      "1st Innings",

      "West Indies",

      "Live score feed",

      "Live",

      "India - Yet to Bat",

      "Not Set",

      "-",

      "-",

      "Live feed",

      "Live feed",

      "Live feed",

      "Live commentary feed",

      "India won the toss and elected to field",

      "Greenfield International Stadium, Thiruvananthapuram",

      now
    )
  }
}


// ============================================================
// LOGIN WINDOW
// ============================================================

class BixuuLogin
    extends JFrame {

  setTitle(
    "BIXUU CRICKET LIVE - LOGIN"
  )

  setSize(
    520,
    430
  )

  setLocationRelativeTo(null)

  setResizable(false)

  setDefaultCloseOperation(
    WindowConstants.EXIT_ON_CLOSE
  )


  val loginRoot =
    new JPanel(
      new BorderLayout()
    )

  loginRoot.setBackground(
    BixuuConfig.BG_COLOR
  )


  // ----------------------------------------------------------
  // HEADING
  // ----------------------------------------------------------

  val loginHeading =
    new JLabel(
      "<html><center>" +
      "BIXUU<br>" +
      "CRICKET LIVE" +
      "</center></html>",
      SwingConstants.CENTER
    )

  loginHeading.setFont(
    BixuuConfig.boldFont(32)
  )

  loginHeading.setForeground(
    BixuuConfig.GOLD_COLOR
  )

  loginHeading.setBorder(
    BorderFactory.createEmptyBorder(
      25,
      10,
      20,
      10
    )
  )

  loginRoot.add(
    loginHeading,
    BorderLayout.NORTH
  )


  // ----------------------------------------------------------
  // LOGIN BOX
  // ----------------------------------------------------------

  val loginCenter =
    new JPanel(
      new GridBagLayout()
    )

  loginCenter.setBackground(
    BixuuConfig.BG_COLOR
  )


  val loginBox =
    new JPanel(
      new GridBagLayout()
    )

  loginBox.setBackground(
    BixuuConfig.PANEL_COLOR
  )

  loginBox.setBorder(
    BorderFactory.createEmptyBorder(
      25,
      40,
      25,
      40
    )
  )


  val loginGrid =
    new GridBagConstraints()

  loginGrid.insets =
    new Insets(
      7,
      7,
      7,
      7
    )

  loginGrid.fill =
    GridBagConstraints.HORIZONTAL


  val userLabel =
    new JLabel(
      "Username"
    )

  userLabel.setForeground(
    BixuuConfig.WHITE_COLOR
  )

  userLabel.setFont(
    BixuuConfig.boldFont(15)
  )


  val userInput =
    new JTextField(18)


  val passwordLabel =
    new JLabel(
      "Password"
    )

  passwordLabel.setForeground(
    BixuuConfig.WHITE_COLOR
  )

  passwordLabel.setFont(
    BixuuConfig.boldFont(15)
  )


  val passwordInput =
    new JPasswordField(18)


  val loginButton =
    new JButton(
      "LOGIN"
    )

  loginButton.setFont(
    BixuuConfig.boldFont(15)
  )

  loginButton.setBackground(
    BixuuConfig.GOLD_COLOR
  )

  loginButton.setForeground(
    Color.BLACK
  )


  val loginMessage =
    new JLabel(" ")

  loginMessage.setForeground(
    BixuuConfig.RED_COLOR
  )

  loginMessage.setHorizontalAlignment(
    SwingConstants.CENTER
  )


  loginGrid.gridx = 0
  loginGrid.gridy = 0

  loginBox.add(
    userLabel,
    loginGrid
  )


  loginGrid.gridy = 1

  loginBox.add(
    userInput,
    loginGrid
  )


  loginGrid.gridy = 2

  loginBox.add(
    passwordLabel,
    loginGrid
  )


  loginGrid.gridy = 3

  loginBox.add(
    passwordInput,
    loginGrid
  )


  loginGrid.gridy = 4

  loginBox.add(
    loginButton,
    loginGrid
  )


  loginGrid.gridy = 5

  loginBox.add(
    loginMessage,
    loginGrid
  )


  loginCenter.add(
    loginBox
  )


  loginRoot.add(
    loginCenter,
    BorderLayout.CENTER
  )


  setContentPane(
    loginRoot
  )


  // ----------------------------------------------------------
  // LOGIN FUNCTION
  // ----------------------------------------------------------

  def doLogin(): Unit = {

    val entered =
      new String(
        passwordInput.getPassword()
      )


    if (
      entered ==
      BixuuConfig.PASSWORD
    ) {

      dispose()


      SwingUtilities.invokeLater(
        new Runnable {

          def run(): Unit = {

            val app =
              new BixuuMainApp()

            app.setVisible(true)
          }
        }
      )

    } else {

      loginMessage.setText(
        "Wrong password!"
      )
    }
  }


  loginButton.addActionListener(
    new ActionListener {

      def actionPerformed(
        e: ActionEvent
      ): Unit = {

        doLogin()
      }
    }
  )


  passwordInput.addActionListener(
    new ActionListener {

      def actionPerformed(
        e: ActionEvent
      ): Unit = {

        doLogin()
      }
    }
  )
}


// ============================================================
// MAIN APPLICATION
// ============================================================

class BixuuMainApp
    extends JFrame {

  BixuuDatabase.load()


  setTitle(
    "BIXUU CRICKET LIVE"
  )

  setSize(
    1200,
    760
  )

  setMinimumSize(
    new Dimension(
      1000,
      650
    )
  )

  setLocationRelativeTo(null)

  setDefaultCloseOperation(
    WindowConstants.EXIT_ON_CLOSE
  )


  // ==========================================================
  // HEADER
  // ==========================================================

  val header =
    new JPanel(
      new BorderLayout()
    )

  header.setBackground(
    BixuuConfig.PANEL_COLOR
  )

  header.setBorder(
    BorderFactory.createEmptyBorder(
      12,
      20,
      12,
      20
    )
  )


  val logo =
    new JLabel(
      "BIXUU CRICKET LIVE"
    )

  logo.setFont(
    BixuuConfig.boldFont(26)
  )

  logo.setForeground(
    BixuuConfig.GOLD_COLOR
  )

  header.add(
    logo,
    BorderLayout.WEST
  )


  val liveStatus =
    new JLabel(
      "? LIVE"
    )

  liveStatus.setFont(
    BixuuConfig.boldFont(17)
  )

  liveStatus.setForeground(
    BixuuConfig.GREEN_COLOR
  )

  header.add(
    liveStatus,
    BorderLayout.EAST
  )


  // ==========================================================
  // SEARCH AREA
  // ==========================================================

  val searchArea =
    new JPanel(
      new BorderLayout(
        10,
        0
      )
    )

  searchArea.setBackground(
    BixuuConfig.BG_COLOR
  )

  searchArea.setBorder(
    BorderFactory.createEmptyBorder(
      10,
      15,
      10,
      15
    )
  )


  val searchInput =
    new JTextField()

  searchInput.setFont(
    BixuuConfig.normalFont(15)
  )

  searchInput.setToolTipText(
    "Search team, match or series"
  )


  val searchButton =
    new JButton(
      "SEARCH"
    )

  searchButton.setBackground(
    BixuuConfig.GOLD_COLOR
  )

  searchButton.setForeground(
    Color.BLACK
  )


  val refreshButton =
    new JButton(
      "REFRESH"
    )

  refreshButton.setBackground(
    BixuuConfig.BLUE_COLOR
  )

  refreshButton.setForeground(
    Color.WHITE
  )


  val buttonArea =
    new JPanel(
      new FlowLayout(
        FlowLayout.RIGHT
      )
    )

  buttonArea.setBackground(
    BixuuConfig.BG_COLOR
  )

  buttonArea.add(
    searchButton
  )

  buttonArea.add(
    refreshButton
  )


  searchArea.add(
    searchInput,
    BorderLayout.CENTER
  )

  searchArea.add(
    buttonArea,
    BorderLayout.EAST
  )


  // ==========================================================
  // TABS
  // ==========================================================

  val tabs =
    new JTabbedPane()

  tabs.setFont(
    BixuuConfig.boldFont(14)
  )


  tabs.addTab(
    "HOME",
    createHome()
  )

  tabs.addTab(
    "LIVE",
    createStatusTab("LIVE")
  )

  tabs.addTab(
    "UPCOMING",
    createStatusTab("UPCOMING")
  )

  tabs.addTab(
    "COMPLETED",
    createStatusTab("COMPLETED")
  )

  tabs.addTab(
    "INDIA",
    createCategoryTab("INDIA")
  )

  tabs.addTab(
    "IPL",
    createCategoryTab("IPL")
  )

  tabs.addTab(
    "ICC",
    createCategoryTab("ICC")
  )

  tabs.addTab(
    "ALL MATCHES",
    createAllTab()
  )


  // ==========================================================
  // ROOT
  // ==========================================================

  val root =
    new JPanel(
      new BorderLayout()
    )

  root.setBackground(
    BixuuConfig.BG_COLOR
  )


  val top =
    new JPanel(
      new BorderLayout()
    )

  top.setBackground(
    BixuuConfig.BG_COLOR
  )

  top.add(
    header,
    BorderLayout.NORTH
  )

  top.add(
    searchArea,
    BorderLayout.CENTER
  )


  root.add(
    top,
    BorderLayout.NORTH
  )

  root.add(
    tabs,
    BorderLayout.CENTER
  )


  setContentPane(
    root
  )


  // ==========================================================
  // HOME
  // ==========================================================

  def createHome(): JPanel = {

    val panel =
      new JPanel(
        new BorderLayout(
          10,
          10
        )
      )

    panel.setBackground(
      BixuuConfig.BG_COLOR
    )

    panel.setBorder(
      BorderFactory.createEmptyBorder(
        18,
        18,
        18,
        18
      )
    )


    val heading =
      new JLabel(
        "? BIXUU CRICKET MATCH CENTRE"
      )

    heading.setFont(
      BixuuConfig.boldFont(22)
    )

    heading.setForeground(
      BixuuConfig.WHITE_COLOR
    )


    panel.add(
      heading,
      BorderLayout.NORTH
    )


    val live =
      BixuuLiveProvider.current()


    panel.add(
      createLiveCard(live),
      BorderLayout.CENTER
    )


    panel
  }


  // ==========================================================
  // LIVE CARD
  // ==========================================================

  def createLiveCard(
    live: BixuuLiveData
  ): JPanel = {

    val card =
      new JPanel(
        new BorderLayout(
          10,
          10
        )
      )

    card.setBackground(
      BixuuConfig.CARD_COLOR
    )

    card.setBorder(
      BorderFactory.createCompoundBorder(
        BorderFactory.createLineBorder(
          BixuuConfig.GREEN_COLOR,
          2
        ),
        BorderFactory.createEmptyBorder(
          18,
          18,
          18,
          18
        )
      )
    )


    val heading =
      new JLabel(
        "? LIVE - INDIA vs WEST INDIES"
      )

    heading.setFont(
      BixuuConfig.boldFont(23)
    )

    heading.setForeground(
      BixuuConfig.GREEN_COLOR
    )


    card.add(
      heading,
      BorderLayout.NORTH
    )


    val liveText =
      new JTextArea()

    liveText.setEditable(false)

    liveText.setLineWrap(true)

    liveText.setWrapStyleWord(true)

    liveText.setBackground(
      BixuuConfig.CARD_COLOR
    )

    liveText.setForeground(
      BixuuConfig.WHITE_COLOR
    )

    liveText.setFont(
      BixuuConfig.normalFont(16)
    )


    liveText.setText(
      "MATCH: India vs West Indies - 1st ODI\n\n" +
      "STATUS: " + live.status + "\n\n" +
      "INNINGS: " + live.innings + "\n" +
      "BATTING TEAM: " + live.battingTeam + "\n\n" +
      "SCORE: " + live.score + "\n" +
      "OVERS: " + live.overs + "\n" +
      "INDIA: " + live.otherTeam + "\n\n" +
      "TARGET: " + live.target + "\n" +
      "REQUIRED RUNS: " + live.requiredRuns + "\n" +
      "REQUIRED RUN RATE: " + live.requiredRate + "\n\n" +
      "STRIKER: " + live.striker + "\n" +
      "NON-STRIKER: " + live.nonStriker + "\n" +
      "BOWLER: " + live.bowler + "\n\n" +
      "LAST OVER: " + live.lastOver + "\n\n" +
      "TOSS: " + live.toss + "\n\n" +
      "VENUE: " + live.venue + "\n\n" +
      "UPDATED: " + live.updated
    )


    val scroll =
      new JScrollPane(
        liveText
      )

    scroll.setBorder(null)


    card.add(
      scroll,
      BorderLayout.CENTER
    )


    val openButton =
      new JButton(
        "OPEN FULL MATCH"
      )

    openButton.setFont(
      BixuuConfig.boldFont(16)
    )

    openButton.setBackground(
      BixuuConfig.GOLD_COLOR
    )

    openButton.setForeground(
      Color.BLACK
    )


    openButton.addActionListener(
      new ActionListener {

        def actionPerformed(
          e: ActionEvent
        ): Unit = {

          val matchObject =
            BixuuDatabase.findMatch(1)

          if (
            matchObject != null
          ) {

            showDetails(
              matchObject
            )
          }
        }
      }
    )


    card.add(
      openButton,
      BorderLayout.SOUTH
    )


    card
  }


  // ==========================================================
  // STATUS TAB
  // ==========================================================

  def createStatusTab(
    wantedStatus: String
  ): JPanel = {

    val listPanel =
      new JPanel()

    listPanel.setBackground(
      BixuuConfig.BG_COLOR
    )

    listPanel.setLayout(
      new BoxLayout(
        listPanel,
        BoxLayout.Y_AXIS
      )
    )

    listPanel.setBorder(
      BorderFactory.createEmptyBorder(
        15,
        15,
        15,
        15
      )
    )


    var found =
      false

    var i = 0

    while (
      i < BixuuDatabase.matches.size
    ) {

      val current =
        BixuuDatabase.matches(i)


      if (
        current.statusText ==
        wantedStatus
      ) {

        found = true


        val card =
          createMatchCard(
            current
          )

        card.setAlignmentX(
          Component.LEFT_ALIGNMENT
        )

        listPanel.add(
          card
        )

        listPanel.add(
          Box.createVerticalStrut(10)
        )
      }


      i = i + 1
    }


    if (!found) {

      val empty =
        new JLabel(
          "No " +
          wantedStatus +
          " matches."
        )

      empty.setFont(
        BixuuConfig.boldFont(20)
      )

      empty.setForeground(
        BixuuConfig.WHITE_COLOR
      )

      listPanel.add(
        empty
      )
    }


    val scroll =
      new JScrollPane(
        listPanel
      )

    scroll.setBorder(null)


    val wrapper =
      new JPanel(
        new BorderLayout()
      )

    wrapper.setBackground(
      BixuuConfig.BG_COLOR
    )

    wrapper.add(
      scroll,
      BorderLayout.CENTER
    )


    wrapper
  }


  // ==========================================================
  // CATEGORY TAB
  // ==========================================================

  def createCategoryTab(
    wantedCategory: String
  ): JPanel = {

    val listPanel =
      new JPanel()

    listPanel.setBackground(
      BixuuConfig.BG_COLOR
    )

    listPanel.setLayout(
      new BoxLayout(
        listPanel,
        BoxLayout.Y_AXIS
      )
    )

    listPanel.setBorder(
      BorderFactory.createEmptyBorder(
        15,
        15,
        15,
        15
      )
    )


    var found =
      false

    var i = 0

    while (
      i < BixuuDatabase.matches.size
    ) {

      val current =
        BixuuDatabase.matches(i)


      if (
        current.categoryName ==
        wantedCategory
      ) {

        found = true


        val card =
          createMatchCard(
            current
          )

        card.setAlignmentX(
          Component.LEFT_ALIGNMENT
        )

        listPanel.add(
          card
        )

        listPanel.add(
          Box.createVerticalStrut(10)
        )
      }


      i = i + 1
    }


    if (!found) {

      val empty =
        new JLabel(
          "No matches found."
        )

      empty.setFont(
        BixuuConfig.boldFont(20)
      )

      empty.setForeground(
        BixuuConfig.WHITE_COLOR
      )

      listPanel.add(
        empty
      )
    }


    val scroll =
      new JScrollPane(
        listPanel
      )

    scroll.setBorder(null)


    val wrapper =
      new JPanel(
        new BorderLayout()
      )

    wrapper.setBackground(
      BixuuConfig.BG_COLOR
    )

    wrapper.add(
      scroll,
      BorderLayout.CENTER
    )


    wrapper
  }


  // ==========================================================
  // ALL MATCHES
  // ==========================================================

  def createAllTab(): JPanel = {

    val listPanel =
      new JPanel()

    listPanel.setBackground(
      BixuuConfig.BG_COLOR
    )

    listPanel.setLayout(
      new BoxLayout(
        listPanel,
        BoxLayout.Y_AXIS
      )
    )

    listPanel.setBorder(
      BorderFactory.createEmptyBorder(
        15,
        15,
        15,
        15
      )
    )


    var i = 0

    while (
      i < BixuuDatabase.matches.size
    ) {

      val card =
        createMatchCard(
          BixuuDatabase.matches(i)
        )

      card.setAlignmentX(
        Component.LEFT_ALIGNMENT
      )

      listPanel.add(
        card
      )

      listPanel.add(
        Box.createVerticalStrut(10)
      )

      i = i + 1
    }


    val scroll =
      new JScrollPane(
        listPanel
      )

    scroll.setBorder(null)


    val wrapper =
      new JPanel(
        new BorderLayout()
      )

    wrapper.setBackground(
      BixuuConfig.BG_COLOR
    )

    wrapper.add(
      scroll,
      BorderLayout.CENTER
    )


    wrapper
  }


  // ==========================================================
  // MATCH CARD
  // ==========================================================

  def createMatchCard(
    m: BixuuMatch
  ): JPanel = {

    val card =
      new JPanel(
        new BorderLayout(
          15,
          10
        )
      )

    card.setBackground(
      BixuuConfig.CARD_COLOR
    )


    val borderColor =
      if (
        m.statusText == "LIVE"
      ) {

        BixuuConfig.GREEN_COLOR

      } else {

        new Color(
          70,
          80,
          100
        )
      }


    card.setBorder(
      BorderFactory.createCompoundBorder(
        BorderFactory.createLineBorder(
          borderColor,
          1
        ),
        BorderFactory.createEmptyBorder(
          15,
          15,
          15,
          15
        )
      )
    )


    val left =
      new JPanel()

    left.setBackground(
      BixuuConfig.CARD_COLOR
    )

    left.setLayout(
      new BoxLayout(
        left,
        BoxLayout.Y_AXIS
      )
    )


    val matchName =
      new JLabel(
        m.matchName
      )

    matchName.setFont(
      BixuuConfig.boldFont(19)
    )

    matchName.setForeground(
      BixuuConfig.WHITE_COLOR
    )


    val series =
      new JLabel(
        m.seriesName
      )

    series.setFont(
      BixuuConfig.normalFont(14)
    )

    series.setForeground(
      BixuuConfig.GRAY_COLOR
    )


    val teams =
      new JLabel(
        m.teamA +
        "  vs  " +
        m.teamB
      )

    teams.setFont(
      BixuuConfig.boldFont(17)
    )

    teams.setForeground(
      BixuuConfig.GOLD_COLOR
    )


    val venue =
      new JLabel(
        "Venue: " +
        m.venueName
      )

    venue.setFont(
      BixuuConfig.normalFont(13)
    )

    venue.setForeground(
      BixuuConfig.GRAY_COLOR
    )


    left.add(
      matchName
    )

    left.add(
      Box.createVerticalStrut(5)
    )

    left.add(
      series
    )

    left.add(
      Box.createVerticalStrut(5)
    )

    left.add(
      teams
    )

    left.add(
      Box.createVerticalStrut(5)
    )

    left.add(
      venue
    )


    card.add(
      left,
      BorderLayout.CENTER
    )


    val right =
      new JPanel()

    right.setBackground(
      BixuuConfig.CARD_COLOR
    )

    right.setLayout(
      new BoxLayout(
        right,
        BoxLayout.Y_AXIS
      )
    )


    val status =
      new JLabel(
        m.statusText
      )

    status.setFont(
      BixuuConfig.boldFont(15)
    )


    if (
      m.statusText == "LIVE"
    ) {

      status.setForeground(
        BixuuConfig.GREEN_COLOR
      )

    } else if (
      m.statusText == "COMPLETED"
    ) {

      status.setForeground(
        BixuuConfig.BLUE_COLOR
      )

    } else {

      status.setForeground(
        BixuuConfig.GOLD_COLOR
      )
    }


    val score =
      new JLabel(
        m.scoreA +
        " | " +
        m.scoreB
      )

    score.setFont(
      BixuuConfig.boldFont(14)
    )

    score.setForeground(
      BixuuConfig.WHITE_COLOR
    )


    val open =
      new JButton(
        "OPEN"
      )

    open.setBackground(
      BixuuConfig.GOLD_COLOR
    )

    open.setForeground(
      Color.BLACK
    )


    open.addActionListener(
      new ActionListener {

        def actionPerformed(
          e: ActionEvent
        ): Unit = {

          showDetails(m)
        }
      }
    )


    right.add(
      status
    )

    right.add(
      Box.createVerticalStrut(7)
    )

    right.add(
      score
    )

    right.add(
      Box.createVerticalStrut(7)
    )

    right.add(
      open
    )


    card.add(
      right,
      BorderLayout.EAST
    )


    card
  }


  // ==========================================================
  // DETAILS
  // ==========================================================

  def showDetails(
    m: BixuuMatch
  ): Unit = {

    val dialog =
      new JDialog()


    dialog.setTitle(
      "BIXUU MATCH DETAILS"
    )

    dialog.setModal(true)

    dialog.setSize(
      850,
      650
    )

    dialog.setLocationRelativeTo(null)


    val rootPanel =
      new JPanel(
        new BorderLayout()
      )

    rootPanel.setBackground(
      BixuuConfig.BG_COLOR
    )


    val heading =
      new JLabel(
        m.matchName,
        SwingConstants.CENTER
      )

    heading.setFont(
      BixuuConfig.boldFont(25)
    )

    heading.setForeground(
      BixuuConfig.GOLD_COLOR
    )

    heading.setBorder(
      BorderFactory.createEmptyBorder(
        15,
        10,
        15,
        10
      )
    )


    rootPanel.add(
      heading,
      BorderLayout.NORTH
    )


    val infoPanel =
      new JPanel()

    infoPanel.setBackground(
      BixuuConfig.BG_COLOR
    )

    infoPanel.setLayout(
      new BoxLayout(
        infoPanel,
        BoxLayout.Y_AXIS
      )
    )

    infoPanel.setBorder(
      BorderFactory.createEmptyBorder(
        10,
        25,
        10,
        25
      )
    )


    addInfo(
      infoPanel,
      "Series",
      m.seriesName
    )

    addInfo(
      infoPanel,
      "Category",
      m.categoryName
    )

    addInfo(
      infoPanel,
      "Teams",
      m.teamA +
      " vs " +
      m.teamB
    )

    addInfo(
      infoPanel,
      "Date",
      m.dateText
    )

    addInfo(
      infoPanel,
      "Time",
      m.timeText
    )

    addInfo(
      infoPanel,
      "Venue",
      m.venueName
    )

    addInfo(
      infoPanel,
      "Status",
      m.statusText
    )

    addInfo(
      infoPanel,
      "Score",
      m.scoreA +
      " | " +
      m.scoreB
    )

    addInfo(
      infoPanel,
      "Overs",
      m.oversA +
      " | " +
      m.oversB
    )


    if (
      m.tossText != ""
    ) {

      addInfo(
        infoPanel,
        "Toss",
        m.tossText
      )
    }


    if (
      m.resultText != ""
    ) {

      addInfo(
        infoPanel,
        "Result",
        m.resultText
      )
    }


    addInfo(
      infoPanel,
      "Information",
      m.infoText
    )


    // --------------------------------------------------------
    // LIVE DETAILS
    // --------------------------------------------------------

    if (
      m.id == 1
    ) {

      val live =
        BixuuLiveProvider.current()


      addInfo(
        infoPanel,
        "LIVE INNINGS",
        live.innings
      )

      addInfo(
        infoPanel,
        "BATTING TEAM",
        live.battingTeam
      )

      addInfo(
        infoPanel,
        "CURRENT SCORE",
        live.score
      )

      addInfo(
        infoPanel,
        "CURRENT OVERS",
        live.overs
      )

      addInfo(
        infoPanel,
        "INDIA",
        live.otherTeam
      )

      addInfo(
        infoPanel,
        "TARGET",
        live.target
      )

      addInfo(
        infoPanel,
        "REQUIRED RUNS",
        live.requiredRuns
      )

      addInfo(
        infoPanel,
        "REQUIRED RATE",
        live.requiredRate
      )

      addInfo(
        infoPanel,
        "STRIKER",
        live.striker
      )

      addInfo(
        infoPanel,
        "NON-STRIKER",
        live.nonStriker
      )

      addInfo(
        infoPanel,
        "BOWLER",
        live.bowler
      )

      addInfo(
        infoPanel,
        "LAST OVER",
        live.lastOver
      )

      addInfo(
        infoPanel,
        "TOSS",
        live.toss
      )

      addInfo(
        infoPanel,
        "VENUE",
        live.venue
      )

      addInfo(
        infoPanel,
        "LAST UPDATED",
        live.updated
      )
    }


    val scroll =
      new JScrollPane(
        infoPanel
      )

    scroll.setBorder(null)


    rootPanel.add(
      scroll,
      BorderLayout.CENTER
    )


    val bottom =
      new JPanel(
        new FlowLayout(
          FlowLayout.CENTER
        )
      )

    bottom.setBackground(
      BixuuConfig.BG_COLOR
    )


    val close =
      new JButton(
        "CLOSE"
      )

    close.setBackground(
      BixuuConfig.GOLD_COLOR
    )

    close.setForeground(
      Color.BLACK
    )


    close.addActionListener(
      new ActionListener {

        def actionPerformed(
          e: ActionEvent
        ): Unit = {

          dialog.dispose()
        }
      }
    )


    bottom.add(
      close
    )


    rootPanel.add(
      bottom,
      BorderLayout.SOUTH
    )


    dialog.setContentPane(
      rootPanel
    )

    dialog.setVisible(true)
  }


  // ==========================================================
  // INFO HELPER
  // ==========================================================

  def addInfo(
    parent: JPanel,
    labelText: String,
    valueText: String
  ): Unit = {

    val text =
      new JTextArea(
        labelText +
        ": " +
        valueText
      )

    text.setEditable(false)

    text.setLineWrap(true)

    text.setWrapStyleWord(true)

    text.setBackground(
      BixuuConfig.BG_COLOR
    )

    text.setForeground(
      BixuuConfig.WHITE_COLOR
    )

    text.setFont(
      BixuuConfig.normalFont(15)
    )

    text.setBorder(
      BorderFactory.createEmptyBorder(
        5,
        5,
        5,
        5
      )
    )


    parent.add(
      text
    )
  }


  // ==========================================================
  // SEARCH
  // ==========================================================

  def performSearch(): Unit = {

    val query =
      searchInput.getText
        .trim
        .toLowerCase


    if (
      query.length == 0
    ) {

      JOptionPane.showMessageDialog(
        BixuuMainApp.this,
        "Please type a team, match, series or category.",
        "SEARCH",
        JOptionPane.INFORMATION_MESSAGE
      )

    } else {

      val result =
        new scala.collection.mutable.ArrayBuffer[BixuuMatch]()


      var i = 0


      while (
        i < BixuuDatabase.matches.size
      ) {

        val m =
          BixuuDatabase.matches(i)


        val matchNameFound =
          m.matchName
            .toLowerCase
            .contains(query)


        val seriesFound =
          m.seriesName
            .toLowerCase
            .contains(query)


        val categoryFound =
          m.categoryName
            .toLowerCase
            .contains(query)


        val teamAFound =
          m.teamA
            .toLowerCase
            .contains(query)


        val teamBFound =
          m.teamB
            .toLowerCase
            .contains(query)


        // IMPORTANT:
        // All conditions are calculated separately.
        // ???????? multiline || parser error ??? ????.

        if (
          matchNameFound
        ) {

          result += m

        } else if (
          seriesFound
        ) {

          result += m

        } else if (
          categoryFound
        ) {

          result += m

        } else if (
          teamAFound
        ) {

          result += m

        } else if (
          teamBFound
        ) {

          result += m
        }


        i = i + 1
      }


      showSearchResults(
        result
      )
    }
  }


  // ==========================================================
  // SEARCH RESULTS
  // ==========================================================

  def showSearchResults(
    results:
      scala.collection.mutable.ArrayBuffer[BixuuMatch]
  ): Unit = {

    val dialog =
      new JDialog()


    dialog.setTitle(
      "BIXUU SEARCH RESULTS"
    )

    dialog.setModal(true)

    dialog.setSize(
      850,
      570
    )

    dialog.setLocationRelativeTo(null)


    val resultPanel =
      new JPanel()

    resultPanel.setBackground(
      BixuuConfig.BG_COLOR
    )

    resultPanel.setLayout(
      new BoxLayout(
        resultPanel,
        BoxLayout.Y_AXIS
      )
    )

    resultPanel.setBorder(
      BorderFactory.createEmptyBorder(
        15,
        15,
        15,
        15
      )
    )


    if (
      results.size == 0
    ) {

      val noResult =
        new JLabel(
          "No matches found."
        )

      noResult.setForeground(
        BixuuConfig.WHITE_COLOR
      )

      noResult.setFont(
        BixuuConfig.boldFont(20)
      )

      resultPanel.add(
        noResult
      )

    } else {

      var i = 0

      while (
        i < results.size
      ) {

        val card =
          createMatchCard(
            results(i)
          )

        card.setAlignmentX(
          Component.LEFT_ALIGNMENT
        )

        resultPanel.add(
          card
        )

        resultPanel.add(
          Box.createVerticalStrut(10)
        )

        i = i + 1
      }
    }


    val scroll =
      new JScrollPane(
        resultPanel
      )

    scroll.setBorder(null)


    dialog.add(
      scroll
    )

    dialog.setVisible(true)
  }


  // ==========================================================
  // REFRESH
  // ==========================================================

  def refreshData(): Unit = {

    BixuuDatabase.load()


    JOptionPane.showMessageDialog(
      BixuuMainApp.this,
      "BIXUU Cricket Live refreshed successfully!",
      "REFRESH",
      JOptionPane.INFORMATION_MESSAGE
    )
  }


  // ==========================================================
  // BUTTON EVENTS
  // ==========================================================

  searchButton.addActionListener(
    new ActionListener {

      def actionPerformed(
        e: ActionEvent
      ): Unit = {

        performSearch()
      }
    }
  )


  searchInput.addActionListener(
    new ActionListener {

      def actionPerformed(
        e: ActionEvent
      ): Unit = {

        performSearch()
      }
    }
  )


  refreshButton.addActionListener(
    new ActionListener {

      def actionPerformed(
        e: ActionEvent
      ): Unit = {

        refreshData()
      }
    }
  )
}


// ============================================================
// START
// ============================================================

SwingUtilities.invokeLater(
  new Runnable {

    def run(): Unit = {

      val login =
        new BixuuLogin()

      login.setVisible(true)
    }
  }
)