Results 1 to 2 of 2
  1. #1
    lifedistroy is offline Member
    Join Date
    Mar 2012
    Posts
    4
    Rep Power
    0

    Default Need help with calling classes!

    Hey! im kind of new to java (ive been trying to code with it for about 2-3 months now.)

    Im trying to replicate a game called bomberman and I've made 3 separate classes for now.

    twoplayergamebomb
    RedBomb
    BlueBomb

    self-explanatory about what they do.

    First off i need to know if RedBomb.class can draw on twoplayergamebomb in an applet.

    Here is my code: (its quite long...)

    twoplayergamebomb(fullcode)
    [Java] twoplayergamebomb - Pastebin.com

    Specific Code where im calling RedBomb.class methods:

    public void paint(Graphics g){
    if(background==0){
    background++;
    background(g);
    }
    players(g);
    BombPlace(g);
    RedBomb r= new RedBomb();
    r.init();
    r.input(P1x, P1y, darkRed, lightRed);
    r.repaint();
    }


    RedBomb Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class RedBomb extends JApplet implements ActionListener {


    int freq=100;
    int Posx;
    int Posy;
    Color darkBomb;
    Color lightBomb;
    Timer T=new Timer(freq, this);


    public void init(){
    T.start();
    }

    public void input(int x, int y,Color darkInput,Color lightInput){
    Posx=x;
    Posy=y;
    darkBomb=darkInput;
    lightBomb=lightInput;
    repaint();
    System.out.println("test");
    }


    public void paint(Graphics g){
    g.setColor(darkBomb);
    g.fillRect(Posx+5, Posy+5, 27, 27);


    g.setColor(lightBomb);
    g.fillRect(Posx+5, Posy+5, 27, 27);


    System.out.println(freq);


    if(freq<5){
    g.setColor(Color.white);
    g.fillRect(Posx, Posy, 32, 32);
    T.stop();
    }else if(freq>5){
    freq--;
    }
    }
    @Override
    public void actionPerformed(ActionEvent arg0) {
    repaint();
    }
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Need help with calling classes!

    Please use [code] tags [/code] when posting code.
    Someone else will correct me if I'm wrong, but I'm pretty sure you shouldn't override paint().
    You should override paintComponent().

    That's the first thing I can see.

    The second is, I don't think you can initialise an applet like that.
    A JApplet is usually the top level (ie entry point) for your application, so that creation and call looks wrong.
    It's the JApplet that should contain the other things you are drawing, probably in the form of a JPanel.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. calling methods in other classes
    By elite 98 in forum New To Java
    Replies: 5
    Last Post: 07-09-2011, 04:33 AM
  2. Calling classes from another class
    By jay_mascis in forum New To Java
    Replies: 1
    Last Post: 04-20-2011, 12:41 AM
  3. using and calling class within classes..
    By Bgreen7887 in forum New To Java
    Replies: 5
    Last Post: 10-27-2010, 04:49 PM
  4. Calling Methods between classes?
    By questionanswer in forum New To Java
    Replies: 2
    Last Post: 03-22-2010, 02:22 AM
  5. Calling jar classes from java executable
    By SteM in forum Advanced Java
    Replies: 1
    Last Post: 11-27-2007, 09:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •