Results 1 to 3 of 3
  1. #1
    quickfingers is offline Member
    Join Date
    Dec 2007
    Posts
    21
    Rep Power
    0

    Default [SOLVED] Trying to use the Paint but program isn't working correctly

    Okay I'm going to attempt to explain what I am trying to do here. I am trying to right a class that uses Runnable for my timer but using paint as my output to the screen instead of using this line System.out.println(bank.amount()); . When I run the program nothing happens at all. I know I have a lot of stuff commented out that was already tested and works perfectly fine.


    Here is the main class call game

    Java Code:
    import java.lang.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    
    
    public class game extends JFrame implements Runnable
    {
    //Bank bank = new Bank();
    Time time = new Time();
    Thread main = new Thread(this);
    Graphics g;
    Image buffer;
    int ct=0;
    public static void main (String args[])
        {
            new game();  
        }
        
    public game()
    {
        addNotify();
        Graphics bufferG;
        g = this.getGraphics();
        this.setLayout(null);
        this.setSize(1024,800);
        setTitle("Death");
        
    
       
       main.start();
      //  time
       // buffer=createImage(this.getWidth(),this.getHeight());
       // bufferG=buffer.getGraphics();
        
       
        int wallet=500;
       // System.out.println("Hello World");
       // bank.deposit(200);
        wallet-=200;
       // bank.withdraw(150);
        //System.out.println(bank.amount());
       
       // System.exit(6);
       paint();
       
    }
    public void run()
    {
        //while(true)
       // {
           while(true)
           {
            //time.run();
           // ct++;
            paint();
        //System.out.println(time.toString()+"   "+ct);
         try
            {
                main.sleep(1000);
            }
            catch(Exception e){}
        }
    }
    
    public void paint()
    {
        g.setColor(Color.black);
        g.drawRect(0,0,5000,5000);
        g.setColor(Color.red);
        g.drawString("Random Text 35251regweerasghtgaf gseta gh sts ", 200,200);
    }
    public void update(Graphics g)
        {  
            paint(g);
        }
    }
    Here are the classes I typed to be used in game

    time class
    Java Code:
    public class Time extends Thread
    {
        private int hr, min, sec;
        private boolean isAM;
        
        public Time()
        {
            hr=0;
            min=0;
            sec=0;
            isAM=true;
        }
        
        public int getHR()
        {
            return hr;
        }
        public int getMin()
        {
            return min;
        }
        public int getSec()
        {
            return sec;
        }
        public boolean getAM()
        {
            return isAM;
        }
        public void setHr (int inHr)
        {
            if(inHr>=1&&inHr<=12)
                hr=inHr;
        }
        public void setMin(int inMin)
        {
            if(inMin>=0&&inMin<60)
                min=inMin;
        }
        public void setSec(int inSec)
        {
            if(inSec>=0&&inSec<60)
                sec=inSec;
        }
        public void setAM(boolean inAM)
        {
            isAM=inAM;
        }
        public void addSec()
        {
            sec++;
            if(sec==60)
            {
                addMin();
                sec=0;
            }
        }
        public void addMin()
        {
            min++;
            if(min==60)
            {
                addHr();
                min=0;
            }
        }
        public void addHr()
        {
            hr++;
            if(hr==13)
                hr=0;
            if(hr==12)
                isAM=!isAM;
        }
        public String toString()
        {
            String temp=hr+" : ";
            if(min<10)
                temp+="0";
            temp+=min+" : ";
            if(sec<10)
                temp+="0";
            temp+=sec+" ";
            if(isAM)
                temp+="AM";
            else
                temp+="PM";
            return temp;
        }
        public void run()
        {
            addSec();
            try
            {
                this.sleep(1000);
            }
            catch(Exception e) {}
        }
    }

    And here is the Bank Class (which I know is commented out at the moment)

    Java Code:
    public class Bank
    {
        private int money;
        private boolean isPossible;
        
        public Bank()
        {
            money=0;
            isPossible=true;
        }
        
        public void deposit(int amount)
        {
            money+=amount;
        }
        public int withdraw(int amount)
        {
            if(money>amount)
            {
                money-=amount;
                return amount;
            }
            else
            {
                isPossible=false;
                return 0;
            }
        }
        public int amount()
        {
            return money;
        }
    }
    Last edited by quickfingers; 12-29-2011 at 01:45 AM. Reason: SOLVED

  2. #2
    quickfingers is offline Member
    Join Date
    Dec 2007
    Posts
    21
    Rep Power
    0

    Default Re: Trying to use the Paint but program isn't working correctly

    sorry about the double post but my friend figure it out for me I simple forgot a line

    this.setVisible(true);

  3. #3
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default Re: Trying to use the Paint but program isn't working correctly

    Quote Originally Posted by quickfingers View Post
    sorry about the double post but my friend figure it out for me I simple forgot a line

    this.setVisible(true);
    Is it solved? Then please mark this post as SOLVED.
    Don't Forget to try yourself before asking others help.....
    Press REP, if you find their advices/solutions effective.

Similar Threads

  1. Applet not working correctly?
    By Beavotropper2 in forum Java Applets
    Replies: 2
    Last Post: 04-18-2011, 07:32 AM
  2. drawString() method not working correctly
    By tnixon22 in forum New To Java
    Replies: 2
    Last Post: 02-25-2011, 09:57 PM
  3. Error Checking not working correctly
    By RickAintree in forum New To Java
    Replies: 1
    Last Post: 12-15-2010, 02:54 PM
  4. Gueesing Game Almost done, but not working correctly
    By mbnumba6 in forum New To Java
    Replies: 5
    Last Post: 03-18-2009, 04:01 AM
  5. [SOLVED] \t not working correctly?
    By Gakusei in forum New To Java
    Replies: 5
    Last Post: 05-06-2008, 05:45 PM

Posting Permissions

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