Easy way to convert javascript to a java applet?

Hello all! I am relatively new to java and java programming and had a question about converting a JavaScript to a java applet or even a standalone application. I included the JavaScript code for a checkers game below and wanted to know what would be the easiest way to convert this code if at all possible?
Thanks in advance,
Bob
<SCRIPT language=JavaScript>
<!--
version = 1.0;
// -->
</SCRIPT>
<SCRIPT language=JavaScript1.1>
<!--
version = 1.1;
// -->
</SCRIPT>
<SCRIPT language=JavaScript>
<!--
if (version==1.0)
document.write("Your browser doesn't have JavaScript 1.1 capabilities. "
+ "This checkers game script only works on Netscape 3+ and MSIE 4+.");
// -->
</SCRIPT>
<SCRIPT language=JavaScript1.1>
<!--
// Checkers Game
// black.gif
// gray.gif
// you1.gif -- normal piece (player/red)
// you2.gif -- highlighted piece
// you1k.gif -- kinged normal piece
// you2k.gif -- kinged highlighted piece
// me1.gif -- normal piece (computer/black)
// me2.gif -- highlighted piece
// me1k.gif -- kinged normal piece
// me2k.gif -- kinged highlighted piece
function preload() {
this.length = preload.arguments.length;
for (var i = 0; i < this.length; i++) {
this[i] = new Image();
this.src = preload.arguments[i];
var pics = new preload("black.gif","gray.gif",
"you1.gif","you2.gif","you1k.gif","you2k.gif",
"me1.gif","me2.gif","me1k.gif","me2k.gif");
var black = -1; // computer is black
var red = 1; // visitor is red
var square_dim = 35;
var piece_toggled = false;
var my_turn = false;
var double_jump = false;
var comp_move = false;
var game_is_over = false;
var safe_from = safe_to = null;
var toggler = null;
var togglers = 0;
function Board() {
board = new Array();
for (var i=0;i<8; i++) {
board[i] = new Array();
for (var j=0;j<8;j++)
board[i][j] = Board.arguments[8*j+i];
board[-2] = new Array(); // prevents errors
board[-1] = new Array(); // prevents errors
board[8] = new Array(); // prevents errors
board[9] = new Array(); // prevents errors
var board;
Board(1,0,1,0,1,0,1,0,
0,1,0,1,0,1,0,1,
1,0,1,0,1,0,1,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,-1,0,-1,0,-1,0,-1,
-1,0,-1,0,-1,0,-1,0,
0,-1,0,-1,0,-1,0,-1);
function message(str) {
if (!game_is_over)
document.disp.message.value = str;
function moveable_space(i,j) {
// calculates whether it is a gray (moveable)
// or black (non-moveable) space
return (((i%2)+j)%2 == 0);
function Coord(x,y) {
this.x = x;
this.y = y;
function coord(x,y) {
c = new Coord(x,y);
return c;
document.write("<table border=0 cellspacing=0 cellpadding=0 width="+(square_dim*8+8)
+"<tr><td><img src='black.gif' width="+(square_dim*8+8)
+" height=4><br></td></tr>");
for(var j=0;j<8;j++) {
document.write("<tr><td><img src='black.gif' width=4 height="+square_dim+">");
for(var i=0;i<8;i++) {
if (moveable_space(i,j))
document.write("<a href='javascript:clicked("+i+","+j+")'>");
document.write("<img src='");
if (board[i][j]==1) document.write("you1.gif");
else if (board[i][j]==-1) document.write("me1.gif");
else if (moveable_space(i,j)) document.write("gray.gif");
else document.write("black.gif");
document.write("' width="+square_dim+" height="+square_dim
+" name='space"+i+""+j+"' border=0>");
if (moveable_space(i,j)) document.write("</a>");
document.write("<img src='black.gif' width=4 height="+square_dim+"></td></tr>");
document.write("<tr><td><img src='black.gif' width="+(square_dim*8+8)
+" height=4><br></td></tr></table><br>"
+"<form name='disp'><textarea name='message' wrap=virtual rows=2 cols=40></textarea><br><input "
+"type=button value=\"Start the Game Over\" onClick=\"location.href+=''\"></form>");
function clicked(i,j) {
if (my_turn) {
if (integ(board[i][j])==1) toggle(i,j);
else if (piece_toggled) move(selected,coord(i,j));
else message("First click one of your red pieces, then click where you want to move it");
} else {
message("It's not your turn yet. Hang on a sec!");
function toggle(x,y) {
if (my_turn) {
if (piece_toggled)
draw(selected.x,selected.y,"you1"+((board[selected.x][selected.y]==1.1)?"k":"")+".gif");
if (piece_toggled && (selected.x == x) && (selected.y == y)) {
piece_toggled = false;
if (double_jump) { my_turn = double_jump = false; computer(); }
} else {
piece_toggled = true;
draw(x,y,"you2"+((board[x][y]==1.1)?"k":"")+".gif");
selected = coord(x,y);
} else {
if ((piece_toggled) && (integ(board[selected_c.x][selected_c.y])==-1))
draw(selected_c.x,selected_c.y,"me1"+((board[selected_c.x][selected_c.y]==-1.1)?"k":"")+".gif");
if (piece_toggled && (selected_c.x == x) && (selected_c.y == y)) {
piece_toggled = false;
} else {
piece_toggled = true;
draw(x,y,"me2"+((board[x][y]==-1.1)?"k":"")+".gif");
selected_c = coord(x,y);
function draw(x,y,name) {
document.images["space"+x+""+y].src = name;
function integ(num) {
if (num != null)
return Math.round(num);
else
return null;
function abs(num) {
return Math.abs(num);
function sign(num) {
if (num < 0) return -1;
else return 1;
function concatenate(arr1,arr2) {
// function tacks the second array onto the end of the first and returns result
for(var i=0;i<arr2.length;i++)
arr1[arr1.length+i] = arr2[i];
return arr1;
function legal_move(from,to) {
if ((to.x < 0) || (to.y < 0) || (to.x > 7) || (to.y > 7)) return false;
piece = board[from.x][from.y];
distance = coord(to.x-from.x,to.y-from.y);
if ((distance.x == 0) || (distance.y == 0)) {
message("You may only move diagonally.");
return false;
if (abs(distance.x) != abs(distance.y)) {
message("Invalid move.");
return false;
if (abs(distance.x) > 2) {
message("Invalid move.");
return false;
if ((abs(distance.x) == 1) && double_jump) {
return false;
if ((board[to.x][to.y] != 0) || (piece == 0)) {
return false;
if ((abs(distance.x) == 2)
&& (integ(piece) != -integ(board[from.x+sign(distance.x)][from.y+sign(distance.y)]))) {
return false;
if ((integ(piece) == piece) && (sign(piece) != sign(distance.y))) {
return false;
return true;
function move(from,to) {
my_turn = true;
if (legal_move(from,to)) {
piece = board[from.x][from.y];
distance = coord(to.x-from.x,to.y-from.y);
if ((abs(distance.x) == 1) && (board[to.x][to.y] == 0)) {
swap(from,to);
} else if ((abs(distance.x) == 2)
&& (integ(piece) != integ(board[from.x+sign(distance.x)][from.y+sign(distance.y)]))) {
double_jump = false;
swap(from,to);
remove(from.x+sign(distance.x),from.y+sign(distance.y));
if ((legal_move(to,coord(to.x+2,to.y+2)))
|| (legal_move(to,coord(to.x+2,to.y-2)))
|| (legal_move(to,coord(to.x-2,to.y-2)))
|| (legal_move(to,coord(to.x-2,to.y+2)))) {
double_jump = true;
message("You may complete the double jump or click on your piece to stay still.");
if ((board[to.x][to.y] == 1) && (to.y == 7)) king_me(to.x,to.y);
selected = to;
if (game_over() && !double_jump) {
setTimeout("toggle("+to.x+","+to.y+");my_turn = double_jump = false;computer();",1000);
return true;
function king_me(x,y) {
if (board[x][y] == 1) {
board[x][y] = 1.1; // king you
draw(x,y,"you2k.gif");
} else if (board[x][y] == -1) {
board[x][y] = -1.1; // king me
draw(x,y,"me2k.gif");
function swap(from,to) {
if (my_turn || comp_move) {
dummy_src = document.images["space"+to.x+""+to.y].src;
document.images["space"+to.x+""+to.y].src = document.images["space"+from.x+""+from.y].src;
document.images["space"+from.x+""+from.y].src = dummy_src;
dummy_num = board[from.x][from.y];
board[from.x][from.y] = board[to.x][to.y];
board[to.x][to.y] = dummy_num;
function remove(x,y) {
if (my_turn || comp_move)
draw(x,y,"gray.gif");
board[x][y] = 0;
function Result(val) {
this.high = val;
this.dir = new Array();
function move_comp(from,to) {
toggle(from.x,from.y);
comp_move = true;
swap(from,to);
if (abs(from.x-to.x) == 2) {
remove(from.x+sign(to.x-from.x),from.y+sign(to.y-from.y));
if ((board[to.x][to.y] == -1) && (to.y == 0)) king_me(to.x,to.y);
setTimeout("selected_c = coord("+to.x+","+to.y+");piece_toggled = true;",900);
setTimeout("bak=my_turn;my_turn=false;toggle("+to.x+","+to.y+");my_turn=bak;",1000);
if (game_over()) {
setTimeout("comp_move = false;my_turn = true;togglers=0;",600);
message("Ok. It's your turn. You may make your move.");
return true;
function game_over() { // make sure game is not over (return false if game is over)
comp = you = false;
for(var i=0;i<8;i++) {
for(var j=0;j<8;j++) {
if(integ(board[i][j]) == -1) comp = true;
if(integ(board[i][j]) == 1) you = true;
if (!comp) message("You beat me!");
if (!you) message("Gotcha! Game over.");
game_is_over = (!comp || !you)
return (!game_is_over);
// the higher the jump_priority, the more often the computer will take the jump over the safe move
var jump_priority = 10;
function computer() {
// step one - prevent any jumps
for(var j=0;j<8;j++) {
for(var i=0;i<8;i++) {
if (integ(board[i][j]) == 1) {
if ((legal_move(coord(i,j),coord(i+2,j+2))) && (prevent(coord(i+2,j+2),coord(i+1,j+1)))) {
return true;
} if ((legal_move(coord(i,j),coord(i-2,j+2))) && (prevent(coord(i-2,j+2),coord(i-1,j+1)))) {
return true;
} if (board[i][j] == 1.1) {
if ((legal_move(coord(i,j),coord(i-2,j-2))) && (prevent(coord(i-2,j-2),coord(i-1,j-1)))) {
return true;
} if ((legal_move(coord(i,j),coord(i+2,j-2))) && (prevent(coord(i+2,j-2),coord(i+1,j-1)))) {
return true;
// step two - if step one not taken, look for jumps
for(var j=7;j>=0;j--) {
for(var i=0;i<8;i++) {
if (jump(i,j))
return true;
safe_from = null;
// step three - if step two not taken, look for safe single space moves
for(var j=0;j<8;j++) {
for(var i=0;i<8;i++) {
if (single(i,j))
return true;
// if no safe moves, just take whatever you can get
if (safe_from != null) {
move_comp(safe_from,safe_to);
} else {
message("You beat me!!");
game_is_over = true;
safe_from = safe_to = null;
return false;
function jump(i,j) {
if (board[i][j] == -1.1) { 
if (legal_move(coord(i,j),coord(i+2,j+2))) {
move_comp(coord(i,j),coord(i+2,j+2));
setTimeout("jump("+(i+2)+","+(j+2)+");",500);
return true;
} if (legal_move(coord(i,j),coord(i-2,j+2))) {
move_comp(coord(i,j),coord(i-2,j+2));
setTimeout("jump("+(i-2)+","+(j+2)+");",500);
return true;
} if (integ(board[i][j]) == -1) {
if (legal_move(coord(i,j),coord(i-2,j-2))) {
move_comp(coord(i,j),coord(i-2,j-2));
setTimeout("jump("+(i-2)+","+(j-2)+");",500);
return true;
} if (legal_move(coord(i,j),coord(i+2,j-2))) {
move_comp(coord(i,j),coord(i+2,j-2));
setTimeout("jump("+(i+2)+","+(j-2)+");",500);
return true;
return false;
function single(i,j) {
if (board[i][j] == -1.1) {
if (legal_move(coord(i,j),coord(i+1,j+1))) {
safe_from = coord(i,j);
safe_to = coord(i+1,j+1);
if (wise(coord(i,j),coord(i+1,j+1))) {
move_comp(coord(i,j),coord(i+1,j+1));
return true;
} if (legal_move(coord(i,j),coord(i-1,j+1))) {
safe_from = coord(i,j);
safe_to = coord(i-1,j+1);
if (wise(coord(i,j),coord(i-1,j+1))) {
move_comp(coord(i,j),coord(i-1,j+1));
return true;
} if (integ(board[i][j]) == -1) {
if (legal_move(coord(i,j),coord(i+1,j-1))) {
safe_from = coord(i,j);
safe_to = coord(i+1,j-1);
if (wise(coord(i,j),coord(i+1,j-1))) {
move_comp(coord(i,j),coord(i+1,j-1));
return true;
} if (legal_move(coord(i,j),coord(i-1,j-1))) {
safe_from = coord(i,j);
safe_to = coord(i-1,j-1);
if (wise(coord(i,j),coord(i-1,j-1))) {
move_comp(coord(i,j),coord(i-1,j-1));
return true;
return false;
function possibilities(x,y) {
if (!jump(x,y))
if (!single(x,y))
return true;
else
return false;
else
return false;
function prevent(end,s) {
i = end.x;
j = end.y;
if (!possibilities(s.x,s.y))
return true;
else if ((integ(board[i-1][j+1])==-1) && (legal_move(coord(i-1,j+1),coord(i,j)))) {
return move_comp(coord(i-1,j+1),coord(i,j));
} else if ((integ(board[i+1][j+1])==-1) && (legal_move(coord(i+1,j+1),coord(i,j)))) {
return move_comp(coord(i+1,j+1),coord(i,j));
} else if ((board[i-1][j-1]==-1.1) && (legal_move(coord(i-1,j-1),coord(i,j)))) {
return move_comp(coord(i-1,j-1),coord(i,j));
} else if ((board[i+1][j-1]==-1.1) && (legal_move(coord(i+1,j-1),coord(i,j)))) {
return move_comp(coord(i+1,j-1),coord(i,j));
} else {
return false;
function wise(from,to) {
i = to.x;
j = to.y;
n = (j>0);
s = (j<7);
e = (i<7);
w = (i>0);
if (n&&e) ne = board[i+1][j-1]; else ne = null;
if (n&&w) nw = board[i-1][j-1]; else nw = null;
if (s&&e) se = board[i+1][j+1]; else se = null;
if (s&&w) sw = board[i-1][j+1]; else sw = null;
eval(((j-from.y != 1)?"s":"n")+((i-from.x != 1)?"e":"w")+"=0;");
if ((sw==0) && (integ(ne)==1)) return false;
if ((se==0) && (integ(nw)==1)) return false;
if ((nw==0) && (se==1.1)) return false;
if ((ne==0) && (sw==1.1)) return false;
return true;
message("You may begin! Select a piece to move.");
my_turn = true;
// -->
</SCRIPT>

Well, you can get a free tutorial to Java at http://www.mindview.net/. It's the "Thinking In Java" book. You can download the whole book from that site, it's about a thousand pages. If you read that whole book, you'll know exactly where to start and probably how to finish it too.
As a gimmie, think about it -- you'll have to remove all of the browser-detect code, since browser-detection is only done to determine which version of JavaScript is supported by the browser.

Similar Messages

  • Is there an easy way to convert from a String with a comma, ie. 1,000.00 to

    Is there an easy way to convert from a String with a comma, ie. 1,000.00 to a float or a double?
    thanks,
    dosteov

    Like DrClap said: DecimalFormat. However, make sure you understand the Locale things, as explained at http://java.sun.com/j2se/1.3/docs/api/java/text/DecimalFormat.html (which refers to NumberFormat as well) and use them explicitly. Like
    public class FormatTest
      public static void main(String args[])
        try
          // see NumberFormat.getInstance()
          DecimalFormat fmt = new DecimalFormat();
          Number num = fmt.parse("1,000.01");
          System.out.println(num.doubleValue());
        catch(ParseException pe)
          System.out.println(pe);
    }most likely seems OK on your system, but may print "1.0" (or even fail) on some non-English platforms!
    When performing calculations, also see http://developer.java.sun.com/developer/JDCTechTips/2001/tt0807.html
    a.

  • Convert javascript array to java array

    Is there any way possible to convert javascript array to java array?

    if you will try to experiment a javascript array
    putting it to a hidden element, it will be converted
    to a string (comma delimited). You can get the value
    of that element as a string and use StringTokenizer
    class to put the values into a java arrayThanks, got it.

  • Is there an easy way to convert original images to b&w ?

    I have a canon 5d mark II and when I decide to shoot b&w pics, this is what i do : I set my camera to b&w and shoot raw+jpeg. raw files come out in color all the time but jpegs show up in b&w when i import them . I decided to do so as it is very time consuming to convert the original images to b&w one by one.
    Is there an easy way to do it?? Any suggestions? 

    Little known hint well worth knowing:
    If you use the menu selection "Photos→Add Adjustment" or "Photos→Add Adjustment Preset", the operation is done to all selected images.
    In addition to what Frank says, you could also apply a B&W Adjustment Preset when the files are imported.  These adjustments are like any others -- they can be toggled on and off, removed, and adjusted with the settings in the Bricks used.
    For grayscale, it is well worth the time exploring the included Presets and the slider controls.  Afaik, sophisticated grayscale photographers optimize their images in color prior to converting to grayscale.
    JPG is 8-bit and lossy.  RAW is (up to) 16-bit and unconverted (no loss of data, but "lossless" isn't quite right).  If the JPG conversion and quality suffices, there is little reason to shoot RAW+JPEG.
    In essence, you can use the in-camera-created grayscale JPGs, with their fixed and baked-in conversion settings, or you can use Aperture's broad (and time-consuming) grayscale controls.  If you do the latter, and settle on a conversion that works for your camera and subject(s), save it as an Adjustment Preset and use it.

  • Is there an easy way to convert and import MTS files from a external hardrive so that I can edit them in FCP?

    I am trying to convert game footage that is in MTS format to something that I can edit into a quick highlights video. I have final cut express and the standard IMovie '09. looking for easiest solution, everything seems to involve using one application to convert to Quicktime and then dropping file into Iphoto etc. is there an easy way?

    I'm not completely sure that MPEG Streamclip can convert AVCHD footage (.mts files).  If MPEG Streamclip doesn't do the job, then get a copy of Clipwrap, which was designed for transcoding .mts files to QuickTime/Apple Intermediate Codec (that's the format/codec you need to convert the .mts files to for use in FCE).

  • CS4\5 - Easy Way to Convert Gradient Stops to Swatches?

    Hi Folks
    I wonder if there is an easy way to do this?
    I am working with an AI file where I want to create swatches for every colour I use to ensure consistency. There are a number of gradients in the document, and I have stored the colour stops from the gradient as swatches. So far so good.
    Now I want to adjust the gradient colour stops, but there seems to be no easy way to add a new swatch from a gradient colour stop, or to update an existing swatch from a gradient colour stop.
    The swatches palette that appears when clicking the gradient colour stop has no buttons on it to add a new swatch, for example, and none of the usual swatch creating methods seem to work.
    Is this possible without reverting to some cumbersome workaround?
    Any help appreciated!
    Cheers
    Richard

    Does clicking on a stop then dragging the color from the Color panel to the Swatches panel not work for you (translation, er, repetition of post 1)?
    Also, wouldn't the Edit > Edit Colors mechanism help here?

  • Best way to perform vSync in a java applet

    Hi, (sorry for my bad english)
    I'm looking for the best way to perform vertical synchronization in a java applet.
    I saw it is possible with the jogl library but i don't need a heavy 3d lib (it's just for 2d)
    Is there a more simple lib allowing vSync in applets (and if possible, working on every windows, mac, linux...)

    why do you need this?

  • JavaScript call to Java applet

    Sorry if this message get posted twice, but I haven't seen the 1st. I sent.
    I seem to have a problem with a form trying to call an applet. I hava a button like this:
    <input type=button value="Add" onClick="Nota.addRow('2','3','12.80','Cacahuates Mafer 1/2 kg.')">
    my Nota.addRow method is thisone:
    public void addRow (String idS, String qtyS, String priceS, String desc) {
    int id= Integer.parseInt (idS);
    int qty= Integer.parseInt (qtyS);
    float price= Float.parseFloat (priceS);
    remove (total);
    renglones[renglonCnt]= new Renglon (id,qty,price,desc);
    add (renglones[renglonCnt]);//<- This line is not adding the Row when i call it from JavaScript. Otherwise it works just fine...
    //total= Renglon.Total();
    //add (total);
    System.out.println("El id es: " + Integer.toString(id));
    System.out.println("La cantidad es: " + Integer.toString(qty));
    System.out.println("El precio es: " + Float.toString(price));
    System.out.println("La descripcion es: " + desc.toString());
    System.out.println("El precio del objeto es: " + Float.toString(renglones[renglonCnt].getTotal()));
    renglonCnt++;
    Altough my addRow works when I callit from a Nota object it doesn't when i call it from javascript.
    total is just a panel that you get from class Renglon.
    And Renglon is a Panel class too.
    I'll appreciate any help, thanks.
    Jeronimo

    Hey, that's really good news, does it actually adds the row to the applet and gets the new total?!
    Anyway, i tried 1.) (wich describes the applet quite well) and 2.) but still doesn't works for me. Also changed the "price" line...
    Im using:
    Navigator 4.72
    IE 5.50
    Netscape 6
    Here's the html code (the form):
    <form>
    <table border=5 WIDTH=500 align=center>
    <tr>
    <TD width=30%>
    <table border=1 width="100%" >
    <tr>
    <th WIDTH="20%"> Cantidad </th>
    <th WIDTH="26%"> Descripci&oacute;n </th>
    <th WIDTH="20%">Precio Unitario</th>
    <th WIDTH="20%"> Agregar </th>
    </tr>
    <tr>
    <td WIDTH="20%" align=center>
         <input size=2 name=cantidad maxlength=2>
         </td>
    <td WIDTH="26%">
         Cerveza Sol 600ml.
         </td>
    <td WIDTH="20%">
         $15.50
         </td>
    <td WIDTH="20%" align=center>
         <input type=button value="Add" onClick="document.Nota.addRow('1','12','15.50','Cerveza-Sol-600ml.')">
         </td>
    </tr>
    <tr>
    <td WIDTH="20%" align=center><input size=2 maxlength=2></td>
    <td WIDTH="26%">
         Cacahuates Mafer 1/2 kg.
         </td>
    <td WIDTH="20%">
         $12.80
         </td>
    <td WIDTH="20%" align=center>
         <!--<input type=button value="Add" onClick="Nota.addRow('2','3','12.80','Cacahuates Mafer 1/2 kg.')">
         -->
         <input type=button value="Test" onClick="alert (Nota)"
         </td>
    </tr>
    <tr>
    <td WIDTH="20%" align=center><input size=2 maxlength=2></td>
    <td WIDTH="26%"> </td>
    <td WIDTH="20%"> </td>
    <td WIDTH="20%" align=center>
         <input type=button value="Add">
         </td>
    </tr>
    <tr>
    <td WIDTH="20%" align=center><input size=2 maxlength=2></td>
    <td WIDTH="26%"> </td>
    <td WIDTH="20%"> </td>
    <td WIDTH="20%" align=center><input type=button value="Add"></td>
    </tr>
    </table>
    </td>
    <td width="40%">
    <applet name=Nota code=Nota.class width=350 height=250> </applet>
    </td>
    </tr>
    <tr>
    <td colspan=2 align=center>
    <input type=button value="Enviar Pedido">
    </td>
    </tr>
    </table>
    </form>
    Here's the Nota applet code:
    import java.awt.*;
    import java.applet.*;
    public class Nota extends Applet {
    private Renglon renglones[];
    private BarraTitulo titulo;
    private int renglonCnt;
    private Panel total;
    public void init () {
    setLayout (new GridLayout(12,1));
    renglonCnt=0;
    renglones= new Renglon [10];
    total= Renglon.Total();
    public void start () {
    String titulos[]= new String [4];
    titulos[0]="(-) Cantidad (+)";
    titulos[1]="Descripcion";
    titulos[2]="Precio Unitario";
    titulos[3]="Total";
    titulo= new BarraTitulo (titulos,12);
    add (titulo);
    add (total);
    public void addRow (String idS, String qtyS, String priceS, String desc) {
    int id= Integer.parseInt (idS);
    int qty= Integer.parseInt (qtyS);
    //float price= Float.parseFloat (priceS);
    float price= Float.valueOf (priceS).floatValue();
    remove (total);
    renglones[renglonCnt]= new Renglon (id,qty,price,desc);
    add (renglones[renglonCnt]);
    //total= Renglon.Total();
    //add (total);
    //THESE LINES SHOW EVERTHING WELL IN THE JAVA CONSOLE, BUT THESE ARE JUST FOR DEBUG. System.out.println("El id es: " + Integer.toString(id));
    System.out.println("La cantidad es: " + Integer.toString(qty));
    System.out.println("El precio es: " + Float.toString(price));
    System.out.println("La descripcion es: " + desc.toString());
    System.out.println("El precio del objeto es: " + Float.toString(renglones[renglonCnt].getTotal()));
    renglonCnt++;
    This is the Renglon class code:
    import java.awt.*;
    import java.awt.event.*;
    public class Renglon extends Panel implements ActionListener {
    private TextField qty, description, up, total;
    private Button more, less;
    private int cantidad, identificador;
    private float unitP;
    private String descripcion;
    static float elTotal= 0;
    static Panel totalP= new Panel();
    static Label c4tot= new Label();
    public Renglon () {
    this(1, 1, (float) 2.50, "Algun articulo");
    public Renglon (int id, int q, float pu, String desc) {
    identificador= id;
    cantidad= q;
    unitP= pu;
    descripcion= desc;
    elTotal+= cantidad * unitP;
    Panel addsub;
    setLayout (new GridLayout (1,4));
    addsub= new Panel();
    addsub.setLayout(new GridLayout(1,3));
    less= new Button ("<<");
    more= new Button (">>");
    less.addActionListener (this);
    more.addActionListener (this);
    Integer c= new Integer (cantidad);
    qty= new TextField (c.toString());
    description= new TextField (descripcion);
    Float x= new Float (unitP);
    up= new TextField ("$" + x.toString());
    Float t= new Float (getTotal());
    total= new TextField ("$" + t.toString());
    qty.setEditable (false);
    description.setEditable (false);
    up.setEditable (false);
    total.setEditable (false);
    addsub.add (less);
    addsub.add (qty);
    addsub.add (more);
    add (addsub);
    add (description);
    add (up);
    add (total);
    setVisible (true);
    public float getTotal () {
    return ((float) cantidad*unitP);
    public void actionPerformed (ActionEvent e) {
    if (e.getActionCommand().equals("<<")){
    cantidad--;
    elTotal-= unitP;
    if (cantidad < 0) {
    cantidad=0;
         elTotal+= unitP;
    } else {
    cantidad++;
    elTotal+= unitP;
    Float nuevoTot= new Float (getTotal());
    Integer c= new Integer (cantidad);
    qty.setText (c.toString());
    total.setText ("$" + nuevoTot.toString());
    Float et= new Float (elTotal);
    c4tot.setText("$" + et.toString());
    static public Panel Total () {
    totalP.setLayout (new GridLayout(1,4));
    Label c1,c2,c3;
    Float totalF= new Float (elTotal);
    c1= new Label("");
    c2= new Label("");
    c3= new Label("Total:");
    c4tot= new Label("$" + totalF.toString());
    totalP.add(c1);
    totalP.add(c2);
    totalP.add(c3);
    totalP.add(c4tot);
    totalP.setVisible(true);
    return (totalP);
    And just in case, this is the BarraTitulo class code:
    import java.awt.*;
    public class BarraTitulo extends Panel {
    public BarraTitulo (String [] titulos) {
    this (titulos,15);
    public BarraTitulo (String [] titulos, int size) {
    Label labels;
    Font ft= new Font("Serif",Font.BOLD, size);
    int length= titulos.length + 1;
    setLayout (new GridLayout (1,length));
    setFont (ft);
    for (int i=0; i< titulos.length; i++) {
    labels= new Label(titulos);
    add (labels);
    Thanx again for your time.
    Jeronimo

  • What's the easiest way to save info from a java applet to use it later?

    How can a java applet take info from a user (text, binary, picture, or some other form), and save it (like on my computer), then bring it up when another user views the same applet?

    flounder
    "Did you try it?
    Do you have a file called Stuff.txt?
    Does the file contain "Testing outstream"?"
    Yes I compiled and ran the code as a Java applet, nothing happened. I was expecting a write error becase java applets are not inally allowed to write to a file. Yes I have file a Stuff.txt in the same directory as the program. No, nothing happened to the file, it stays blank.
    paulcw
    "And if you tested it, how did you test it?
    (Hint: the code you've shown doesn't need to extend Applet.) "
    If it does not extend applet then I get a class cast exception when I try to compile it as an applet.

  • Is there an easy way to convert a long string into an array?

    I can convert a long string into a 1-d array by parsing and using build array, but I would like to know if there is a function to make this easier.
    For example:
    from/   aaaaaaaabbbbbbbbccccccccdddddddd         (string of ascii)
    to/       an array that is 1-d with each element having eight characters
              aaaaaaaa
              bbbbbbbb
              cccccccc
              dddddddd
    Thank you.
    Solved!
    Go to Solution.

    Try something like this:
    (If you can guarantee that the string length is an integer multiple of 8, you an drop the two triangular modes in the upper left. )
    Message Edited by altenbach on 03-14-2010 06:40 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    ChopString.png ‏9 KB

  • Exist an easy way to convert base64 code in XML files into the original image file on forms

    I've made a form in lifecycle that will be distributed by email as a pdf, and submitted back to me as an XML file and then that data imported into the pdf form template to view the data. Issue is I have an "attach image" field on the form and in XML it gets written to a base64 encoded format. Is there convenient way to extract this code from the XML file so that I would have a workable jpeg image file that I can save and open in other apps? Thank you in advance!  -Robert Tampa

    I tried to make John Brinkman's sample working in reverse.
    This script will grab an image field's value and produce an attachment (png-file), which then can be saved to the hard drive.
    //Get Base64 data of the image field
    var b64Data = ImageField1.value.image.value;
    //Convert to a read stream
    var ReadStream = util.streamFromString(b64Data);
    //Decode from Base64
    var DecodedStream = Net.streamDecode(ReadStream, "base64");
    //Attach an empty image file
    event.target.createDataObject("MyExportImage.png", "", "image/png");
    //Update attached image file with stream data
    event.target.setDataObjectContents("MyExportImage.png", DecodedStream);
    //Show attachment pane
    event.target.viewState = {overViewMode:7};
    This works so far, but the produced images are always cutted off.
    No idea what's the reason for this behavior.

  • Is there an easier way to convert files from Windows Media Player to iTunes

    I have many gb's of music in my Windows Media Player...now that I have an ipod I want to move the music over. Do I really have to do this one file at a time or is there away to move over whole albums at once? Is there a way to transfer the entire library at once? Do I have to reload ALL of those CD's? PLEASE HELP !!!!

    Maybe you can help me out too. I have copied over 250 gigs of music in WAV loss less files to windows media player. On media player I see the artist, album etc. However, when I add the file, either as the song or whole album only the track number and song title copy to the itunes. How do I get all the other information like genre, album title, artist. If I convert to applelossless I still do not get anything and when I search AppleSTore for album art nothing happens. Please help.

  • Easier way to convert array to cluster with named variables?

    I have an array of variables, I would like to essentially unbundle that array to named variables.
    I believe the only way of doing this is by converting the array to cluster (besides removing each element one by one)?
    Is what I have done below the best way of doing it? seems a bit weird having to unbundle and rebundle by name.
    comments appreciated.
     

    Your problem code is actually right before the red square. Instead of the "array-to-cluster-unbudle dance", you should simply use a plain index array resized for the same number of outputs. same functionality, less convoluted.
    Your wiring is a bit of a mess and it is hard to tell if the order of elements in the array is the same as in the cluster.  Maybe a simple typecast to the cluster would work.
     

  • I have lots of beta monkey drum loops in WAV format, is there an easy way to convert format for garageband use?

    to convert all these files for garageband use (apple loops)

    You will have to convert them to proper Apple Loops - add tags for key and tempo, category.
    One way to do this would be to use GarageBand to add the wav files to the Loop Library one by one:
    Find out the tempo and the key (if applicable) of one of your loops.
    Set the key and tempo for your project.
    Import a loop to a real instrument track and name the track, select the loop and use the command "Edit > Add to loop library". Set all the tags correctly, so the loopp will be properly indexed.
    There used to be a SoundTrack Loop Utility, but I am not sure if it is still available somewhere. My old links don't work anymore.
    Regards
    Léonie

  • Easier Way to convert Hex to Integer

    This problem is mainly to do with a hex string to integer conversion.  The device, connected via serial connection outputs hex in the format 0A00, when looking at it in hex.  The first two digits are the data, the last two are attached to seperate data points.  what I'm trying to do is to raster the last 2 digits off so that 2A00 becomes 2A and then convert the 2A into integer format (42).  I have come up with a method to do this, but it is very messy and occasionally results in data loss.  I have attached my vi (8.2).  The large integer being subtracted is a constant that continues to come up for reasons I am not aware of.
    another issue which I am coding through is the fact that sometimes a byte slips by, making 2A00 become 00BB or something of that format.  Is there a way to scan the string, determine whether the first two digits or the last two digits are the valid ones and then seperate the valid string?  In this code, it would be necessary to allow for the value 0000 to read 0.
    If there is confusion, here is some examples of incoming data and desired output
    0100 - 1
    0A00 - 10
    0005 -5
    000B - 11
    etc.
    Solved!
    Go to Solution.
    Attachments:
    geiger read.vi ‏28 KB

    Since you are reading 2 bytes, it looks like you should be dealing with a 16 bit number. Typecast to U16 rather than I32 like you are doing now. And all of that string manipulation make it look like you are getting a string of ASCII formatted characters like "0" "A" "1" "B" rather than a 2 byte string of ASCII characters 0A and 1B. Then you can split the U16 number and take the higher order byte.
    I can't explain why you would be having a byte slip by unless it has something to do with all that string manipulation you are trying to do.  But if it still happens, and you know one byte for the other is always zero.  Just take the high order byte and add it to the low order byte.  Since one is zero, it will have no effect on the other byte.
    Message Edited by Ravens Fan on 07-07-2009 01:54 PM
    Attachments:
    geiger%20read[1]_BD.png ‏3 KB

Maybe you are looking for

  • Unable to create file - SXMB_MONI -- Trouble shooting

    I am replicating Products Data from SRM to MDM. I am using BBP_CCM_TRANSFER_CATALOG report in SRM. This is Proxy-File scenario. After executing the above report, I can seee the Message in SXMB_MONI in PI. The message has passed through these steps. I

  • Can't transfer files from old macbook to new retina?

    Hello, I am well aware that the macbook pro retina does not have a firewire 800 port, but rather thunderbolt. Unfortunately I didn't know of this when I asked an apple employee about how to transfer files from my old broken macbook pro (leopard) to t

  • Dreaded iMac lines symptom hits 23" Cinema display!

    Have a 17" iMac that developed the "lines" symptom within a month after the factory warranty expired - that computer is all but useless now unless I spend the $700+ to get the display working again (& who knows how long the fix will last...) Now, the

  • NTSC wide gamut matte vs. glossy

    Getting a new laptop. I have a choice for the 17.3" monitor: 1. 72% NTSC color gamut matte 2. 90% NTSC color gamut glossy I really like mattes, but I don't know if there is a big difference between the two percentiles. Has anyone used both? Which wou

  • Find Photos Not In Collection

    I am sure this seems like a OTW [off the wall] requirement, but does anyone know how to locate photos that have not been assigned to a Collection? I have 13,500 photos and went through them assigning them to collections. After that exercise, I find I