Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. package Label; // Figura 14.6: LabelFrame.java
  2. //Demonstrando a calsse JLabel.
  3. import java.awt.FlowLayout; // especidifica como os componentes são organizados
  4. import javax.swing.JFrame; // fornece recursos básicos de janela
  5. import javax.swing.JLabel; // exibe texto e imagens
  6. import javax.swing.SwingConstants; // constantes comuns utilizados com Swing
  7. import javax.swing.Icon; // interface utilizada para manipular imagens
  8. import javax.swing.ImageIcon;// carrega imagens
  9.  
  10. public class LabelFrame extends JFrame
  11. {
  12. private JLabel label1; // JLabel apenas com texto
  13. private JLabel label2; // JLabel construído com texto e icone
  14. private JLabel label3; // JLabel com texto e ícone adicionados
  15.  
  16. // construtor LabelFrame adiciona JLabels a JFrame
  17. public LabelFrame()
  18. {
  19. super("Testing JLabel");
  20. setLayout( new FlowLayout ()); // configura o layout de frame
  21.  
  22. //Construtor JLabel com um argumento de string
  23. label1 = new JLabel ("Label with text");
  24. label1.setToolTipText("This is label1");
  25. add( label1 ); // adiciona o label1 ao JFrame
  26.  
  27. // construtor JLabel com string, Icon e argumentos de alinhamento
  28. Icon bug = new ImageIcon(getClass().getResource("bug1.png"));
  29. label2 = new JLabel("Label with text and icon", bug,
  30. SwingConstants.LEFT);
  31. label2.setToolTipText("This is label2");
  32. add(label2); // adiciona label2 ao JFrame
  33.  
  34. label3 = new JLabel(); // Construtor JLabel sem arguemntos
  35. label3.setText("Label with icon text at bottom");
  36. label3.setIcon( bug); // adiciona ao JLabel
  37. label3.setHorizontalTextPosition(SwingConstants.CENTER);
  38. label3.setVerticalTextPosition(SwingConstants.BOTTOM);
  39. label3.setToolTipText("This is label3");
  40. add(label3); // adiciona label3 ao JFrame
  41. }//fim do construtor LabelFrame
  42. }// fim da classe LabelFrame
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement