public MainPanel() { super(new BorderLayout()); BufferedImage bi = null; try { bi = ImageIO.read(getClass().getResource("test.jpg")); } catch (IOException ioe) { ioe.printStackTrace(); } bufferedImage = bi; List<AbstractAction> list = Arrays.asList( new AbstractAction("NONE") { @Override public void actionPerformed(ActionEvent e) { mode = Flip.NONE; repaint(); } }, new AbstractAction("VERTICAL") { @Override public void actionPerformed(ActionEvent e) { mode = Flip.VERTICAL; repaint(); } }, new AbstractAction("HORIZONTAL") { @Override public void actionPerformed(ActionEvent e) { mode = Flip.HORIZONTAL; repaint(); } }); Box box = Box.createHorizontalBox(); box.add(Box.createHorizontalGlue()); box.add(new JLabel("Flip: ")); for (AbstractAction a : list) { JRadioButton rb = new JRadioButton(a); if (bg.getButtonCount() == 0) { rb.setSelected(true); } box.add(rb); bg.add(rb); box.add(Box.createHorizontalStrut(5)); } add(p); add(box, BorderLayout.SOUTH); setOpaque(false); setPreferredSize(new Dimension(320, 240)); }
public void checkPupCollision() { // pretty much the same thing as before, however it alsoe does the powerup effects for (Powerup p : pupList) { if (p.getOnScreen()) { // can be removed later on if (p.checkCollision(player1)) { pupRemove.add(p); player1.setPower(p.getType()); player1.setVelo(50); } } else { pupRemove.add(p); } } if (player1.getPower().equals("Lucky")) { // changes everything to stars for (Coin c : coinList) { starList.add(new Star(c.getX(), c.getY(), 2)); cRemove.add(c); } for (Box b : boxList) { starList.add(new Star(b.getX(), b.getY(), 2)); bRemove.add(b); } for (Enemy e : enemyList) { starList.add(new Star(e.getX(), e.getY(), 2)); eRemove.add(e); } } else if (player1.getPower().equals("Magnet")) { // moves the coins towards the player for (Coin c : coinList) { c.moveTowards(player1); } } else { // else do nothing } for (Powerup p : pupRemove) { poofList.add(new Poof(p.getX(), p.getY(), 2)); pupList.remove(p); } pupRemove = new ArrayList<Powerup>(); }
public void checkBoxCollision() { // pretty much the same thing as all the other collisions for (Box b : boxList) { if (b.getOnScreen()) { // checks if its on the screen if (b.checkCollision(b.getImage(), player1)) { player1.setVelo(50); player1.setDown(false); b.setPcount( b.getPcount() - 1); // sets the type to one less so then you can bounce on it twice if (b.getPcount() == 0) { bRemove.add(b); // removes the box } if (musicOn) { bounce.play(); } } } else { bRemove.add(b); } } for (Box b : bRemove) { boxList.remove(b); } bRemove = new ArrayList<Box>(); }
/** * Set up a menu and tool bar * * @param pane panel to add toolbar to * @param ftree file tree display */ private JMenuBar makeMenuBar(JPanel pane, final FileTree ftree) { JMenuBar mBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); mBar.add(fileMenu); JMenuItem fileMenuGoto = new JMenuItem("Go to Directory ..."); fileMenuGoto.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { String dir = ftree.getRoot().getAbsolutePath(); String newDir = JOptionPane.showInputDialog(FileManager.this, "Go to Directory:", dir); if (newDir == null) return; newDir = newDir.trim(); File newDirFile = new File(newDir); if (newDirFile.exists() && newDirFile.canRead() && !newDir.equals(dir)) ftree.newRoot(newDir); else { String error = null; if (!newDirFile.exists()) error = new String(newDir + " doesn't exist!"); else if (!newDirFile.canRead()) error = new String(newDir + " cannot be read!"); else if (newDir.equals(dir)) error = new String("Same directory!"); if (error != null) JOptionPane.showMessageDialog( FileManager.this, error, "Warning", JOptionPane.WARNING_MESSAGE); } } }); fileMenu.add(fileMenuGoto); fileMenu.add(new JSeparator()); JMenuItem fileMenuClose = new JMenuItem("Close"); fileMenuClose.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { setVisible(false); } }); fileMenu.add(fileMenuClose); // tool bar set up JToolBar toolBar = new JToolBar(); Dimension buttonSize = new Dimension(22, 24); JButton upBt = new JButton() { public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setColor(new Color(0, 128, 0)); float loc1[][] = {{11, 18}, {7, 18}, {7, 14}, {3, 14}, {11, 4}}; g2.fill(makeShape(loc1)); g2.setColor(Color.green); float loc2[][] = {{11, 18}, {15, 18}, {15, 14}, {19, 14}, {11, 4}}; g2.fill(makeShape(loc2)); setSize(22, 24); } }; upBt.setPreferredSize(buttonSize); upBt.setMinimumSize(buttonSize); upBt.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { FileManager.this.setCursor(cbusy); File root = ftree.getRoot(); String parent = root.getParent(); if (parent != null) ftree.newRoot(parent); FileManager.this.setCursor(cdone); } }); toolBar.add(upBt); // yeastpub JButton shortCut1 = new JButton() { public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; Font font = new Font("Monospaced", Font.BOLD, 14); g2.setFont(font); g2.setColor(Color.black); g2.drawString("Y", 4, 18); g2.setColor(Color.red); g2.drawString("P", 10, 15); setSize(22, 24); } }; shortCut1.setPreferredSize(buttonSize); shortCut1.setMinimumSize(buttonSize); shortCut1.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { ftree.newRoot("/nfs/disk222/yeastpub"); } }); if ((new File("/nfs/disk222/yeastpub")).exists()) toolBar.add(shortCut1); // pathdata JButton shortCut2 = new JButton() { public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; Font font = new Font("Monospaced", Font.BOLD, 14); g2.setFont(font); g2.setColor(Color.black); g2.drawString("P", 4, 18); g2.setColor(Color.red); g2.drawString("D", 10, 15); setSize(22, 24); } }; shortCut2.setPreferredSize(buttonSize); shortCut2.setMinimumSize(buttonSize); shortCut2.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { ftree.newRoot("/nfs/pathdata/"); } }); if ((new File("/nfs/pathdata/")).exists()) toolBar.add(shortCut2); // home button JButton homeBt = new JButton() { public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setColor(Color.blue); float loc1[][] = {{3, 14}, {11, 3}, {19, 14}, {17, 14}, {17, 18}, {5, 18}, {5, 14}}; g2.fill(makeShape(loc1)); setSize(22, 24); } }; homeBt.setPreferredSize(buttonSize); homeBt.setMinimumSize(buttonSize); homeBt.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { ftree.newRoot(System.getProperty("user.home")); } }); toolBar.add(homeBt); toolBar.add(Box.createVerticalStrut(35)); pane.add(toolBar, BorderLayout.NORTH); return mBar; }
public void scrollBoxes() { for (Box i : boxList) { i.setY(i.getY() + (int) (player1.getVelocity() * 0.3)); } }
public void drawBox(Graphics g) { for (Box i : boxList) { g.drawImage(i.getImage(), i.getX(), i.getY(), i.getWidth(), i.getHeight(), null); } }