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. Hashtag 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now