about awt.I have problem to print out numbers next to ....

Hi to everyone,

I am new in java programming and new in this forum.So sorry if i do something wrong.

About awt.I have problem to print out numbers next to a box.It is about a thermometer and i would like to put next to this a column of numbers.for example spmethinf like:

100

80

60

40

20

I know it is only a for loop but i can't do it because i am confused with the methods.I use drawString("",int x ,int y). BY the way how can i convert integer to string?

thanks

[525 byte] By [javoxygena] at [2007-10-3 10:18:35]
# 1
how does ur code look?
SvHa at 2007-7-15 5:39:40 > top of Java-index,Java Essentials,Java Programming...
# 2

import java.awt.*;

class TempWindow extends Frame

{

String temperature;

//constructor method

public TempWindow(String temp)

{

temperature=temp;

//reading a single number as a command line argument

//I would like to give this line argument from the main

double arg= Double.valueOf(temp).doubleValue();

/*************************************************

*in the above lines set the title of the window,

*the size of the window and the background color

*of the window.

**************/

setTitle("Temp:"+ arg + "\u00B0C");

setSize(200,600);

setBackground(Color.white);

}//end of constructor

//paint method

public void paint(Graphics g)

{

//reading a single number as a command line argument

double arg= Double.valueOf(temperature).doubleValue();

/*****************************************************

* in the above lines we set the size of the box of

* the thermometer,the symbol: 癈 in specific font,

* height,weight(20,60,65),the each time temperature

* in a specific font,height,weight(15,12,110).

************/

g.drawRect(100,60,12,480);

g.setFont(new Font("sansserif",Font.BOLD,20));

g.drawString("\u00B0C",60,65);

g.setFont(new Font("sansserif",Font.BOLD,14));

g.drawString(arg + "\u00B0C",12,110);

/*******************************************

*for loop for the list 100,80,60,...,0,-20

*next to box of the thermometer

*********/

//I can't do that

/*for(int i=60;i<=540;i=i-20)

{int k;

k=Integer.intValue(i-20);

g.drawString(k,120,135);

}*/

//convertion String to integer

//There is better way to do that?

int t=(int) arg;

//if commands for above 100癈 and below -20癈 condition

//i would like to put this if statements in switch

if(t>100)

{

g.setColor(Color.red);

g.setFont(new Font("sansserif", Font.BOLD, 11));

g.drawString("Too Hot!",12,130);

}

else if(t<-20)

{

g.setColor(Color.blue);

g.setFont(new Font("sansserif", Font.BOLD, 11));

g.drawString("Too Cold!",12,130);

}

//output for any other temperature

else

{

//is not working as i want

int z=t*420/100+60; // the height of the red fill

int x=540-z; // the point that starts the red fill

g.setColor(Color.red);//the color

g.fillRect(101,x,11,z); //the output

}

//draw scale lines

for(int i=60;i<=540;i=i+8)

{

g.setColor(Color.black);

g.drawLine(98,i,114,i);

}

for(int i=60;i<=540;i=i+80)

{

g.setColor(Color.black);

g.drawLine(96,i,116,i);//draw two lines(to make it thick)

g.drawLine(96,i+1,116,i+1);

}

}

}

public class cw2

{ public static void main(String args[])

{

// double arg= Double.valueOf(temp).doubleValue(args [0]);

String str= args[0] ;

TempWindow myTemp = new TempWindow(str);

myTemp.show();

}

}

this is my code.is not working well.if you my comments you can understnd!

javoxygena at 2007-7-15 5:39:40 > top of Java-index,Java Essentials,Java Programming...