Guest User

Untitled

a guest
Jul 17th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. package grafo;
  2.  
  3. import javax.swing.*;
  4.  
  5. import java.awt.*;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8. import java.awt.event.KeyEvent;
  9. import java.awt.Toolkit;
  10. import javax.swing.JFrame;
  11. import grafo.Desenho;
  12.  
  13. public class Grafica1 extends JFrame {
  14.  
  15. private Toolkit toolkit;
  16.  
  17. public Grafica1() {
  18.  
  19. toolkit = getToolkit();
  20. Dimension size = toolkit.getScreenSize();
  21.  
  22. //Criando botoes na tela principal
  23. JPanel panel = new JPanel();
  24. getContentPane().add(panel);
  25.  
  26. panel.setLayout(null);
  27.  
  28. JButton caminho = new JButton("Encontre seu caminho");
  29. caminho.setBounds(150, 60, 300, 30);
  30.  
  31. caminho.addActionListener(new ActionListener() {
  32. public void actionPerformed(ActionEvent event) {
  33. toolkit.beep();
  34. }
  35.  
  36.  
  37. });
  38.  
  39.  
  40.  
  41. //Exibir botoes
  42. panel.add(caminho);
  43.  
  44.  
  45. //Criando menu
  46. JMenuBar menubar = new JMenuBar();
  47. ImageIcon saida = new ImageIcon("exit.png");
  48.  
  49. JMenu arquivo = new JMenu("Arquivo");
  50. arquivo.setMnemonic(KeyEvent.VK_F);
  51.  
  52. JMenu help = new JMenu("Ajuda");
  53. arquivo.setMnemonic(KeyEvent.VK_F);
  54. //Escrevendo texto do help
  55. JPanel textPanel = new JPanel(new BorderLayout());
  56. textPanel.setBorder(BorderFactory.createEmptyBorder(15, 25, 15, 25));
  57. JTextPane pane = new JTextPane();
  58.  
  59. pane.setContentType("text/html");
  60. String text = "<p><b>Closing windows using the mouse wheel</b></p>" +
  61. "<p>Clicking with the mouse wheel on an editor tab closes the window. " +
  62. "This method works also with dockable windows or Log window tabs.</p>";
  63. pane.setText(text);
  64. pane.setEditable(false);
  65. textPanel.add(pane);
  66.  
  67.  
  68. JMenuItem novoArquivo = new JMenuItem("Novo");
  69. novoArquivo.setMnemonic(KeyEvent.VK_N);
  70.  
  71. JMenuItem fileClose = new JMenuItem("Close", saida);
  72. fileClose.setMnemonic(KeyEvent.VK_C);
  73. fileClose.setToolTipText("Saida da aplicação");
  74. fileClose.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W,
  75. ActionEvent.CTRL_MASK));
  76.  
  77. fileClose.addActionListener(new ActionListener() {
  78. public void actionPerformed(ActionEvent event) {
  79. System.exit(0);
  80. }
  81.  
  82. });
  83.  
  84.  
  85.  
  86. arquivo.add(novoArquivo);
  87. arquivo.addSeparator();
  88. arquivo.addSeparator();
  89. arquivo.add(fileClose);
  90.  
  91. menubar.add(arquivo);
  92. menubar.add(help);
  93.  
  94. setJMenuBar(menubar);
  95.  
  96.  
  97.  
  98.  
  99. //Criando tela principal
  100. // atribui uma decoração mais bonita a janela
  101. JFrame.setDefaultLookAndFeelDecorated(true);
  102. setTitle("KaMail - Entrega Rápida");
  103. setSize(600, 400);
  104. setLocation((size.width - getWidth())/2, (size.height - getHeight())/2);
  105. setDefaultCloseOperation(EXIT_ON_CLOSE);
  106. setLocationRelativeTo(null);
  107.  
  108. }
  109.  
  110. public static void main(String[] args) {
  111.  
  112. Grafica1 buttons = new Grafica1();
  113. Grafica1 simple = new Grafica1();
  114. simple.setVisible(true);
  115. Grafica1 menubar = new Grafica1();
  116. Desenho novoDesenho = new Desenho();
  117.  
  118. }
  119. }
Add Comment
Please, Sign In to add comment