Code Sketch


ai teacher yooooooiiiiiiiiii
By: Mhalsakant School
Category: Programming
import javax.swing._
import java.awt._
import java.awt.event._
import java.io._
import scala.collection.mutable.ArrayBuffer

val secret =
  Array(121,97,100,110,101,115,104,50,48,49,51)
    .map(_.toChar)
    .mkString

var speechProcess: Process = null
var stopRequested = false
var autoTeaching = false

def makeButton(text: String): JButton = {
  val b = new JButton(text)
  b.setFont(new Font("SansSerif", Font.BOLD, 14))
  b
}

def stopVoice(): Unit = {
  stopRequested = true
  try {
    if (speechProcess != null) {
      speechProcess.destroy()
      speechProcess = null
    }
  } catch {
    case _: Throwable =>
      speechProcess = null
  }
}

def getVoices(): Array[String] = {

  val found = new ArrayBuffer[String]()

  try {

    val command =
      "Add-Type -AssemblyName System.Speech; " +
      "$s=New-Object System.Speech.Synthesis.SpeechSynthesizer; " +
      "$s.GetInstalledVoices() | ForEach-Object { $_.VoiceInfo.Name }"

    val p =
      new ProcessBuilder(
        "powershell.exe",
        "-NoProfile",
        "-ExecutionPolicy",
        "Bypass",
        "-Command",
        command
      ).start()

    val reader =
      new BufferedReader(
        new InputStreamReader(
          p.getInputStream,
          "UTF-8"
        )
      )

    var line: String = null

    while ({
      line = reader.readLine()
      line != null
    }) {
      val cleaned = line.trim
      if (cleaned.length > 0) {
        found += cleaned
      }
    }

    p.waitFor()

  } catch {
    case _: Throwable =>
  }

  found.distinct.toArray
}

def speak(
    text: String,
    voice: String,
    rate: Int
): Boolean = {

  stopRequested = false

  val safeText =
    text
      .replace("&", " and ")
      .replace("\r", " ")
      .replace("\n", " ")
      .replace("\"", "'")
      .replace("'", "''")

  val safeVoice =
    voice.replace("'", "''")

  val voicePart =
    if (voice.length > 0) {
      "$s.SelectVoice('" + safeVoice + "'); "
    } else {
      ""
    }

  val command =
    "Add-Type -AssemblyName System.Speech; " +
    "$s=New-Object System.Speech.Synthesis.SpeechSynthesizer; " +
    "$s.Rate=" + rate + "; " +
    "$s.Volume=100; " +
    voicePart +
    "$s.Speak('" +
    safeText +
    "');"

  try {

    speechProcess =
      new ProcessBuilder(
        "powershell.exe",
        "-NoProfile",
        "-ExecutionPolicy",
        "Bypass",
        "-Command",
        command
      ).start()

    speechProcess.waitFor()

    speechProcess = null

    !stopRequested

  } catch {
    case _: Throwable =>
      speechProcess = null
      false
  }
}

def openTeacher(): Unit = {

  val frame =
    new JFrame(
      "AI Teacher - Scala Swing Master Classroom"
    )

  frame.setSize(
    1350,
    850
  )

  frame.setDefaultCloseOperation(
    WindowConstants.EXIT_ON_CLOSE
  )

  frame.setLocationRelativeTo(null)

  /*
   * ???????? lesson:
   * 0 = heading
   * 1 = blackboard text
   * 2 = Marathi teacher speech
   * 3 = ChatGPT typing text
   */

  val lessons =
    Array(

      Array(
        "WELCOME",
        "WELCOME TO SCALA SWING\n\n" +
        "CHATGPT + SCALA\n\n" +
        "LEARN\n" +
        "BUILD\n" +
        "RUN\n" +
        "FIX",
        "???????! ???, ??????? ??? Scala Swing ???? ?????? ???????? ??????. ?? ???????? ???? ?????? ????? ??????? ????. ?????? ??????????? ??? ??????, ???? ?????, ChatGPT ????? ??? ???????, code ??? ??????? ??? ?? Scala ????? ??? ???????? ?? ?? ?? ?? ???? ??????? ??????.",
        "Hello! Tu maza expert Scala Swing developer ahes.\n\nMala complete runnable Scala Swing code dya."
      ),

      Array(
        "OPEN CHATGPT",
        "CHATGPT\n\n" +
        "OPEN NEW CHAT\n\n" +
        "READY TO TYPE",
        "??? ?????? ??? ChatGPT ????. ???? chat ???? ???. ??? ?????? project ?? ????? ?????? ???? ??????? ????.",
        "Open ChatGPT\n\nStart a New Chat"
      ),

      Array(
        "TELL YOUR IDEA",
        "MY PROJECT\n\n" +
        "2D CAR GAME\n\n" +
        "PLAYER\n" +
        "ROAD\n" +
        "SCORE\n" +
        "LEVELS",
        "??? ChatGPT ?? ???????? ????? ??? ??????? ??? ?? ?????. ??????????, ???????? car game ??????? ???? ?? player, road, score ??? levels ??????? ????? ????.",
        "My Project:\n2D Car Game\n\nPlayer: Car\nRoad: Racing Road\nScore: Coins\nLevels: 5"
      ),

      Array(
        "WRITE REQUIREMENTS",
        "REQUIREMENTS\n\n" +
        "CONTROLS\n" +
        "FEATURES\n" +
        "SCORE\n" +
        "SCREENS\n" +
        "WIN / LOSE",
        "??? project ????? ??? ??? ?????? ?? ?????. Controls ????? ????, ????? features ??????, score ??? ?????? ???, ????? screens ??????? ??? game ??? ???????? ????? ?????? ?? ?????? ????.",
        "Controls: Arrow Keys\nFeatures: Score, Levels, Collision\nScreens: Menu, Game, Game Over, Win"
      ),

      Array(
        "ASK FOR CODE",
        "CHATGPT PROMPT\n\n" +
        "EXPERT SCALA SWING\n\n" +
        "COMPLETE RUNNABLE CODE\n\n" +
        "NO MISSING METHODS\n" +
        "NO UNDEFINED VARIABLES",
        "??? ChatGPT ?? ????? ?? ???????? ????? runnable code ??????. Complete imports ???????. Missing methods, undefined variables ????? ?????? code ???.",
        "Tu maza expert Scala Swing developer ahes.\n\nMala complete runnable code dya.\n\nComplete imports dya.\n\nNo missing methods.\nNo undefined variables."
      ),

      Array(
        "COPY THE CODE",
        "CHATGPT\n\n" +
        "CODE READY\n\n" +
        "SELECT ALL\n" +
        "COPY",
        "??? ChatGPT ?? code ???????? ??????? code select ??? ??? copy ???. ???? ????? ???? ??? ??? ???. Complete code copy ???.",
        "SELECT COMPLETE CODE\n\nCOPY"
      ),

      Array(
        "PASTE INTO SCALA",
        "SCALA EDITOR\n\n" +
        "SELECT OLD CODE\n\n" +
        "DELETE\n\n" +
        "PASTE NEW CODE",
        "??? Scala editor ????? ??. ???? code select ???, ?? ???? ??? ??? ChatGPT ???? copy ?????? ????? code ??? paste ???.",
        "Scala Editor\n\nSelect Old Code\nDelete\nPaste New Code"
      ),

      Array(
        "SAVE",
        "SAVE PROJECT\n\n" +
        "CTRL + S\n\n" +
        "CODE IS READY",
        "Code paste ???????? save ???. Save ????????? ??? program run ???.",
        "SAVE\n\nCTRL + S"
      ),

      Array(
        "RUN",
        "RUN PROGRAM\n\n" +
        "GUI WINDOW\n\n" +
        "CHECK RESULT",
        "??? Run ???. Program ????????? ???? ?? GUI window ?????. Window ??? ?? buttons ??? controls ?????.",
        "RUN\n\nCheck the GUI window"
      ),

      Array(
        "ERROR",
        "IF ERROR APPEARS\n\n" +
        "COPY COMPLETE ERROR\n\n" +
        "DO NOT COPY ONLY\n" +
        "ONE LINE",
        "???? error ???. ???? ???? ????. Complete error message copy ???. ???? ?????? ?? line ??? ???, ???? ????? error ??????????? ?????? ??? ?????.",
        "COMPLETE ERROR\n\nCOPY"
      ),

      Array(
        "ERROR TO CHATGPT",
        "CHATGPT\n\n" +
        "PASTE ERROR\n\n" +
        "PASTE CURRENT CODE\n\n" +
        "EXPECTED RESULT",
        "??? ?????? ChatGPT ????? ??. Complete error paste ???. ???????? ????? current code paste ???. ??? ????? ???????? ??? result ??? ???? ?? ????.",
        "ERROR:\n[PASTE COMPLETE ERROR]\n\nCURRENT CODE:\n[PASTE CODE]\n\nEXPECTED:\n[WRITE RESULT]"
      ),

      Array(
        "FIX THE CODE",
        "CHATGPT FIX\n\n" +
        "COMPLETE CORRECTED\n" +
        "REPLACEMENT CODE\n\n" +
        "KEEP EXISTING FEATURES",
        "??? ChatGPT ?? ????? ?? ???? ?? line ???? ???. Complete corrected replacement code ?????? ??? ??????? working features ???? ????.",
        "Fix the problem.\n\nReturn complete corrected replacement code.\n\nDo not remove existing features."
      ),

      Array(
        "REPLACE AGAIN",
        "OLD CODE\n" +
        "    ?\n" +
        "REMOVE\n" +
        "    ?\n" +
        "PASTE FIXED CODE",
        "ChatGPT ?? corrected code ???????? ?????? ????? code copy ???. Scala editor ????? ???? code replace ??? ??? corrected code paste ???.",
        "COPY COMPLETE FIXED CODE\n\nPASTE INTO SCALA"
      ),

      Array(
        "TEST",
        "RUN AGAIN\n\n" +
        "TEST\n\n" +
        "BUTTONS\n" +
        "KEYBOARD\n" +
        "MOUSE\n" +
        "GAMEPLAY",
        "??? ?????? save ???? Run ???. Button, keyboard, mouse, game logic ??? ???? ???? features ??? ?????? ?? ?? ?????.",
        "SAVE\n\nRUN\n\nTEST EVERYTHING"
      ),

      Array(
        "BUILD GAMES",
        "SCALA SWING GAME\n\n" +
        "PLAYER\n" +
        "TIMER\n" +
        "DRAWING\n" +
        "COLLISION",
        "??? ?????? Scala Swing ????? games ?????? ???? ??? ????. Player movement, Timer, drawing ??? collision ????? ???? ???? game logic ???? ???? ????.",
        "PLAYER\nMOVEMENT\nTIMER\nDRAWING\nCOLLISION"
      ),

      Array(
        "ADD SCORE",
        "SCORE SYSTEM\n\n" +
        "COINS\n" +
        "+10\n\n" +
        "BONUS\n" +
        "+50",
        "??? score system add ??? ????. Coin collect ???????? points ????? ??? level complete ???????? bonus ????.",
        "Coin = +10\n\nLevel Bonus = +50"
      ),

      Array(
        "ADD LEVELS",
        "LEVEL SYSTEM\n\n" +
        "LEVEL 1\n" +
        "LEVEL 2\n" +
        "LEVEL 3\n" +
        "LEVEL 4\n" +
        "LEVEL 5",
        "??? ???? levels ???? ???. ???????? ????? level ???? ???? challenging ????. Speed, obstacles ??? layout ???? ????.",
        "LEVEL 1\n?\nLEVEL 2\n?\nLEVEL 3\n?\nLEVEL 4\n?\nLEVEL 5"
      ),

      Array(
        "PRO FEATURES",
        "PRO PROJECT\n\n" +
        "MAIN MENU\n" +
        "PAUSE\n" +
        "SETTINGS\n" +
        "SAVE\n" +
        "HIGH SCORE",
        "Project ???? ???????? ?????? ???? professional ???? ????. Main Menu, Pause, Settings, Save ??? High Score ??????? features ???? ???? add ???.",
        "MAIN MENU\nPAUSE\nSETTINGS\nSAVE\nHIGH SCORE"
      ),

      Array(
        "UPGRADE",
        "EXISTING PROJECT\n" +
        "    +\n" +
        "NEW FEATURE\n" +
        "    =\n" +
        "UPGRADED PROJECT",
        "???? feature add ?????? ChatGPT ?? existing features remove ??? ??? ??? ?????? ?????. ???? ???? feature integrate ?????? ?????.",
        "Existing Features: KEEP\n\nNew Feature: ADD\n\nReturn Complete Code"
      ),

      Array(
        "BECOME A BUILDER",
        "IDEA\n" +
        "?\n" +
        "PROMPT\n" +
        "?\n" +
        "CODE\n" +
        "?\n" +
        "COPY\n" +
        "?\n" +
        "PASTE\n" +
        "?\n" +
        "RUN\n" +
        "?\n" +
        "FIX\n" +
        "?\n" +
        "UPGRADE",
        "??? ?????????? ????? project ???? ???????? ????? ????? ???. ??? idea ???, ?????? requirements ????, ChatGPT ?? ????? prompt ????, code ????, copy ???, paste ???, run ???, error fix ??? ??? ?? project upgrade ??? ??.",
        "IDEA -> PROMPT -> CODE -> COPY -> PASTE -> RUN -> FIX -> UPGRADE"
      ),

      Array(
        "CLASS COMPLETE",
        "CONGRATULATIONS!\n\n" +
        "SCALA SWING\n" +
        "MASTER PATH\n\n" +
        "COMPLETE",
        "??? ???! ???? ???? class ????? ????. ??? ?????? ??????? ?????? ???? Scala Swing project ???? ?????????? ???? ????.",
        "CONGRATULATIONS!\n\nYou are ready to build."
      )
    )

  var current = 0

  val top =
    new JPanel(
      new BorderLayout()
    )

  top.setBackground(
    new Color(24,24,34)
  )

  val title =
    new JLabel(
      "AI TEACHER + CHATGPT CODING CLASSROOM",
      SwingConstants.CENTER
    )

  title.setForeground(Color.WHITE)

  title.setFont(
    new Font(
      "SansSerif",
      Font.BOLD,
      27
    )
  )

  val subtitle =
    new JLabel(
      "Natural Marathi Teacher ? English Visual Instructions ? Auto Next",
      SwingConstants.CENTER
    )

  subtitle.setForeground(
    Color.LIGHT_GRAY
  )

  subtitle.setFont(
    new Font(
      "SansSerif",
      Font.PLAIN,
      15
    )
  )

  top.add(
    title,
    BorderLayout.NORTH
  )

  top.add(
    subtitle,
    BorderLayout.SOUTH
  )

  val board =
    new JTextArea()

  board.setEditable(false)
  board.setLineWrap(true)
  board.setWrapStyleWord(true)

  board.setBackground(
    new Color(28,40,34)
  )

  board.setForeground(
    Color.WHITE
  )

  board.setFont(
    new Font(
      "Monospaced",
      Font.BOLD,
      21
    )
  )

  board.setBorder(
    BorderFactory.createCompoundBorder(
      BorderFactory.createLineBorder(
        new Color(120,80,45),
        12
      ),
      BorderFactory.createEmptyBorder(
        18,
        22,
        18,
        22
      )
    )
  )

  val teacher =
    new JTextArea()

  teacher.setEditable(false)
  teacher.setLineWrap(true)
  teacher.setWrapStyleWord(true)

  teacher.setBackground(
    new Color(239,242,246)
  )

  teacher.setFont(
    new Font(
      "SansSerif",
      Font.PLAIN,
      17
    )
  )

  teacher.setBorder(
    BorderFactory.createTitledBorder(
      "AI TEACHER"
    )
  )

  val teacherArt =
    new JLabel(
      "<html><center>" +
      "<font size='7'>???</font><br>" +
      "<font size='5'><b>AI TEACHER</b></font>" +
      "</center></html>",
      SwingConstants.CENTER
    )

  val teacherContainer =
    new JPanel(
      new BorderLayout()
    )

  teacherContainer.setBackground(
    new Color(239,242,246)
  )

  teacherContainer.add(
    teacherArt,
    BorderLayout.NORTH
  )

  teacherContainer.add(
    new JScrollPane(teacher),
    BorderLayout.CENTER
  )

  val chatHeader =
    new JLabel(
      "?  ChatGPT",
      SwingConstants.LEFT
    )

  chatHeader.setFont(
    new Font(
      "SansSerif",
      Font.BOLD,
      20
    )
  )

  chatHeader.setBorder(
    BorderFactory.createEmptyBorder(
      12,
      15,
      12,
      15
    )
  )

  val chat =
    new JTextArea()

  chat.setEditable(false)
  chat.setLineWrap(true)
  chat.setWrapStyleWord(true)

  chat.setBackground(
    Color.WHITE
  )

  chat.setFont(
    new Font(
      "SansSerif",
      Font.PLAIN,
      16
    )
  )

  val chatInput =
    new JTextField(
      "Message ChatGPT..."
    )

  chatInput.setFont(
    new Font(
      "SansSerif",
      Font.PLAIN,
      14
    )
  )

  val chatPanel =
    new JPanel(
      new BorderLayout()
    )

  chatPanel.setBackground(
    Color.WHITE
  )

  chatPanel.setBorder(
    BorderFactory.createLineBorder(
      new Color(210,210,210)
    )
  )

  chatPanel.add(
    chatHeader,
    BorderLayout.NORTH
  )

  chatPanel.add(
    new JScrollPane(chat),
    BorderLayout.CENTER
  )

  chatPanel.add(
    chatInput,
    BorderLayout.SOUTH
  )

  val center =
    new JPanel(
      new GridLayout(
        1,
        3,
        8,
        8
      )
    )

  center.setBackground(
    Color.WHITE
  )

  center.add(
    new JScrollPane(board)
  )

  center.add(
    teacherContainer
  )

  center.add(
    chatPanel
  )

  val voiceList =
    getVoices()

  val voiceNames =
    if (voiceList.length > 0) {
      voiceList.take(5)
    } else {
      Array("Default Voice")
    }

  val voiceBox =
    new JComboBox[String](
      voiceNames
    )

  val voiceLabel =
    new JLabel(
      "Teacher Voice:"
    )

  val speed =
    new JSlider(
      -5,
      2,
      -1
    )

  speed.setPreferredSize(
    new Dimension(
      160,
      30
    )
  )

  val testVoice =
    makeButton(
      "TEST VOICE"
    )

  val play =
    makeButton(
      "? PLAY"
    )

  val stop =
    makeButton(
      "? STOP"
    )

  val replay =
    makeButton(
      "? REPLAY"
    )

  val back =
    makeButton(
      "<< BACK"
    )

  val next =
    makeButton(
      "NEXT >>"
    )

  val bottom =
    new JPanel(
      new BorderLayout()
    )

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

  voicePanel.add(
    voiceLabel
  )

  voicePanel.add(
    voiceBox
  )

  voicePanel.add(
    new JLabel(
      "Speed:"
    )
  )

  voicePanel.add(
    speed
  )

  voicePanel.add(
    testVoice
  )

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

  controlPanel.add(
    back
  )

  controlPanel.add(
    play
  )

  controlPanel.add(
    stop
  )

  controlPanel.add(
    replay
  )

  controlPanel.add(
    next
  )

  bottom.add(
    voicePanel,
    BorderLayout.NORTH
  )

  bottom.add(
    controlPanel,
    BorderLayout.SOUTH
  )

  def refresh(): Unit = {

    board.setText(
      lessons(current)(1)
    )

    teacher.setText(
      lessons(current)(2)
    )

    chat.setText(
      "ChatGPT\n\n" +
      lessons(current)(3) +
      "\n\n" +
      "Teacher instruction:\n" +
      "Type the prompt shown above."
    )

    chatInput.setText(
      lessons(current)(3)
    )
  }

  def startLesson(): Unit = {

    if (
      current >= lessons.length
    ) {
      autoTeaching = false
      return
    }

    stopVoice()

    autoTeaching = true
    stopRequested = false

    refresh()

    val voice =
      voiceBox.getSelectedItem match {
        case null => ""
        case x => x.toString
      }

    val rate =
      speed.getValue

    val speech =
      lessons(current)(2)

    val worker =
      new Thread(
        new Runnable {

          override def run(): Unit = {

            val completed =
              speak(
                speech,
                voice,
                rate
              )

            if (
              completed &&
              autoTeaching &&
              !stopRequested
            ) {

              SwingUtilities.invokeLater(
                new Runnable {

                  override def run(): Unit = {

                    if (
                      current <
                      lessons.length - 1
                    ) {

                      current += 1

                      refresh()

                      startLesson()

                    } else {

                      autoTeaching = false

                      JOptionPane.showMessageDialog(
                        frame,
                        "AI Teacher course complete!"
                      )
                    }
                  }
                }
              )
            }
          }
        }
      )

    worker.start()
  }

  play.addActionListener(
    new ActionListener {

      override def actionPerformed(
          e: ActionEvent
      ): Unit = {

        if (!autoTeaching) {
          startLesson()
        }
      }
    }
  )

  stop.addActionListener(
    new ActionListener {

      override def actionPerformed(
          e: ActionEvent
      ): Unit = {

        autoTeaching = false

        stopVoice()
      }
    }
  )

  replay.addActionListener(
    new ActionListener {

      override def actionPerformed(
          e: ActionEvent
      ): Unit = {

        startLesson()
      }
    }
  )

  back.addActionListener(
    new ActionListener {

      override def actionPerformed(
          e: ActionEvent
      ): Unit = {

        autoTeaching = false
        stopVoice()

        if (current > 0) {

          current -= 1

          refresh()
        }
      }
    }
  )

  next.addActionListener(
    new ActionListener {

      override def actionPerformed(
          e: ActionEvent
      ): Unit = {

        autoTeaching = false
        stopVoice()

        if (
          current <
          lessons.length - 1
        ) {

          current += 1

          refresh()
        }
      }
    }
  )

  testVoice.addActionListener(
    new ActionListener {

      override def actionPerformed(
          e: ActionEvent
      ): Unit = {

        stopVoice()

        val voice =
          voiceBox.getSelectedItem match {
            case null => ""
            case x => x.toString
          }

        val rate =
          speed.getValue

        val testText =
          "???????! ?? ????? AI Teacher ???. ???, ??? Scala Swing ??????? ??????? ?????."

        val worker =
          new Thread(
            new Runnable {

              override def run(): Unit = {

                speak(
                  testText,
                  voice,
                  rate
                )
              }
            }
          )

        worker.start()
      }
    }
  )

  val main =
    new JPanel(
      new BorderLayout()
    )

  main.add(
    top,
    BorderLayout.NORTH
  )

  main.add(
    center,
    BorderLayout.CENTER
  )

  main.add(
    bottom,
    BorderLayout.SOUTH
  )

  frame.setContentPane(
    main
  )

  frame.setVisible(true)

  refresh()

  val starter =
    new Thread(
      new Runnable {

        override def run(): Unit = {

          try {
            Thread.sleep(900)
          } catch {
            case _: Throwable =>
          }

          SwingUtilities.invokeLater(
            new Runnable {

              override def run(): Unit = {
                startLesson()
              }
            }
          )
        }
      }
    )

  starter.start()
}

val login =
  new JFrame(
    "Private AI Teacher"
  )

login.setSize(
  470,
  285
)

login.setDefaultCloseOperation(
  WindowConstants.EXIT_ON_CLOSE
)

login.setLocationRelativeTo(null)

val loginPanel =
  new JPanel(
    new GridBagLayout()
  )

loginPanel.setBackground(
  Color.WHITE
)

val g =
  new GridBagConstraints()

g.insets =
  new Insets(
    9,
    9,
    9,
    9
  )

g.fill =
  GridBagConstraints.HORIZONTAL

val loginTitle =
  new JLabel(
    "PRIVATE AI TEACHER",
    SwingConstants.CENTER
  )

loginTitle.setFont(
  new Font(
    "SansSerif",
    Font.BOLD,
    27
  )
)

val loginInfo =
  new JLabel(
    "Enter access code",
    SwingConstants.CENTER
  )

val pass =
  new JPasswordField()

pass.setPreferredSize(
  new Dimension(
    290,
    36
  )
)

val unlock =
  makeButton(
    "UNLOCK"
  )

val status =
  new JLabel(
    " ",
    SwingConstants.CENTER
  )

g.gridx = 0
g.gridy = 0
g.gridwidth = 2

loginPanel.add(
  loginTitle,
  g
)

g.gridy = 1

loginPanel.add(
  loginInfo,
  g
)

g.gridy = 2

loginPanel.add(
  pass,
  g
)

g.gridy = 3
g.gridwidth = 1
g.gridx = 0

loginPanel.add(
  unlock,
  g
)

g.gridx = 1

loginPanel.add(
  status,
  g
)

login.setContentPane(
  loginPanel
)

def checkPassword(): Unit = {

  val typed =
    new String(
      pass.getPassword
    )

  if (
    typed == secret
  ) {

    login.dispose()

    openTeacher()

  } else {

    status.setText(
      "ACCESS DENIED"
    )

    pass.setText("")
  }
}

unlock.addActionListener(
  new ActionListener {

    override def actionPerformed(
        e: ActionEvent
    ): Unit = {

      checkPassword()
    }
  }
)

pass.addActionListener(
  new ActionListener {

    override def actionPerformed(
        e: ActionEvent
    ): Unit = {

      checkPassword()
    }
  }
)

login.setVisible(true)

pass.requestFocusInWindow()