Svetli0o

field

May 15th, 2014
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Component;
  3. import java.awt.Container;
  4. import java.awt.image.BufferedImage;
  5. import java.io.File;
  6. import java.io.IOException;
  7.  
  8. import javax.imageio.ImageIO;
  9. import javax.swing.BoxLayout;
  10. import javax.swing.ImageIcon;
  11. import javax.swing.JButton;
  12. import javax.swing.JFrame;
  13. import javax.swing.JLabel;
  14.  
  15.  
  16. public class Field {
  17.     public static void addComponentsToPane(Container pane) {
  18.         pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
  19.         BufferedImage myPicture = null;
  20.         try {
  21.             myPicture = ImageIO.read(new File("D:\\Software-University\\Field - Copy2.jpg"));
  22.         } catch (IOException e) {
  23.             // TODO Auto-generated catch block
  24.             e.printStackTrace();
  25.         }
  26.         JLabel picLabel = new JLabel(new ImageIcon(myPicture));
  27.         pane.add(picLabel);
  28.     }
  29.    
  30.     /*
  31.      * Create the GUI and show it.
  32.      */
  33.     private static void createAndShowGUI() {
  34.         //Create and set up the window.
  35.         JFrame frame = new JFrame("Game frame");
  36.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  37.  
  38.         //Set up the content pane.
  39.         addComponentsToPane(frame.getContentPane());
  40.         //Display the window.
  41.         frame.setSize(1005, 735);
  42.         frame.setResizable(false);
  43.         frame.setTitle("Pong");
  44.         frame.setLocationRelativeTo(null);
  45.         frame.setVisible(true);
  46.     }
  47.  
  48.     public static void main(String[] args) {
  49.         //creating and showing this application's GUI.
  50.         javax.swing.SwingUtilities.invokeLater(new Runnable() {
  51.             public void run() {
  52.                 createAndShowGUI();
  53.             }
  54.         });
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment