Guest User

Untitled

a guest
Oct 18th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. package tuplanolla.unnamed;
  2.  
  3. import java.awt.*;
  4. import java.awt.event.*;
  5.  
  6. /**
  7. dirty test case
  8. **/
  9. public class Test extends Canvas {
  10. private static Frame display = new Frame("Title");
  11. private static void init() {
  12. WindowListener window = new WindowAdapter() {
  13. public void windowOpened(WindowEvent event) {
  14. Font font = new Font("Times New Roman", Font.PLAIN, 32);
  15. FontMetrics metrics = display.getFontMetrics(font);
  16. display.setSize(metrics./*getMaxAdvance()*/charWidth('@')*32, metrics.getHeight()*8);
  17. Component component = new Label("", Label.CENTER);
  18. Label label = (Label)component;
  19. label.setText("This is not in Times New Roman.");
  20. label.setFont(font);
  21. label.setForeground(Color.GRAY);
  22. label.setBackground(Color.BLACK);
  23. display.add(component, BorderLayout.CENTER);
  24. }
  25.  
  26. public void windowClosing(WindowEvent event) {
  27. display.setVisible(false);
  28. display.dispose();
  29. }
  30.  
  31. public void windowClosed(WindowEvent event) {
  32. System.exit(0);
  33. }
  34. };
  35. display.addWindowListener(window);
  36. display.setResizable(false);
  37. display.setVisible(true);
  38. }
  39. public static void main(String[] argv) {
  40. Test test = new Test();
  41. test.init();
  42. }
  43. }
Add Comment
Please, Sign In to add comment