Advertisement
dcndrd

Untitled

Nov 22nd, 2014
465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.35 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package br.uefs.ecomp.Game.GraphicInterface;
  7.  
  8. import br.uefs.ecomp.Game.facade.GameFacade;
  9. import java.awt.BorderLayout;
  10. import java.awt.FlowLayout;
  11. import java.awt.GridLayout;
  12. import java.awt.Label;
  13. import java.awt.event.ActionEvent;
  14. import java.awt.event.ActionListener;
  15. import java.io.FileNotFoundException;
  16. import java.util.Iterator;
  17. import javax.swing.*;
  18. import javax.swing.filechooser.FileNameExtensionFilter;
  19.  
  20. /**
  21. *
  22. * @author dcandrade
  23. */
  24. public class MainInterface {
  25.  
  26. private static GameFacade gf;
  27. private JFrame windows;
  28. private JPanel mainPanel;
  29. JComboBox originCombo;
  30. JComboBox destinyCombo;
  31.  
  32. public MainInterface() {
  33. gf = new GameFacade();
  34. }
  35.  
  36. public static void main(String[] args) {
  37. new MainInterface().createScreen();
  38. }
  39.  
  40. private void createScreen() {
  41. prepareWindows();
  42. prepareMainPanel();
  43. prepareButtonLoad();
  44. showWindows();
  45. prepareCombos();
  46. // prepareOriginCombo(gf.getSpots());
  47. //prepareDestinyCombo(gf.getSpots());
  48. }
  49.  
  50. private void prepareWindows() {
  51. windows = new JFrame("CGoes no Mundo da Fantasia");
  52. windows.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  53. }
  54.  
  55. private void prepareMainPanel() {
  56. mainPanel = new JPanel();
  57. mainPanel.setLayout(new BorderLayout());
  58. windows.add(mainPanel);
  59. }
  60.  
  61. private void prepareButtonLoad() {
  62. JButton buttonLoad = new JButton("Carregar arquivo");
  63. buttonLoad.addActionListener(new ActionListener() {
  64. @Override
  65. public void actionPerformed(ActionEvent e) {
  66. JFileChooser chooser = new JFileChooser();
  67. chooser.setFileFilter(new FileNameExtensionFilter("Apenas txt", "txt"));
  68. if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
  69. try {
  70. gf.importSettingsFile(chooser.getSelectedFile().getAbsolutePath());
  71. prepareOriginCombo(gf.getSpots());
  72. prepareDestinyCombo(gf.getSpots());
  73. JOptionPane.showMessageDialog(null, "Arquivo Carregado");
  74. } catch (FileNotFoundException ex) {
  75. JOptionPane.showMessageDialog(null, "Nao foi possivel ler o arquivo");
  76. }
  77. }
  78. }
  79. });
  80.  
  81. mainPanel.add(buttonLoad, BorderLayout.SOUTH);
  82. }
  83.  
  84. private void prepareCombos() {
  85. prepareOriginCombo(gf.getSpots());
  86. prepareDestinyCombo(gf.getSpots());
  87.  
  88. JPanel originPanel = new JPanel(new GridLayout(1, 2));
  89. originPanel.add(new Label("Escolha a origem"));
  90. originPanel.add(originCombo);
  91.  
  92. JPanel destinyPanel = new JPanel(new GridLayout(1, 2));
  93. destinyPanel.add(new Label("Escolha o destino"));
  94. destinyPanel.add(destinyCombo);
  95.  
  96. JPanel combos = new JPanel(new BorderLayout());
  97. combos.add(originPanel, BorderLayout.EAST);
  98. combos.add(destinyPanel, BorderLayout.WEST);
  99. mainPanel.add(combos, BorderLayout.NORTH);
  100. mainPanel.updateUI();
  101. }
  102.  
  103. private void prepareOriginCombo(Iterator spots) {
  104. if (originCombo == null) {
  105. originCombo = new JComboBox();
  106. originCombo.addItem("Vazio!");
  107. originCombo.setSize(70, 30);
  108. } else {
  109. originCombo.removeItem("Vazio!");
  110. }
  111. while (spots.hasNext()) {
  112. originCombo.addItem(spots.next().toString());
  113. }
  114. }
  115.  
  116. private void prepareDestinyCombo(Iterator spots) {
  117. if (destinyCombo == null) {
  118. destinyCombo = new JComboBox();
  119. destinyCombo.addItem("Vazio!");
  120. destinyCombo.setSize(70, 30);
  121. destinyCombo.updateUI();
  122. } else {
  123. destinyCombo.removeItem("Vazio!");
  124. }
  125. while (spots.hasNext()) {
  126. destinyCombo.addItem(spots.next().toString());
  127. }
  128.  
  129. }
  130.  
  131. private void showWindows() {
  132. windows.pack();
  133. windows.setSize(540, 540);
  134. windows.setVisible(true);
  135. }
  136.  
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement