Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package br.uefs.ecomp.Game.GraphicInterface;
- import br.uefs.ecomp.Game.facade.GameFacade;
- import java.awt.BorderLayout;
- import java.awt.FlowLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.io.FileNotFoundException;
- import java.util.Iterator;
- import javax.swing.*;
- import javax.swing.filechooser.FileNameExtensionFilter;
- /**
- *
- * @author dcandrade
- */
- public class MainInterface {
- private static GameFacade gf;
- private JFrame windows;
- private JPanel mainPanel;
- JComboBox originCombo;
- JComboBox destinyCombo;
- public MainInterface() {
- gf = new GameFacade();
- }
- public static void main(String[] args) {
- new MainInterface().createScreen();
- }
- private void createScreen() {
- prepareWindows();
- prepareMainPanel();
- prepareButtonLoad();
- showWindows();
- prepareOriginCombo(gf.getSpots());
- prepareDestinyCombo(gf.getSpots());
- }
- private void prepareWindows() {
- windows = new JFrame("CGoes no Mundo da Fantasia");
- windows.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
- private void prepareMainPanel() {
- mainPanel = new JPanel();
- mainPanel.setLayout(new BorderLayout());
- windows.add(mainPanel);
- }
- private void prepareButtonLoad() {
- JButton buttonLoad = new JButton("Carregar arquivo");
- buttonLoad.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- JFileChooser chooser = new JFileChooser();
- chooser.setFileFilter(new FileNameExtensionFilter("Apenas txt", "txt"));
- if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
- try {
- gf.importSettingsFile(chooser.getSelectedFile().getAbsolutePath());
- prepareOriginCombo(gf.getSpots());
- prepareDestinyCombo(gf.getSpots());
- JOptionPane.showMessageDialog(null, "Arquivo Carregado");
- } catch (FileNotFoundException ex) {
- JOptionPane.showMessageDialog(null, "Nao foi possivel ler o arquivo");
- }
- }
- }
- });
- mainPanel.add(buttonLoad, BorderLayout.SOUTH);
- }
- private void prepareOriginCombo(Iterator spots) {
- if (originCombo == null) {
- originCombo = new JComboBox();
- originCombo.addItem("Vazio!");
- JPanel secondPanel = new JPanel();
- secondPanel.setLayout(new BorderLayout());
- secondPanel.add(originCombo, BorderLayout.NORTH);
- mainPanel.add(secondPanel, BorderLayout.WEST);
- originCombo.setSize(70, 30);
- } else {
- originCombo.removeItem("Vazio!");
- }
- while (spots.hasNext()) {
- originCombo.addItem(spots.next().toString());
- }
- }
- private void prepareDestinyCombo(Iterator spots) {
- if (destinyCombo == null) {
- destinyCombo = new JComboBox();
- destinyCombo.addItem("Vazio!");
- JPanel secondPanel = new JPanel();
- secondPanel.setLayout(new BorderLayout());
- secondPanel.add(destinyCombo, BorderLayout.NORTH);
- mainPanel.add(secondPanel, BorderLayout.EAST);
- destinyCombo.setSize(70, 30);
- destinyCombo.updateUI();
- } else {
- destinyCombo.removeItem("Vazio!");
- }
- while (spots.hasNext()) {
- destinyCombo.addItem(spots.next().toString());
- }
- }
- private void showWindows() {
- windows.pack();
- windows.setSize(540, 540);
- windows.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement