Ja. Zum Glück. Sonst müsste ich ja irgendwann alles selbst programmieren und könnte nicht sagen: "Programmier mir das mal!".
Themabewertung:
Total Spam
|
package de.mewking.mewland;
import java.awt.Component; public class MewlandMain { /** * The version of the project. */ public static final String version = "v2.3.0.1a"; /** * The window's frame. */ private JFrame frame; /** * The savegame. */ private SaveGame save; /** * The content panel on the frame. */ private JPanel panel; /** * Buttons on the menu screen. */ private JButton[] menu_b; /** * The menu panel. */ private JPanel menu; /** * The map component. */ private ImagePanel map_r; /** * The player instance. */ private Player player; /** * Size of the window before menu opened. */ private int[] winsize = new int[2]; /** * The map instance. */ private Map map; /** * Whether user can leave screen with SPACE. */ private boolean canLeave = true; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { MewlandMain window = new MewlandMain(); window.getFrame().setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the application. */ public MewlandMain() { Language.setUp(); initialize(); } /** * Initialize the contents of the frame. */ private void initialize() { setSave(new SaveGame()); getSave().setPlayername("Mewking"); //Create new player object setPlayer(new Player()); //Create new map object setMapObj(new Map("wildwood_city")); //Pass this to player instance getPlayer().setMain(this); //Initialize the frame initializeFrame(); //Initialize the panel initializePanel(); initializeMenu(); //Fill the frame with the panel fillFrame(); //Create new ImagePanel for the map ImagePanel ip_map = new ImagePanel(getImageResource(getMapObj().getMapResource())); //Calculate bounds ip_map.setBounds(0, 0, ip_map.getWidth(), ip_map.getHeight()); //Add map to panel addToContentPanel(ip_map); //Set map setMap(ip_map); //Create new ImagePanel for the player ImagePanel ip_pla = new ImagePanel(getImageResource(getPlayer().getImage())); //Calculate bounds ip_pla.setBounds(128, 128, ip_pla.getWidth(), ip_pla.getHeight()); //Force the player to be transparent ip_pla.forceTransparent(getMap().getImg(), ip_pla); //Add the player to the map getMap().add(ip_pla); //Set player instance's component to the player component getPlayer().setComp(ip_pla); EventDispatcher.dispatch(getMapObj(), this); //Changelog (new MewlandEvent(new MewlandTextbox(1))).run(this); //Register key listener KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); manager.addKeyEventDispatcher(new MewlandKeyDispatcher(this)); } /** * Forces repaint of the map. */ public void forceRepaint() { this.getMap().repaint(); } /** * Initialize the frame itself. */ private void initializeFrame() { setFrame(new JFrame()); getFrame().setBounds(0, 0, 512, 541); getFrame().setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); getFrame().setResizable(false); getFrame().setTitle("Mewland " + version); getFrame().getContentPane().setLayout(null); } /** * Initialize the panel to show all components. */ private void initializePanel() { setPanel(new JPanel()); getPanel().setBounds(0, 0, 512, 512); getPanel().setLayout(null); } public void showTeam() { getMenu().removeAll(); getMenu().repaint(); setMenuB(new JButton[7]); getMenuB()[0] = new JButton("Zurück zum Menü..."); getMenuB()[0].setBounds(0, 0, 512, 20); BackToMenuButtonClickListener btmbcaction = new BackToMenuButtonClickListener(); btmbcaction.setMain(this); getMenuB()[0].addActionListener(btmbcaction); getMenuB()[1] = new JButton("#1"); getMenuB()[1].setBounds(0, 25, 512, 30); //BackToMenuButtonClickListener btmbcaction = new BackToMenuButtonClickListener(); btmbcaction.setMain(this); getMenuB()[0].addActionListener(btmbcaction); getMenu().add(getMenuB()[0]); } public void showMenu() { getMenu().removeAll(); getMenu().repaint(); setMenuB(new JButton[2]); getMenuB()[0] = new JButton("Dein Team"); getMenuB()[0].setBounds(0, 0, 512, 256); TeamButtonClickListener tbcaction = new TeamButtonClickListener(); tbcaction.setMain(this); getMenuB()[0].addActionListener(tbcaction); getMenuB()[1] = new JButton("Spiel beenden"); getMenuB()[1].setBounds(0, 256, 512, 256); CloseActionListener caction = new CloseActionListener(); caction.setMain(this); getMenuB()[1].addActionListener(caction); getMenu().add(getMenuB()[0]); getMenu().add(getMenuB()[1]); } public void toggleMenu() { if (getMenu().isVisible()) { getPanel().setVisible(true); getMenu().setVisible(false); getFrame().setContentPane(getPanel()); getFrame().setBounds(getFrame().getBounds().x, getFrame().getBounds().y, getWinsize()[0], getWinsize()[1]); } else { getWinsize()[0] = getFrame().getBounds().width; getWinsize()[1] = getFrame().getBounds().height; getMenu().setVisible(true); getPanel().setVisible(false); getFrame().setContentPane(getMenu()); getFrame().setBounds(getFrame().getBounds().x, getFrame().getBounds().y, 512, 541); } getFrame().repaint(); } /** * Inititalize the menu screeen */ public void initializeMenu() { setMenu(new JPanel()); getMenu().setBounds(0, 0, 512, 512); getMenu().setVisible(false); getMenu().setLayout(null); setMenuB(new JButton[2]); getMenuB()[0] = new JButton("Dein Team"); getMenuB()[0].setBounds(0, 0, 512, 256); TeamButtonClickListener tbcaction = new TeamButtonClickListener(); tbcaction.setMain(this); getMenuB()[0].addActionListener(tbcaction); getMenuB()[1] = new JButton("Spiel beenden"); getMenuB()[1].setBounds(0, 256, 512, 256); CloseActionListener caction = new CloseActionListener(); caction.setMain(this); getMenuB()[1].addActionListener(caction); getMenu().add(getMenuB()[0]); getMenu().add(getMenuB()[1]); } /** * Fill the frame with the panel. */ private void fillFrame() { getFrame().getContentPane().add(getPanel()); } /** * Get an image resource. * @param img The image to get. * @return The URL to get. */ public URL getImageResource(String img) { return getClass().getResource("/de/mewking/mewland/resources/img" + img); } /** * Get a data resource. * @param data The datafile to get. * @return The URL of the datafile. */ public URL getDataResource(String data) { return getClass().getResource("/de/mewking/mewland/resources/data" + data); } /** * Add component to panel. * @param c The component to add. */ public void addToContentPanel(Component c) { getPanel().add©; } /** * Remove component from panel. * @param c The component to remove. */ public void removeFromContentPanel(Component c) { getPanel().remove©; } /** * Get the player instance. * @return The player instance. */ public Player getPlayer() { return player; } /** * Set the player instance. * @param player The player instance. */ public void setPlayer(Player player) { this.player = player; } /** * Get the renderer instance of the map. * @return The renderer instance. */ public ImagePanel getMap() { return map_r; } /** * Set the renderer instance of the map. * @param map_r The renderer instance. */ public void setMap(ImagePanel map_r) { this.map_r = map_r; } /** * Get the map object. * @return The map object. */ public Map getMapObj() { return map; } /** * Set the map object. * @param map The map object. */ public void setMapObj(Map map) { this.map = map; } /** * Get the panel. * @return The panel. */ public JPanel getPanel() { return panel; } /** * Set the panel. * @param panel The panel. */ public void setPanel(JPanel panel) { this.panel = panel; } /** * Get the frame. * @return The frame. */ public JFrame getFrame() { return frame; } /** * Set the frame. * @param frame The frame. */ public void setFrame(JFrame frame) { this.frame = frame; } public JPanel getMenu() { return menu; } public void setMenu(JPanel menu) { this.menu = menu; } public JButton[] getMenuB() { return menu_b; } public void setMenuB(JButton[] menu_b) { this.menu_b = menu_b; } public int[] getWinsize() { return winsize; } public void setWinsize(int[] winsize) { this.winsize = winsize; } public boolean canLeave() { return canLeave; } public void setCanLeave(boolean canLeave) { this.canLeave = canLeave; } public SaveGame getSave() { return save; } public void setSave(SaveGame save) { this.save = save; } }
Cool :3 Dass es ihn da auch gibt. Aber naja, da ich ihn sowieso immer selbts mache ist es mir ja eigentlich egal.
|
|
Benutzer, die gerade dieses Thema anschauen: 108 Gast/Gäste