Advertisement
dcndrd

Untitled

Nov 22nd, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 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. prepareOriginCombo(gf.getSpots());
  46. prepareDestinyCombo(gf.getSpots());
  47. }
  48.  
  49. private void prepareWindows() {
  50. windows = new JFrame("CGoes no Mundo da Fantasia");
  51. windows.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  52. }
  53.  
  54. private void prepareMainPanel() {
  55. mainPanel = new JPanel();
  56. mainPanel.setLayout(new BorderLayout());
  57. windows.add(mainPanel);
  58. }
  59.  
  60. private void prepareButtonLoad() {
  61. JButton buttonLoad = new JButton("Carregar arquivo");
  62. buttonLoad.addActionListener(new ActionListener() {
  63. @Override
  64. public void actionPerformed(ActionEvent e) {
  65. JFileChooser chooser = new JFileChooser();
  66. chooser.setFileFilter(new FileNameExtensionFilter("Apenas txt", "txt"));
  67. if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
  68. try {
  69. gf.importSettingsFile(chooser.getSelectedFile().getAbsolutePath());
  70. prepareOriginCombo(gf.getSpots());
  71. prepareDestinyCombo(gf.getSpots());
  72. JOptionPane.showMessageDialog(null, "Arquivo Carregado");
  73. } catch (FileNotFoundException ex) {
  74. JOptionPane.showMessageDialog(null, "Nao foi possivel ler o arquivo");
  75. }
  76. }
  77. }
  78. });
  79.  
  80. mainPanel.add(buttonLoad, BorderLayout.SOUTH);
  81. }
  82.  
  83. private void prepareOriginCombo(Iterator spots) {
  84. if (originCombo == null) {
  85. JPanel originPanel = new JPanel(new GridLayout(1, 2));
  86. originPanel.add(new Label("Escolha a origem"));
  87. originCombo = new JComboBox();
  88. originPanel.add(originCombo);
  89. originCombo.addItem("Vazio!");
  90. JPanel secondPanel = new JPanel();
  91. secondPanel.setLayout(new BorderLayout());
  92. secondPanel.add(originPanel, BorderLayout.NORTH);
  93. mainPanel.add(secondPanel, BorderLayout.WEST);
  94. originCombo.setSize(70, 30);
  95. } else {
  96. originCombo.removeItem("Vazio!");
  97. }
  98. while (spots.hasNext()) {
  99. originCombo.addItem(spots.next().toString());
  100. }
  101. }
  102.  
  103. private void prepareDestinyCombo(Iterator spots) {
  104. if (destinyCombo == null) {
  105. JPanel destinyPanel = new JPanel(new GridLayout(1, 2));
  106. destinyPanel.add(new Label("Escolha o destino"));
  107. destinyCombo = new JComboBox();
  108. destinyPanel.add(destinyCombo);
  109. destinyCombo.addItem("Vazio!");
  110. JPanel secondPanel = new JPanel();
  111. secondPanel.setLayout(new BorderLayout());
  112. secondPanel.add(destinyPanel, BorderLayout.NORTH);
  113. mainPanel.add(secondPanel, BorderLayout.EAST);
  114. destinyCombo.setSize(70, 30);
  115. destinyCombo.updateUI();
  116. } else {
  117. destinyCombo.removeItem("Vazio!");
  118. }
  119. while (spots.hasNext()) {
  120. destinyCombo.addItem(spots.next().toString());
  121. }
  122.  
  123. }
  124.  
  125. private void showWindows() {
  126. windows.pack();
  127. windows.setSize(540, 540);
  128. windows.setVisible(true);
  129. }
  130.  
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement