Results 1 to 3 of 3
- 12-28-2011, 07:11 AM #1
Member
- Join Date
- Dec 2007
- Posts
- 21
- Rep Power
- 0
[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
Here are the classes I typed to be used in gameJava 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); } }
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 12:45 AM. Reason: SOLVED
- 12-28-2011, 08:23 AM #2
Member
- Join Date
- Dec 2007
- Posts
- 21
- Rep Power
- 0
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);
- 12-28-2011, 09:15 AM #3
Senior Member
- Join Date
- Apr 2010
- Location
- Dhaka,Bangladesh
- Posts
- 178
- Rep Power
- 0
Similar Threads
-
Applet not working correctly?
By Beavotropper2 in forum Java AppletsReplies: 2Last Post: 04-18-2011, 06:32 AM -
drawString() method not working correctly
By tnixon22 in forum New To JavaReplies: 2Last Post: 02-25-2011, 08:57 PM -
Error Checking not working correctly
By RickAintree in forum New To JavaReplies: 1Last Post: 12-15-2010, 01:54 PM -
Gueesing Game Almost done, but not working correctly
By mbnumba6 in forum New To JavaReplies: 5Last Post: 03-18-2009, 03:01 AM -
[SOLVED] \t not working correctly?
By Gakusei in forum New To JavaReplies: 5Last Post: 05-06-2008, 04:45 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks