Advertisement
dcndrd

Untitled

Nov 22nd, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.68 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.event.ActionEvent;
  11. import java.awt.event.ActionListener;
  12. import java.io.FileNotFoundException;
  13. import java.util.Iterator;
  14. import javax.swing.*;
  15. import javax.swing.filechooser.FileNameExtensionFilter;
  16.  
  17. /**
  18.  *
  19.  * @author dcandrade
  20.  */
  21. public class MainInterface {
  22.  
  23.     private static GameFacade gf;
  24.     private JFrame windows;
  25.     private JPanel mainPanel;
  26.     JComboBox originCombo;
  27.     JComboBox destinyCombo;
  28.  
  29.     public MainInterface() {
  30.         gf = new GameFacade();
  31.     }
  32.  
  33.     public static void main(String[] args) {
  34.         new MainInterface().createScreen();
  35.     }
  36.  
  37.     private void createScreen() {
  38.         prepareWindows();
  39.         prepareMainPanel();
  40.         prepareButtonLoad();
  41.         showWindows();
  42.         prepareOriginCombo(gf.getSpots());
  43.         prepareDestinyCombo(gf.getSpots());
  44.     }
  45.  
  46.     private void prepareWindows() {
  47.         windows = new JFrame("CGoes no Mundo da Fantasia");
  48.         windows.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  49.     }
  50.  
  51.     private void prepareMainPanel() {
  52.         mainPanel = new JPanel();
  53.         mainPanel.setLayout(new BorderLayout());
  54.         windows.add(mainPanel);
  55.     }
  56.  
  57.     private void prepareButtonLoad() {
  58.         JButton buttonLoad = new JButton("Carregar arquivo");
  59.         buttonLoad.addActionListener(new ActionListener() {
  60.             @Override
  61.             public void actionPerformed(ActionEvent e) {
  62.                 JFileChooser chooser = new JFileChooser();
  63.                 chooser.setFileFilter(new FileNameExtensionFilter("Apenas txt", "txt"));
  64.                 if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
  65.                     try {
  66.                         gf.importSettingsFile(chooser.getSelectedFile().getAbsolutePath());
  67.                         prepareOriginCombo(gf.getSpots());
  68.                         prepareDestinyCombo(gf.getSpots());
  69.                         JOptionPane.showMessageDialog(null, "Arquivo Carregado");
  70.                     } catch (FileNotFoundException ex) {
  71.                         JOptionPane.showMessageDialog(null, "Nao foi possivel ler o arquivo");
  72.                     }
  73.                 }
  74.             }
  75.         });
  76.  
  77.         mainPanel.add(buttonLoad, BorderLayout.SOUTH);
  78.     }
  79.  
  80.     private void prepareOriginCombo(Iterator spots) {
  81.         if (originCombo == null) {
  82.             originCombo = new JComboBox();
  83.             originCombo.addItem("Vazio!");
  84.             mainPanel.add(originCombo, BorderLayout.WEST);
  85.             originCombo.setSize(70, 30);
  86.         } else {
  87.             originCombo.removeItem("Vazio!");
  88.         }
  89.         originCombo.updateUI();
  90.         while (spots.hasNext()) {
  91.             originCombo.addItem(spots.next().toString());
  92.         }
  93.  
  94.     }
  95.  
  96.     private void prepareDestinyCombo(Iterator spots) {
  97.         if (destinyCombo == null) {
  98.             destinyCombo = new JComboBox();
  99.             destinyCombo.addItem("Vazio!");
  100.             mainPanel.add(destinyCombo, BorderLayout.EAST);
  101.             destinyCombo.setSize(70, 30);
  102.         } else {
  103.             destinyCombo.removeItem("Vazio!");
  104.         }
  105.         destinyCombo.updateUI();
  106.         while (spots.hasNext()) {
  107.             destinyCombo.addItem(spots.next().toString());
  108.         }
  109.  
  110.     }
  111.  
  112.     private void showWindows() {
  113.         windows.pack();
  114.         windows.setSize(540, 540);
  115.         windows.setVisible(true);
  116.     }
  117.  
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement