Advertisement
Guest User

Untitled

a guest
Nov 1st, 2019
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. //TEXT
  2. public void drawText(Graphics g, String textFile) {
  3.  
  4. int y = 110;
  5.  
  6. String text = "", firstLine = "";
  7.  
  8. FileReader fr;
  9.  
  10. try {
  11.  
  12. fr = new FileReader(textFile);
  13. BufferedReader reader = new BufferedReader(fr);
  14. firstLine = reader.readLine();
  15. reader.close();
  16. } catch (IOException e1) {
  17.  
  18. e1.printStackTrace();
  19. }
  20.  
  21. try {
  22. text = new String(Files.readAllBytes(Paths.get(textFile)), "MS932");
  23. } catch (IOException e) {
  24.  
  25. e.printStackTrace();
  26. }
  27.  
  28. g.setColor(Color.WHITE);
  29. g.drawString(g.getFontMetrics().stringWidth(text) + " - " + g.getFontMetrics().stringWidth(firstLine), 32, 160);
  30.  
  31. y += textScroll;
  32.  
  33. g.setColor(Color.LIGHT_GRAY);
  34. for (String line : text.split("\n"))
  35. g.drawString(line, getWidth() / 2 - g.getFontMetrics(gameFont).stringWidth(firstLine) / 2, y += g.getFontMetrics().getHeight());
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement