Code Sketch


yoiiiiiiiii
By: Mhalsakant School
Category: Programming
import javax.swing._
import java.awt._
import java.awt.event._

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

val login = new JFrame("Secure Entry")
login.setSize(430,240)
login.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE)
login.setLocationRelativeTo(null)

val panel = new JPanel(new GridBagLayout())
val c = new GridBagConstraints()
c.insets = new Insets(8,8,8,8)
c.fill = GridBagConstraints.HORIZONTAL

val title = new JLabel("SECURE ENTRY", SwingConstants.CENTER)
title.setFont(new Font("SansSerif", Font.BOLD, 24))

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

val pass = new JPasswordField()
pass.setPreferredSize(new Dimension(260,35))

val enter = new JButton("ENTER")

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

c.gridx = 0
c.gridy = 0
c.gridwidth = 2
panel.add(title,c)

c.gridy = 1
panel.add(info,c)

c.gridy = 2
panel.add(pass,c)

c.gridy = 3
c.gridwidth = 1
c.gridx = 0
panel.add(enter,c)

c.gridx = 1
panel.add(status,c)

login.setContentPane(panel)

def checkPassword(): Unit = {
  val typed = new String(pass.getPassword)

  if (typed == secret) {

    login.dispose()

    val win = new JFrame("Scala Swing Complete Guide")
    win.setSize(1100,720)
    win.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE)
    win.setLocationRelativeTo(null)

    val tabs = new JTabbedPane()
    tabs.setFont(new Font("SansSerif",Font.BOLD,14))

    def addTab(name:String, text:String): Unit = {
      val area = new JTextArea()
      area.setText(text)
      area.setEditable(false)
      area.setLineWrap(true)
      area.setWrapStyleWord(true)
      area.setFont(new Font("SansSerif",Font.PLAIN,16))
      area.setBorder(BorderFactory.createEmptyBorder(15,15,15,15))

      val scroll = new JScrollPane(area)
      tabs.addTab(name,scroll)
    }

    addTab(
      "START",
      """SCALA SWING COMPLETE GUIDE

Scala Swing madhye desktop GUI applications ani games banvu shakto.

Basic classes:

JFrame = Main Window
JPanel = Container
JLabel = Text
JButton = Button
JTextField = Text Input
JPasswordField = Password Input
JTextArea = Large Text Area
JScrollPane = Scroll
JTabbedPane = Tabs
Timer = Repeated Update

Basic window:

val frame = new JFrame("My App")
frame.setSize(800,600)
frame.setLocationRelativeTo(null)
frame.setVisible(true)

Scala Swing project madhye GUI + Events + Drawing + Timer
vaprun games ani applications banvu shakto."""
    )

    addTab(
      "CHATGPT",
      """CHATGPT KADUN CODE KASA GHYAYCHA

ChatGPT la exact requirement dya.

Example:

Tu maza expert Scala Swing developer ahes.

Mala complete working Scala Swing application banvun de.

Complete code ekach code block madhye de.

Complete imports de.

Undefined variables nako.

Missing methods nako.

Complete main/start code de.

External libraries avoid kara.

Scala syntax correct theva.

WindowConstants.EXIT_ON_CLOSE vapra.

Code directly run honyasathi ready de.

Application:
Ithe tu tuza game kiwa app idea lihaycha.

Controls:
Keyboard / Mouse / Buttons.

UI:
Buttons / Score / Levels / Screens.

Error ala tar complete error message ChatGPT la pathva."""
    )

    addTab(
      "COMPONENTS",
      """IMPORTANT COMPONENTS

JFrame
Main window.

JPanel
Components organize karanyasathi.

JLabel
Text display.

JButton
Clickable button.

JTextField
Text input.

JPasswordField
Hidden password input.

JTextArea
Large text.

JScrollPane
Scrolling.

JTabbedPane
Multiple tabs.

JOptionPane
Popup message.

Timer
Repeated game update."""
    )

    addTab(
      "EVENTS",
      """EVENTS

Button click:
ActionListener

Mouse:
MouseListener

Mouse movement:
MouseMotionListener

Keyboard:
KeyListener

Timer:
javax.swing.Timer

Button example:

button.addActionListener(new ActionListener {
  override def actionPerformed(e:ActionEvent):Unit = {
    // button action
  }
})

Mouse coordinates:

e.getX
e.getY

Keyboard:

e.getKeyCode"""
    )

    addTab(
      "GAMES",
      """SCALA SWING GAME STRUCTURE

1. Main Window
2. Game Panel
3. Player
4. Enemies
5. Score
6. Timer
7. Controls
8. Collision
9. Drawing
10. Game Over
11. Restart
12. Win Screen
13. Levels

Game loop:

Timer
  ->
Update
  ->
Collision
  ->
Repaint
  ->
Draw

Drawing methods:

fillRect
fillOval
drawRect
drawOval
drawLine
drawString

Repaint:

repaint()"""
    )

    addTab(
      "DRAWING",
      """DRAWING

Rectangle:

g.fillRect(x,y,width,height)

Circle:

g.fillOval(x,y,width,height)

Line:

g.drawLine(x1,y1,x2,y2)

Text:

g.drawString("Hello",x,y)

Color:

g.setColor(Color.RED)

Font:

g.setFont(new Font("SansSerif",Font.BOLD,24))

Game graphics paintComponent madhye draw karta yetat."""
    )

    addTab(
      "ERRORS",
      """COMMON ERRORS

JFrame.EXIT_ON_CLOSE error:

Use:

WindowConstants.EXIT_ON_CLOSE

illegal start of declaration:

Brace kiwa syntax problem.

not found: value:

Variable kiwa method missing.

not enough arguments:

Method parameters missing.

unclosed string literal:

Closing quote missing.

forward reference:

Variable initialization order problem.

ChatGPT la complete error paste kara.
Fakta ek line nahi, complete error dya."""
    )

    addTab(
      "PROMPTS",
      """READY GAME PROMPT

Mala Scala Swing madhye complete 2D game banvun de.

Player pahije.
Enemies pahijet.
Collision pahije.
Score pahije.
Levels pahijet.
Restart pahije.
Game Over pahije.
Win screen pahije.

Complete imports de.
Complete code de.
Undefined variables nako.
Missing methods nako.
External library nako.
Code directly run honyasathi ready de.

ERROR FIX PROMPT

Ha complete Scala error aahe.

Existing features remove karu naka.

Problem completely fix kara.

Mala full corrected replacement code dya.

Code compile ani run honyasathi ready theva."""
    )

    addTab(
      "IDEAS",
      """PROJECT IDEAS

Beginner:

Calculator
Quiz
Digital Clock
Stopwatch
Drawing App
To Do App

Intermediate:

Snake
Tic Tac Toe
Memory Game
Maze
Puzzle
Brick Breaker
Racing Game

Advanced:

Level Game
Car Game
Platform Game
Physics Puzzle
Score System
Multiple Screens
Save / Load"""
    )

    addTab(
      "REFERENCE",
      """QUICK REFERENCE

JFrame
JPanel
JLabel
JButton
JTextField
JPasswordField
JTextArea
JScrollPane
JTabbedPane
JOptionPane
Timer

Window:

setSize()
setVisible()
setLocationRelativeTo(null)
setDefaultCloseOperation()

Drawing:

fillRect()
fillOval()
drawLine()
drawString()

Game:

repaint()
Timer
Collision
Score
Levels

WORKFLOW

Idea
-> Requirements
-> ChatGPT Prompt
-> Complete Code
-> Run
-> Error
-> Complete Error
-> ChatGPT
-> Corrected Code
-> Run"""
    )

    win.setContentPane(tabs)
    win.setVisible(true)

  } else {
    status.setText("WRONG CODE")
    pass.setText("")
  }
}

enter.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()