Help with Javascript - Boxes and Text


Hello! I'm creating a project game on a different platform(JS), but I'd like some information from other websites. How would one be able to post text in a rectangle and keep that text in a rectangle?
For example:
function start(x, y, x1, y1, t){
var rect = new Rectangle(x, y);
rect.setPosition(x1, y1);
var text = new Text(t, "10pt Arial");
txt.setPosition(x1, y1);
In this case, the text would move out of the rectangle. Is there any possible way to ensure that the text will stay in the box? Some sort of getY sorcery? The text, of course, would be allowed to move vertically until it reaches the border of the box and would move beyond, but would NOT traverse across it's horizontal borders.

*Sorry about my previous introduction, wasn't sure how chatting would work here.


We are given a scant lot to go on. Where are the definitions of these classes?


And what of the DOM insertion? Where is that?


First please specify the language for your code above.
My first guess would be Java since there is a static Color class and Rectangle class.
Secondly that add() can be used in a class that extends Jframe or Canvas, not so sure.

The thing that questions my guess would be the method declaration which starts with "function" which doesn't exist in Java.

If you want to make a game in javascript, you don't have to change much on your script.
First notice that you will have to make a <canvas id="c" width="500" height="500"></canvas> in your html file. Than you can add the following in your javascript to get it:

var c = document.getElementById("c").getContext("2d");

After that you can directly start drawing things. Here is how: