Advertisement
Guest User

Untitled

a guest
May 2nd, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.69 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4.  
  5. import javax.swing.*;
  6. import javax.swing.border.*;
  7.  
  8. public class NewGui extends JPanel {
  9.  
  10.     // GUI runs in main method, and calls GamePrimer to do logic
  11.     public static void main(String[] args) {
  12.        
  13.         GamePrimer coffee = new GamePrimer();
  14.        
  15.         int number = 1;
  16.         int floor;
  17.         int ceiling;
  18.        
  19.         JFrame frame = new JFrame("New Layout");
  20.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  21.  
  22.         JPanel mainPanel = new JPanel();
  23.         mainPanel.setLayout(new GridLayout(3, 1));
  24.         mainPanel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
  25.  
  26.         JPanel top = new JPanel();
  27.         top.setLayout(new GridLayout(2, 3, 8, 10));
  28.         top.setBorder(BorderFactory.createLineBorder(Color.gray, 3));
  29.         top.add(new JLabel("Worst TO Margin"));
  30.         top.add(new JLabel("Number of Games"));
  31.         top.add(new JLabel("Best TO Margin"));
  32.         top.add(new JLabel(String.valueOf(coffee.getMin())));
  33.         top.add(new JLabel(String.valueOf(coffee.getTotal())));
  34.         top.add(new JLabel(String.valueOf(coffee.getMax())));
  35.  
  36.         JPanel middle = new JPanel();
  37.         middle.setLayout(new GridLayout(2, 2, 3, 3));
  38.         middle.setBorder(BorderFactory.createLineBorder(Color.gray, 3));
  39.         middle.add(new JLabel("Floor"));
  40.         middle.add(new JLabel("Ceiling"));
  41.  
  42.         final JTextField floorText = new JTextField();
  43.         final JTextField ceilingText = new JTextField();
  44.  
  45.         floorText.addActionListener(new ActionListener() {
  46.             @Override
  47.             public void actionPerformed(ActionEvent arg0) {
  48.                 System.out.println("Floor: " + floorText.getText());
  49.             }
  50.         });
  51.  
  52.         ceilingText.addActionListener(new ActionListener() {
  53.             @Override
  54.             public void actionPerformed(ActionEvent arg0) {
  55.                 System.out.println("Ceiling: " + ceilingText.getText());
  56.             }
  57.         });
  58.  
  59.         try {
  60.         floor = Integer.valueOf(floorText.getText());
  61.         System.out.println(floor);
  62.         } catch (NumberFormatException e1){
  63.             System.out.println("Uh oh! Whatevs...");
  64.         }
  65.        
  66.         // ceiling = Integer.valueOf(ceilingText.getText());
  67.  
  68.         middle.add(floorText);
  69.         middle.add(ceilingText);
  70.  
  71.         JPanel bottom = new JPanel();
  72.         bottom.setLayout(new GridLayout(2, 3, 3, 3));
  73.         bottom.setBorder(BorderFactory.createLineBorder(Color.gray, 3));
  74.         bottom.add(new JLabel("Games below floor"));
  75.         bottom.add(new JLabel("Games between"));
  76.         bottom.add(new JLabel("Games above ceiling"));
  77.         bottom.add(new JLabel(String.valueOf(107)));
  78.         bottom.add(new JLabel(String.valueOf(116)));
  79.         bottom.add(new JLabel(String.valueOf(42)));
  80.  
  81.         mainPanel.add(top);
  82.         mainPanel.add(middle);
  83.         mainPanel.add(bottom);
  84.  
  85.         frame.add(mainPanel);
  86.  
  87.         frame.getContentPane().add(mainPanel);
  88.         frame.pack();
  89.         frame.setVisible(true);
  90.  
  91.     }
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement