Advertisement
Guest User

Untitled

a guest
Apr 13th, 2013
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.03 KB | None | 0 0
  1. package ramble_on.panels;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.Graphics;
  5. import java.awt.Image;
  6. import java.awt.image.BufferedImage;
  7. import javax.swing.JComboBox;
  8. import javax.swing.JPanel;
  9. import mini_game.Sprite;
  10. import mini_game.SpriteType;
  11. import ramble_on.RambleOn;
  12. import ramble_on.events.WelcomeScreenHandler;
  13.  
  14.  
  15. public class SelectAccountPanel extends JPanel
  16. {
  17.     private static final String IMAGES_PATH = "./data/images/";
  18.     private static final String BACKGROUND_IMAGE_PATH = IMAGES_PATH + "selectAccount.png";
  19.     private static final String SELECT_ACCOUNT_TYPE = "SELECT ACCOUNT TYPE";
  20.     private static final String DEFAULT_STATE = "DEFAULT STATE";
  21.     private JPanel flowPanel;
  22.     private Sprite background;
  23.     private RambleOn game;
  24.    
  25.     public SelectAccountPanel(RambleOn g)
  26.     {
  27.         super();
  28.         game = g;
  29.         SpriteType st = new SpriteType(SELECT_ACCOUNT_TYPE);
  30.         BufferedImage img = game.loadImage(BACKGROUND_IMAGE_PATH);
  31.         st.addState(DEFAULT_STATE, img);
  32.        
  33.         background = new Sprite(st,0,0,0,0, DEFAULT_STATE);
  34.        
  35.         //TODO add action listener
  36.         //WelcomeScreenHandler wsh = new WelcomeScreenHandler(game);
  37.         String[] accounts = {"Fred", "Joe", "Mike", "Jake"};
  38.         JComboBox comboBox = new JComboBox(accounts);
  39.         comboBox.setEditable(false);
  40.         comboBox.setLocation(450, 450);
  41.        // flowPanel = new JPanel();
  42.        // flowPanel.add(comboBox);
  43.         this.add(comboBox, BorderLayout.CENTER);
  44.        
  45.        // background.setActionListener(wsh);
  46.         img = game.loadImage(BACKGROUND_IMAGE_PATH);
  47.         game.getGUIDecor().put(SELECT_ACCOUNT_TYPE, background);
  48.     }
  49.    
  50.       /**
  51.      * This is where rendering starts. Note that the order of
  52.      * rendering is of particular importance, since things drawn
  53.      * first will be on the bottom, and things rendered last will
  54.      * be on top.
  55.      *
  56.      * @param g the Graphics context for this panel. Draw commands
  57.      * given through g will render things onto this panel.
  58.      */
  59.     @Override
  60.     public void paintComponent(Graphics g)
  61.     {
  62.         renderToGraphicsContext(g);
  63.     }
  64.  
  65.     private void renderToGraphicsContext(Graphics g)
  66.     {
  67.         Sprite img = game.getGUIDecor().get(SELECT_ACCOUNT_TYPE);
  68.         renderSprite(g, img);
  69.     }
  70.       public String getType()
  71.     {
  72.         return SELECT_ACCOUNT_TYPE;
  73.     }
  74.     /**
  75.      * Renders the s Sprite into the Graphics context g. Note
  76.      * that each Sprite knows its own x,y coordinate location.
  77.      *
  78.      * @param g the Graphics context of this panel
  79.      *
  80.      * @param s the Sprite to be rendered
  81.      */
  82.     public void renderSprite(Graphics g, Sprite s)
  83.     {
  84.         //if (!s.getState().equals(INVISIBLE_STATE))
  85.         {
  86.             SpriteType bgST = s.getSpriteType();
  87.             Image img = bgST.getStateImage(s.getState());
  88.             g.drawImage(img, (int)s.getX(), (int)s.getY(),bgST.getWidth(), bgST.getHeight(), null);
  89.         }
  90.     }
  91.    
  92.    
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement