Advertisement
Guest User

Untitled

a guest
Feb 17th, 2015
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.62 KB | None | 0 0
  1. package gui;
  2.  
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5.  
  6. import javax.swing.DefaultComboBoxModel;
  7. import javax.swing.JButton;
  8. import javax.swing.JComboBox;
  9. import javax.swing.JFrame;
  10. import javax.swing.JPanel;
  11. import javax.swing.SwingUtilities;
  12.  
  13. import data.Data;
  14.  
  15. public class GUI extends JFrame {
  16.    
  17.     private JFrame frame;
  18.     private boolean start;
  19.     private static int chosenBarType;
  20.     private static JComboBox<Object> barTypeJCB;
  21.  
  22.     public GUI() {
  23.         gui();
  24.     }
  25.    
  26.    
  27.     public void gui() {
  28.        
  29.         frame = new JFrame("Smelter");
  30.        
  31.         frame.setSize(250, 80);
  32.         frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
  33.         frame.setLocationRelativeTo(null);
  34.        
  35.         JPanel panel = new JPanel();
  36.        
  37.         JPanel optionsPanel = new JPanel();
  38.        
  39.         barTypeJCB = new JComboBox<>();
  40.         barTypeJCB.setModel(new DefaultComboBoxModel<Object>(Data.bars));
  41.         optionsPanel.add(barTypeJCB);
  42.        
  43.         panel.add(optionsPanel);
  44.        
  45.         JButton startButton = new JButton("Start");
  46.         startButton.addActionListener(new ActionListener() {
  47.  
  48.             @Override
  49.             public void actionPerformed(ActionEvent e) {
  50.                     chosenBarType = barTypeJCB.getSelectedIndex();
  51.                     start = true;
  52.                     frame.dispose();
  53.             }
  54.         });
  55.        
  56.         panel.add(startButton);
  57.         frame.add(panel);
  58.        
  59.         SwingUtilities.invokeLater(new Runnable() {
  60.  
  61.             @Override
  62.             public void run() {
  63.                 frame.setVisible(true);
  64.             }
  65.         });
  66.     }
  67.    
  68.     public static int getBarType() {
  69.         return chosenBarType;
  70.     }
  71.    
  72.     public static String getBarTypeString() {
  73.         return Data.bars[barTypeJCB.getSelectedIndex()];
  74.     }
  75.    
  76.     public boolean getStart() {
  77.         return start;
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement