bd-jb/com/bdjb/Screen.java

48 lines
1.1 KiB
Java
Raw Normal View History

2021-10-24 11:23:44 -04:00
/*
* Copyright (C) 2021 Andy Nguyen
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
package com.bdjb;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.Graphics;
import java.util.ArrayList;
public class Screen extends Container {
2021-10-28 12:15:33 -04:00
private static final long serialVersionUID = 0x4141414141414141L;
2021-10-24 11:23:44 -04:00
private static final Font FONT = new Font(null, Font.PLAIN, 36);
private static final ArrayList messages = new ArrayList();
private static final Screen instance = new Screen();
public static Screen getInstance() {
2021-10-24 11:23:44 -04:00
return instance;
}
public static void println(String msg) {
2021-10-24 11:23:44 -04:00
messages.add(msg);
instance.repaint();
}
public void paint(Graphics g) {
g.setFont(FONT);
g.setColor(Color.WHITE);
int x = 100;
int y = 100;
int height = g.getFontMetrics().getHeight();
for (int i = 0; i < messages.size(); i++) {
String msg = (String) messages.get(i);
g.drawString(msg, x, y);
y += height;
}
}
}