Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.*;
- import javax.swing.border.*;
- public class NewGui extends JPanel {
- // GUI runs in main method, and calls GamePrimer to do logic
- public static void main(String[] args) {
- GamePrimer coffee = new GamePrimer();
- int number = 1;
- int floor;
- int ceiling;
- JFrame frame = new JFrame("New Layout");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- JPanel mainPanel = new JPanel();
- mainPanel.setLayout(new GridLayout(3, 1));
- mainPanel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
- JPanel top = new JPanel();
- top.setLayout(new GridLayout(2, 3, 8, 10));
- top.setBorder(BorderFactory.createLineBorder(Color.gray, 3));
- top.add(new JLabel("Worst TO Margin"));
- top.add(new JLabel("Number of Games"));
- top.add(new JLabel("Best TO Margin"));
- top.add(new JLabel(String.valueOf(coffee.getMin())));
- top.add(new JLabel(String.valueOf(coffee.getTotal())));
- top.add(new JLabel(String.valueOf(coffee.getMax())));
- JPanel middle = new JPanel();
- middle.setLayout(new GridLayout(2, 2, 3, 3));
- middle.setBorder(BorderFactory.createLineBorder(Color.gray, 3));
- middle.add(new JLabel("Floor"));
- middle.add(new JLabel("Ceiling"));
- final JTextField floorText = new JTextField();
- final JTextField ceilingText = new JTextField();
- floorText.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent arg0) {
- System.out.println("Floor: " + floorText.getText());
- }
- });
- ceilingText.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent arg0) {
- System.out.println("Ceiling: " + ceilingText.getText());
- }
- });
- try {
- floor = Integer.valueOf(floorText.getText());
- System.out.println(floor);
- } catch (NumberFormatException e1){
- System.out.println("Uh oh! Whatevs...");
- }
- // ceiling = Integer.valueOf(ceilingText.getText());
- middle.add(floorText);
- middle.add(ceilingText);
- JPanel bottom = new JPanel();
- bottom.setLayout(new GridLayout(2, 3, 3, 3));
- bottom.setBorder(BorderFactory.createLineBorder(Color.gray, 3));
- bottom.add(new JLabel("Games below floor"));
- bottom.add(new JLabel("Games between"));
- bottom.add(new JLabel("Games above ceiling"));
- bottom.add(new JLabel(String.valueOf(107)));
- bottom.add(new JLabel(String.valueOf(116)));
- bottom.add(new JLabel(String.valueOf(42)));
- mainPanel.add(top);
- mainPanel.add(middle);
- mainPanel.add(bottom);
- frame.add(mainPanel);
- frame.getContentPane().add(mainPanel);
- frame.pack();
- frame.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement