Downsidelama 2 Share Posted April 28, 2019 import java.awt.*; import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; /** * Draws settings to the screen. */ public class SettingsDrawer { private final Color color = new Color(255, 255, 255); private final Font font = new Font("Arial", 0, 20); private Map<String, String> settings; private static SettingsDrawer instance; public static SettingsDrawer getInstance() { if(instance == null) { instance = new SettingsDrawer(); } return instance; } private SettingsDrawer() { settings = new HashMap<>(); } public void addSetting(String setting, String value) { this.settings.put(setting, value); } public void draw(Graphics g) { AtomicInteger y = new AtomicInteger(40); int x = 20; int increment = 30; g.setFont(font); g.setColor(color); settings.forEach((k, v) -> { g.drawString(String.format("%s: %s", k, v), x, y.get()); y.addAndGet(increment); }); } } Call the draw(g) function in the onPaint function. Call the addSetting(...) method to insert things to display. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.