-
Notifications
You must be signed in to change notification settings - Fork 47
Simple Example
Trystan May edited this page Jun 1, 2017
·
4 revisions
Here is the same program in both Java and Scala.
This program is provided so that you can see the basics of setting up a panel. It does make use of the € (Euro) character which may not display correctly if your font doesn't contain it. If this causes issues, simply delete the line containing it.
import java.awt.Font;
import javax.swing.JFrame;
import squidpony.squidcolor.SColor;
import squidpony.squidgrid.gui.SGTextPanel;
/**
* Short test of basic functionality of a SGTextPanel.
*
* @author Eben Howard - http://squidpony.com
*/
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
SGTextPanel console = init_console();
JFrame frame = new JFrame("Testing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(console);
console.placeCharacter(12, 12, '€', SColor.AUBURN, SColor.ALIZARIN);
console.placeCharacter(15, 20, (char) 0x2177);
console.placeCharacter(59, 29, 'X', SColor.GREEN_YELLOW, SColor.DARK_SLATE_GRAY);
console.placeCharacter(0, 0, 'X', SColor.GREEN_YELLOW, SColor.DARK_SLATE_GRAY);
console.placeCharacter(59, 0, 'X', SColor.GREEN_YELLOW, SColor.DARK_SLATE_GRAY);
console.placeCharacter(0, 29, 'X', SColor.GREEN_YELLOW, SColor.DARK_SLATE_GRAY);
console.placeHorizontalString(4, 4, "Hello World!");
console.refresh();
frame.setVisible(true);
frame.pack();
frame.setLocationRelativeTo(null);
}
public static SGTextPanel init_console() {
SGTextPanel console = new SGTextPanel();
console.ensureFits(new char[]{0x2177}, false);
console.initialize(15, 15, 60, 30, new Font("Arial Unicode MS", Font.PLAIN, 14));
return console;
}
}
package start;
import java.awt.Font
import javax.swing.JFrame
import squidpony.squidcolor.SColor
import squidpony.squidgrid.gui.SGTextPanel
object Start {
def main(args: Array[String]) {
val console = init_console(80, 50, Font.MONOSPACED, 12)
val frame = new JFrame("Testing")
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
frame.add(console)
console.placeCharacter(49, 49, '€', SColor.AUBURN, SColor.ALIZARIN)
console.placeCharacter(0,0,'X', SColor.GREEN_YELLOW, SColor.DARK_SLATE_GRAY)
console.refresh()
frame.setVisible(true)
frame.pack()
frame.setLocationRelativeTo(null)
}
def init_console(x: Int, y: Int, font: String, font_size: Int): SGTextPanel = {
val console = new SGTextPanel()
console.ensureFits(Array[Char](0x2177), false)
console.initialize(font_size, font_size, x, y, new Font(font, Font.PLAIN, font_size))
return console
}
}