Skip to content

Instantly share code, notes, and snippets.

@sylvia43
Created August 24, 2015 23:29
Show Gist options
  • Save sylvia43/8a4de941cea7c1408fe5 to your computer and use it in GitHub Desktop.
Save sylvia43/8a4de941cea7c1408fe5 to your computer and use it in GitHub Desktop.
Scala vs. Java
import asciiPanel.AsciiPanel;
import game.screens.Screen;
import game.screens.StartScreen;
import java.awt.Color;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
public class Window extends JFrame implements KeyListener {
private AsciiPanel terminal;
public Window() {
super();
terminal = new AsciiPanel();
add(terminal);
pack();
addKeyListener(this);
repaint();
}
@Override
public void repaint() {
terminal.clear();
terminal.writeCenter("HELLO!!!1", 10);
super.repaint();
}
@Override
public void keyPressed(KeyEvent e) {
screen = screen.respondToUserInput(e);
repaint();
}
@Override
public void keyReleased(KeyEvent e) { }
@Override
public void keyTyped(KeyEvent e) { }
public static void main(String[] args) {
Window window = new Window();
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setVisible(true);
window.setBackground(Color.black);
window.setTitle("Dungeon Dive");
}
}
import java.awt.Color
import java.awt.event.{KeyEvent, KeyListener}
import javax.swing.JFrame
import asciiPanel.AsciiPanel
object Window extends JFrame() with KeyListener {
def main (args: Array[String]) {
Window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
Window.setVisible(true)
Window.setBackground(Color.BLACK)
Window.setTitle("ScalaRL")
}
val terminal = new AsciiPanel()
add(terminal)
pack()
addKeyListener(this)
repaint()
println("created")
override def repaint(): Unit = {
println("repaint")
terminal.clear()
terminal.writeCenter("HELLO!!!1", 10)
super.repaint()
}
override def keyPressed(e: KeyEvent): Unit = {
}
override def keyTyped(e: KeyEvent): Unit = ???
override def keyReleased(e: KeyEvent): Unit = ???
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment