Guest User

Untitled

a guest
Oct 30th, 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. public void drawText(Graphics g, String textFile) {
  2.  
  3. int y = 110;
  4.  
  5. String text = " ", firstLine = " ";
  6.  
  7. FileReader fr;
  8.  
  9. try {
  10.  
  11. fr = new FileReader(textFile);
  12. BufferedReader reader = new BufferedReader(fr);
  13. firstLine = reader.readLine();
  14. reader.close();
  15. } catch (IOException e1) {
  16.  
  17. e1.printStackTrace();
  18. }
  19.  
  20. try {
  21. text = new String(Files.readAllBytes(Paths.get(textFile)), "MS932");
  22. } catch (IOException e) {
  23.  
  24. e.printStackTrace();
  25. }
  26.  
  27. //g.setColor(Color.WHITE);
  28. //g.drawString(g.getFontMetrics().stringWidth(text) + " - " + g.getFontMetrics().stringWidth(firstLine), 32, 160);
  29.  
  30. y += textScroll;
  31.  
  32. g.setColor(Color.LIGHT_GRAY);
  33. for (String line : text.split("\n"))
  34. g.drawString(line, getWidth() / 2 - g.getFontMetrics(gameFont).stringWidth(firstLine) / 2, y += g.getFontMetrics().getHeight());
  35. }
Advertisement
Add Comment
Please, Sign In to add comment