Advertisement
dcndrd

Untitled

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