Converting an appilcation to an applet

I need some help with my logic in this algorithm
<hr>
import.awt.event.*;
import.awt.*;
import javax.swing.JApplet;
public class name extends JApplet implements ActionListener {
         call to subclass that creates Frame
         create instance variables
         declare and initialize variables
}public void action events{
}  //end of action events.
public void method {
}/end of method
public staic void main(String args[]) {
}//end of main
public void method {
}end of method
public void method {
}// end of method.<hr>
The question is where would the public void init() be placed in order to run as an applet
Thanks in advance..

Yes that's it
but..
The application is 400 lines of code, which makes me reluctant to post it
Here is where I think the problem may be
public abstract class Calculator extends JApplet implements ActionListener {
       // creating instances of objects
         CalcFrame      frame;
            Label      display;
            Button      key[] = new Button[20];                     // creates a button object array of 20
            Button      clearAll,
            clearEntry;
      boolean addButtonPressed = false,
                  subtractButtonPressed = false,
                  multiplyButtonPressed = false,
               divideButtonPressed = false,
                  decimalButtonPressed = false,
                  equalButtonPressed = false,
                  decimalPoint = false,
                  operatorPressed=false,
                  errorFlag = false;
               String      inputNumber = "";                       // store user input
       double     initialNumber = 0,                               // first number operator
                  currentNumber = 0,                            // second number operator
                  displayNumber = 0,
                  calcResult = 0;
       int         SLENGTH = 12;                                    // 12 digits maximum
public  void init(){
                   public void main(String args[]) {
               Calculator calc = new Calculator();
               calc.makeCalculator();
more methods...
}the error message is expected class or interface

Similar Messages

  • Help need to convert hsa prog to an applet

    Hey everybody I have no clue what i am doin im trying to convert a mathquiz program from the hsa console to an applet. ive attached my hsa code:
    import java.awt.*;
    import hsa.Console;
    import java.io.*;
    public class MathQuizhsa
    static Console c; // The output "c" Console.
    public static void main (String[] args)
    c = new Console ();
    char cont;
    String name1, name2, name3;
    //Start Of Loop.
    while (true)
    // Varible declaration
    int scorechart = 0;
    int scorechart1 = 300;
    //Start of score reset
    int score = 0;
    //End of score reset
    // Display Code
    c.clear ();
    c.println ("\t\t\t\tMath Quiz");
    c.println ("\n\tType:");
    c.println ("\t1 for Easy");
    c.println ("\t2 for Medium");
    c.println ("\t3 for Hard");
    c.println ("\t4 for High Scores");
    c.println ("\t5 for HighScore Setup and reset");
    c.println ("\t6 or more to Exit");
    c.print ("\nEnter Choice Here: ");
    int dec = c.readInt ();
    c.clear ();
    // End of Display Code
    // Starting Of Easy code!....................................
    if (dec == 1)
    int count = 1;
    boolean boo = true;
    while (boo)
    if (count <= 10)
    c.println ("MATH QUIZ..... EASY");
    c.setColor (Color.black);
    c.drawRect (400, 100, 20, 200);
    c.setColor (Color.blue);
    c.fillRect (400, scorechart1, 20, scorechart);
    c.setCursor (17, 45);
    c.println ("Your Score Is: " + score);
    int num1;
    num1 = (int) (Math.random () * (15));
    int num2;
    num2 = (int) (Math.random () * (15));
    int total;
    c.setCursor (2, 1);
    c.println ("Equation " + count);
    c.print ("\t" + num1 + " + " + num2 + " = ");
    total = c.readInt ();
    if (total == num1 + num2)
    c.println ("Correct, press any key to continue");
    cont = c.getChar ();
    score++;
    scorechart = scorechart + 20;
    scorechart1 = scorechart1 - 20;
    else
    c.println ("Wrong, press any key to continue");
    cont = c.getChar ();
    c.clear ();
    else if (count > 10)
    boo = false;
    count++;
    c.clear ();
    // End Of Easy Code!.........................................
    // Starting Of Medium code!....................................
    if (dec == 2)
    int count = 1;
    boolean boo = true;
    while (boo)
    if (count <= 10)
    c.setCursor (1, 1);
    c.println ("MATH QUIZ..... MEDIUM");
    c.setColor (Color.black);
    c.drawRect (400, 100, 20, 200);
    c.setColor (Color.blue);
    c.fillRect (400, scorechart1, 20, scorechart);
    c.setCursor (17, 45);
    c.println ("Your Score Is: " + score);
    int num1;
    num1 = (int) (Math.random () * (50));
    int num2;
    num2 = (int) (Math.random () * (50));
    int total;
    c.setCursor (2, 1);
    c.println ("Equation " + count);
    c.print ("\t" + num1 + " + " + num2 + " = ");
    total = c.readInt ();
    if (total == num1 + num2)
    c.println ("Correct, press any key to continue");
    cont = c.getChar ();
    score++;
    scorechart = scorechart + 20;
    scorechart1 = scorechart1 - 20;
    else
    c.println ("Wrong, press any key to continue");
    cont = c.getChar ();
    c.clear ();
    else if (count > 10)
    boo = false;
    count++;
    // End Of Medium Code!.........................................
    // Starting Of Hard code!....................................
    if (dec == 3)
    int count = 1;
    boolean boo = true;
    while (boo)
    if (count <= 10)
    c.setCursor (1, 1);
    c.println ("MATH QUIZ..... HARD");
    c.setColor (Color.black);
    c.drawRect (400, 100, 20, 200);
    c.setColor (Color.blue);
    c.fillRect (400, scorechart1, 20, scorechart);
    c.setCursor (17, 45);
    c.println ("Your Score Is: " + score);
    int num1;
    num1 = (int) (Math.random () * (100));
    int num2;
    num2 = (int) (Math.random () * (100));
    int total;
    c.setCursor (2, 1);
    c.println ("Equation " + count);
    c.print ("\t" + num1 + " + " + num2 + " = ");
    total = c.readInt ();
    if (total == num1 + num2)
    c.println ("Correct, press any key to continue");
    cont = c.getChar ();
    score++;
    scorechart = scorechart + 20;
    scorechart1 = scorechart1 - 20;
    else
    c.println ("Wrong, press any key to continue");
    cont = c.getChar ();
    c.clear ();
    else if (count > 10)
    boo = false;
    count++;
    // End Of Hard Code!.........................................
    // Start of highscore page!..................................
    else if (dec == 4)
    BufferedReader easyhigh1;
    BufferedReader easyhigh2;
    BufferedReader medhigh1;
    BufferedReader medhigh2;
    BufferedReader hardhigh1;
    BufferedReader hardhigh2;
    c.clear ();
    c.println ("\n\t\t\t\tHigh Scores!!");
    try
    //Easy highscore read start............
    String EasyHighnum, EasyHighname;
    easyhigh1 = new BufferedReader (new FileReader ("EasyHighscore.score"));
    EasyHighnum = easyhigh1.readLine ();
    easyhigh2 = new BufferedReader (new FileReader ("EasyName.score"));
    EasyHighname = easyhigh2.readLine ();
    c.println ("\t\t\t Press any key to exit!");
    c.println ("\nEasy High Scores!..");
    c.println ("\n\t" + EasyHighname);
    c.println ("\t\t\t\t\t\t\t\t" + EasyHighnum);
    //Easy highscore read end..............
    //Med highscore read start............
    String MedHighnum, MedHighname;
    medhigh1 = new BufferedReader (new FileReader ("MedHighscore.score"));
    MedHighnum = medhigh1.readLine ();
    medhigh2 = new BufferedReader (new FileReader ("MedName.score"));
    MedHighname = medhigh2.readLine ();
    c.println ("\nMedium High Scores!..");
    c.println ("\n\t" + MedHighname);
    c.println ("\t\t\t\t\t\t\t\t" + MedHighnum);
    //Med highscore read End..............
    //Hard highscore read start............
    String HardHighnum = "";
    String HardHighname = "";
    hardhigh1 = new BufferedReader (new FileReader ("HardHighscore.score"));
    HardHighnum = hardhigh1.readLine ();
    hardhigh2 = new BufferedReader (new FileReader ("HardName.score"));
    HardHighname = hardhigh2.readLine ();
    c.println ("\nHard High Scores!..");
    c.println ("\n\t" + HardHighname);
    c.println ("\t\t\t\t\t\t\t\t" + HardHighnum);
    //Hard highscore read End..............
    char ans = c.getChar ();
    catch (FileNotFoundException e)
    c.println ("\nHighscore files missing! Please run option 5 in main menu");
    c.println ("Press any key to continue");
    cont = c.getChar ();
    return;
    finally
    continue;
    // End of highscore page!....................................
    // Start of highscore setup
    else if (dec == 5)
    try
    //easy file write
    PrintWriter out
    = new PrintWriter (new BufferedWriter (new FileWriter ("EasyHighscore.score")));
    out.print ("0");
    out.close ();
    PrintWriter out2
    = new PrintWriter (new BufferedWriter (new FileWriter ("EasyName.score")));
    out2.print ("NoName");
    out2.close ();
    //med file write
    PrintWriter out3
    = new PrintWriter (new BufferedWriter (new FileWriter ("MedHighscore.score")));
    out3.print ("0");
    out3.close ();
    PrintWriter out4
    = new PrintWriter (new BufferedWriter (new FileWriter ("MedName.score")));
    out4.print ("NoName");
    out4.close ();
    //hard file write
    PrintWriter out5
    = new PrintWriter (new BufferedWriter (new FileWriter ("HardHighscore.score")));
    out5.print ("0");
    out5.close ();
    PrintWriter out6
    = new PrintWriter (new BufferedWriter (new FileWriter ("HardName.score")));
    out6.print ("NoName");
    out6.close ();
    c.print ("Installing.");
    int loadbar = 5;
    for (int ii = 0 ; ii <= 20 ; ii++)
    c.print (".");
    c.setColor (Color.black);
    c.drawRect (5, 20, 205, 18);
    c.setColor (Color.blue);
    c.fillRect (5, 20, loadbar, 18);
    loadbar = loadbar + 10;
    c.setCursor (3, 1);
    c.print ((ii * 5) + "%");
    Thread.sleep (100);
    c.println ("\nYour Highscores are now reset and installed.");
    c.println ("Press any key to continue");
    cont = c.getChar ();
    finally
    continue;
    // End of highscore setup
    // Start Of End Code!........................................
    else if (dec >= 6)
    System.exit (0);
    // Start Of End Code!........................................
    // Score Code................................................
    if (dec >= 1 & dec <= 3)
    c.setColor (Color.black);
    c.drawRect (400, 100, 20, 200);
    c.setColor (Color.blue);
    c.fillRect (400, scorechart1, 20, scorechart);
    if (score == 0)
    c.println ("Wow... That was horrible: " + score + " out of 10!");
    else if (score == 1)
    c.println ("Go Back To Kindergarten: " + score + " out of 10!");
    else if (score == 2)
    c.println ("Pitiful: " + score + " out of 10!");
    else if (score == 3)
    c.println ("You Suck: " + score + " out of 10!");
    else if (score == 4)
    c.println ("Awesome if your six: " + score + " out of 10!");
    else if (score == 5)
    c.println ("Cant complain with a pass: " + score + " out of 10!");
    else if (score == 6)
    c.println ("Barely: " + score + " out of 10!");
    else if (score == 7)
    c.println ("Ill give u a E for effort: " + score + " out of 10!");
    else if (score == 8)
    c.println ("Wow: " + score + " out of 10!");
    else if (score == 9)
    c.println ("Nerd: " + score + " out of 10!");
    else if (score == 10)
    c.println ("Your Score Was Perfect: " + score + " out of 10!");
    c.println ("Press any key to continue");
    c.setCursor (17, 45);
    c.println ("Your Score Is: " + score);
    cont = c.getChar ();
    c.clear ();
    else
    // Score Code................................................
    // Easy High Score Code...........................................
    if (dec == 1)
    BufferedReader file1;
    try
    file1 = new BufferedReader (new FileReader ("EasyHighscore.score"));
    catch (FileNotFoundException e)
    c.println ("No High Score. Please go to option 5 in main menu");
    c.println ("Press any key to continue");
    cont = c.getChar ();
    continue;
    try
    int highscore1 = file1.read ();
    if (highscore1 == 48)
    highscore1 = 0;
    else if (highscore1 == 49)
    highscore1 = 1;
    else if (highscore1 == 50)
    highscore1 = 2;
    else if (highscore1 == 51)
    highscore1 = 3;
    else if (highscore1 == 52)
    highscore1 = 4;
    else if (highscore1 == 53)
    highscore1 = 5;
    else if (highscore1 == 54)
    highscore1 = 6;
    else if (highscore1 == 55)
    highscore1 = 7;
    else if (highscore1 == 56)
    highscore1 = 8;
    else if (highscore1 == 57)
    highscore1 = 9;
    else if (highscore1 == 58)
    highscore1 = 10;
    if (score >= highscore1)
    highscore1 = score;
    c.println ("Congrats! You beat the highscore. <Enter Name> ");
    name1 = c.readLine ();
    try
    PrintWriter out
    = new PrintWriter (new BufferedWriter (new FileWriter ("EasyHighscore.score")));
    out.print (highscore1);
    out.close ();
    PrintWriter out2
    = new PrintWriter (new BufferedWriter (new FileWriter ("EasyName.score")));
    out2.print (name1);
    out2.close ();
    finally
    continue;
    finally
    continue;
    // End Easy High Score Code...........................................
    // Medium High Score Code...........................................
    else if (dec == 2)
    BufferedReader file2;
    try
    file2 = new BufferedReader (new FileReader ("MedHighscore.score"));
    catch (FileNotFoundException e)
    c.println ("No High Score. Please go to option 5 in main menu");
    c.println ("Press any key to continue");
    cont = c.getChar ();
    continue;
    try
    int highscore2 = file2.read ();
    if (highscore2 == 48)
    highscore2 = 0;
    else if (highscore2 == 49)
    highscore2 = 1;
    else if (highscore2 == 50)
    highscore2 = 2;
    else if (highscore2 == 51)
    highscore2 = 3;
    else if (highscore2 == 52)
    highscore2 = 4;
    else if (highscore2 == 53)
    highscore2 = 5;
    else if (highscore2 == 54)
    highscore2 = 6;
    else if (highscore2 == 55)
    highscore2 = 7;
    else if (highscore2 == 56)
    highscore2 = 8;
    else if (highscore2 == 57)
    highscore2 = 9;
    else if (highscore2 == 58)
    highscore2 = 10;
    if (score >= highscore2)
    highscore2 = score;
    c.println ("Congrats! You beat the highscore. <Enter Name> ");
    name2 = c.readLine ();
    try
    PrintWriter out3
    = new PrintWriter (new BufferedWriter (new FileWriter ("MedHighscore.score")));
    out3.print (highscore2);
    out3.close ();
    PrintWriter out4
    = new PrintWriter (new BufferedWriter (new FileWriter ("MedName.score")));
    out4.print (name2);
    out4.close ();
    finally
    continue;
    finally
    continue;
    // End Medium High Score Code...........................................
    // Hard High Score Code...........................................
    else if (dec == 3)
    BufferedReader file3;
    try
    file3 = new BufferedReader (new FileReader ("HardHighscore.score"));
    catch (FileNotFoundException e)
    c.println ("No High Score. Please go to option 5 in main menu");
    c.println ("Press any key to continue");
    cont = c.getChar ();
    continue;
    try
    int highscore3 = file3.read ();
    if (highscore3 == 48)
    highscore3 = 0;
    else if (highscore3 == 49)
    highscore3 = 1;
    else if (highscore3 == 50)
    highscore3 = 2;
    else if (highscore3 == 51)
    highscore3 = 3;
    else if (highscore3 == 52)
    highscore3 = 4;
    else if (highscore3 == 53)
    highscore3 = 5;
    else if (highscore3 == 54)
    highscore3 = 6;
    else if (highscore3 == 55)
    highscore3 = 7;
    else if (highscore3 == 56)
    highscore3 = 8;
    else if (highscore3 == 57)
    highscore3 = 9;
    else if (highscore3 == 58)
    highscore3 = 10;
    if (score >= highscore3)
    highscore3 = score;
    c.println ("Congrats! You beat the highscore. <Enter Name> ");
    name3 = c.readLine ();
    try
    PrintWriter out5
    = new PrintWriter (new BufferedWriter (new FileWriter ("HardHighscore.score")));
    out5.print (highscore3);
    out5.close ();
    PrintWriter out6
    = new PrintWriter (new BufferedWriter (new FileWriter ("HardName.score")));
    out6.print (name3);
    out6.close ();
    finally
    continue;
    finally
    continue;
    // End Hard High Score Code...........................................
    //End Of Loop.
    // Place your program here.
    } // main method
    } // MathQuiz class

    Most of the awt drawing methods are the same; you just need to provide a panel that calls them in its paint() method.
    You also need to add text fields for any inputs, and buttons or a combo box for choosing the skill level.
    You need to store high scores on the server as there is no way for an applet to access a local file.
    The code int highscore1 = file1.read ();
    if (highscore1 == 48)
    ...would better read in a string then use Integer.parseInt() rather than all those character comparisons, or one of the Character.digit() conversions.
    The code that is many versions of if (score == 0)
    c.println ("Wow... That was horrible: " + score + " out of 10!");
    ...can either be replaced with switch/case or an array of strings.
    You'd be better off reducing all the code you don't need before you convert it to an applet, just so there's only half the amount to convert.
    Pete

  • 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.

  • Convert applet to swing

    Hi;
    Could anyone help me to convert my example code from applet to swing,please, thank
    import java.awt.*;
    import java.applet.*;
    import java.lang.Math;
    import java.awt.Font;
    import java.lang.Integer;
    /*** Main class == Applet  ***/
    public class Suffix extends Applet implements Runnable {
       private Thread main;
       public s_tree _tree=null;
       public node nd=null;
       public boolean userPause=false,resumed=false;
       private String str[]={"GOOGOL$","Paused","Resumed","Compacting","Done"};
       public Color bl=Color.blue,rd=Color.red;
       public Font fnt;
       public int mode=3,delay=3000;
       private char alph[]={'$','Q','W','E','R','T','Y','U','I','O',
                        'P','A','S','D','F','G','H','J','K','L',
                        'Z','X','C','V','B','N','M'};
    /*** initialisation function. It is the first Funct to be called ***/
       public void init() {
    // Temp data
          int temp=0,nxx=30;
    // Ini. of fnt , the font size + style used by this applet.
          fnt=new Font("Denis",1,25);
    /*** parsing command parameters ***/
    //      try {
    //DELAY VALUE PARAM
             String param=getParameter("DELAY");
             if (param!=null) {
                temp=Integer.parseInt(param);
                if ((temp>500)&&(temp<6000)) delay=temp;
    //x LEFTMOST coordinate
             param=getParameter("X");
             if (param!=null) {
                temp=Integer.parseInt(param);
                nxx=temp;
    //Base String parameter
             param=getParameter("STRING");
             if ((param!=null)&&(param.length()<15)) {
                str[0]=param;
    //      } catch (ParseException e) { showParseError(e); }
    // Allocating mem for _tree + initialize it .
          _tree=new s_tree(str[0],fnt);
    // Override xx (left_bound) by the caller's or the default value
          _tree.xx=nxx;
    /*** "animation loop is controled here" ***/
       public void run() {
         while(true) {
             try {
    //delay the process for time==delay
                Thread.sleep(delay);
             } catch (InterruptedException e) {}
    //controls animation loop
          repaint();
    /*** override APPLET's paint function ***/
       public void paint (Graphics g) {
    //Output graphics
          update(g);
    /*** Updates the graphics ***/
       public void update (Graphics g) {
    // Set font
          if (g.getFont()!=fnt) g.setFont(fnt);
          if ((userPause==false)&&(resumed==false)) // Is the applet paused ?
             g.clearRect(0,0,1024,768); //clears the screen
             if (_tree==null) {     // if tree is not initialised
                init();
                //_tree.show(g);
             } else {
                if (mode==3) {      // if graphics output mode is 3
                   if (nd!=null) nd._to_rd(false);
                   nd=_tree.step_compact(nd);  //compacts the tree one step further
                   if (nd==null)  // if tree is totally compacted ...
                      mode=4;   //change the ani. mode to 4 (don't call compact)
                   else
                      nd._to_rd(true);  //colors the next node to compact in red
    // Draw the "titleviewport's" comment
             g.setColor(bl);
             g.drawString(str[mode],10,15);
             _tree.show(g);     //show tree
          } else {
             g.clearRect(0,0,200,25);  //clears the "titleviewport to update it"
             g.setColor(rd);
             if (resumed==true){
                resumed=false;
                g.drawString(str[2],10,15);
             else g.drawString(str[1],10,15);
    /*** restart the animation process ***/
       public void start() {
          main=new Thread(this);
          main.start();
    /*** stops the animation ***/
       public void stop() {
          main.stop();
          main=null;
    /*** Handles the user's events (mouse , kbd , ... ***/
       public boolean handleEvent(Event evt) {
          if (evt.id==Event.MOUSE_DOWN) { //if mouse button have been pushed ...
                if (main!=null && main.isAlive()) {
                   if (userPause) {
                      main.start();
                      resumed=true;
                   } else {
                      main.stop();
                   userPause= !userPause;
                } else {
                   main= new Thread(this);
                   main.start();
                   userPause=false;
                   resumed=true;
                repaint();
             return true;
          } else {
             return super.handleEvent(evt);
    /*** Linked List of node(s) ***/
    class nodelist{
       nodelist next=null;
       node ptr=null;
       public void nodelist(){};
    /*** node of a structure tree ***/
    class node {
    // Relatives
       public nodelist children=null;
       public node parent=null;
    // variables
       public int maxchild=12,childnum=0,level=0;
       public int center[]={0,0};
       public int xlen=20,ylen=10,vspace=15,hspace=8;
       public int x[]={0,0};
       public boolean _ishidden=false;
       private Color bk=Color.black,wh=Color.white,rd=Color.red;
    // Node==red toggle variable
       public boolean to_rd=false;
    // node's text
       public String label=null;
    /*** initialisation of the node ***/
       public node(int nx,int ny,int nxl,int nyl,node nparent,int nlevel,String nstr){
          x[0]=nx; x[1]=ny;
          xlen=nxl; ylen=nyl;
          parent=nparent;
          level=nlevel;
          label=new String(nstr);
          children=new nodelist();
    /*** destroys the node ***/
       public void destruct() {
    // NOTE : not like C++ destructors . Do not confuse .
          delete_subtree();
          children=null;
          parent=null;
          bk=wh=rd=null;
          label=null;
    /*** Node to red toggle switch ***/
       public void _to_rd(boolean b) {to_rd=b;};
    /*** Adds a child to this node ***/
       public void add_child(int nx,int ny,int nxl,int nyl,node nparent,int nlevel,
                                String nstr) {
          if (childnum<maxchild) {    // if 'legal' space left ...
             if (children==null) {    // if no nodelist attached ...
                children=new nodelist(); //init. children
                children.ptr=new node(nx,ny,nxl,nyl,nparent,nlevel,nstr); //create node
                childnum++;
             } else {
                nodelist dummy=children;
    // search for the last nodelist
                while (dummy.next!=null) dummy=dummy.next;
                dummy.next=new nodelist(); //adds a nodelist
                dummy=dummy.next;
                dummy.ptr=new node(nx,ny,nxl,nyl,nparent,nlevel,nstr); //create child
                childnum++;
    // Tree needs to be realigned
    /*** adds a child and returns its address ***/
       public node add_child_ret(int nx,int ny,int nxl,int nyl,node nparent,int nlevel,
                                String nstr) {
          if (childnum<maxchild) {
             if (children==null) {
                children=new nodelist();
                children.ptr=new node(nx,ny,nxl,nyl,nparent,nlevel,nstr);
                childnum++;
                return(children.ptr);
             } else {
                nodelist dummy=children;
    // search for the last child
                while (dummy.next!=null) dummy=dummy.next;
                dummy.next=new nodelist();
                dummy=dummy.next;
                dummy.ptr=new node(nx,ny,nxl,nyl,nparent,nlevel,nstr);
                childnum++;
                return(dummy.ptr);
        return(null);
    // Tree needs to be realigned
    /*** adds the node nchild as a new children ***/
       public void add_child(node nchild) {
          nodelist dummy=null;
          dummy=children;
          if (childnum<maxchild) {
             if (children==null) {
                children=new nodelist();
                children.ptr=nchild;
                childnum++;
             } else {
                while (dummy.next!=null) dummy=dummy.next;
                dummy.next=new nodelist();
                dummy=dummy.next;
                dummy.ptr=nchild;
                childnum++;
    //Tree needs to restructured.
    /*** deletes all childrens ***/
       public void delete_subtree() {
          while (childnum>0 && children!=null) { //while child exists , kill it
             if (children.ptr!=null) {
                children.ptr.destruct();
                children.ptr=null;
                children=children.next;
             } else children=null;
             childnum--;
    /*** moves this node and its children horizontally ***/
       public void move_tree(int nx) {
          nodelist dummy=children;
          x[0]+=nx;
          while (childnum>0 && dummy!=null) {
             if (dummy.ptr!=null) {
                dummy.ptr.move_tree(nx);
                dummy=dummy.next;
    /*** removes the node from the tree (do not preserve order of ordered tree ) ***/
       public void remove_node() {
          nodelist dummy=children;
          while(dummy!=null) {
             if (dummy.ptr!=null){
                parent.add_child(dummy.ptr);
             dummy=dummy.next;
          children=null;
    //could call restructure tree here .
    //don't forget to change the node's levels !!!
    /*** show all nodes ***/
       public void show_all(Graphics g) {
          if (_ishidden==false) { //if not hidden
             if (children!=null) {  //if child exist
                nodelist dummy=children; //temp var.
                while(dummy!=null) { //while there is a child...
                   if (dummy.ptr!=null)
                      dummy.ptr.show_all(g);
                   dummy=dummy.next;
             show_node(g);
    /*** show nodes in preorder ***/
       public int preorder_show(Graphics g,int label){
          if (_ishidden==false) {
             show_node(g/*,label++*/);
             if (children!=null) {
                nodelist dummy=children;
                while(dummy!=null) {
                   if (dummy.ptr!=null) label=dummy.ptr.preorder_show(g,label);
                   dummy=dummy.next;
          return(label);
    /** show nodes in postorder ***/
       public int postorder_show(Graphics g,int label){
          if (_ishidden==false) {
             if (children!=null) {
                nodelist dummy=children;
                while(dummy!=null) {
                   if (dummy.ptr!=null) label=dummy.ptr.postorder_show(g,label);
                   dummy=dummy.next;
             show_node(g/*,label++*/);
          return(label);
    /*** show nodes in inorder ***/
       public int inorder_show(Graphics g,int label){
          if (_ishidden==false) {
             if (children!=null) {
                nodelist dummy=children;
                if (dummy.ptr!=null) label=dummy.ptr.inorder_show(g,label);
                dummy=dummy.next;
                show_node(g/*,label++*/);
                while(dummy!=null) {
                   if (dummy.ptr!=null) label=dummy.ptr.inorder_show(g,label);
                   dummy=dummy.next;
             } else show_node(g/*,label++*/);
          return(label);
    /*** Restructure the coordinates of all nodes ***/
       public int align(int min,Font fnt,int lev,Graphics g){
          int i=min; //left bound
          FontMetrics fntm=g.getFontMetrics(fnt); //used to know the text size
          level=lev;
    // node x and y radius are computed here
          xlen=4+(int)(fntm.stringWidth(label)/2);
          ylen=4+(int)(fntm.getHeight()/2);
          if (children!=null) {      //if child present ...
             nodelist dummy=children;
             while(dummy!=null) {
                if (dummy.ptr!=null) i=dummy.ptr.align(i,fnt,lev+1,g); //align them
                   dummy=dummy.next;
          x[0]=min+(int)((i-min)/2); //could be underflow so will be checked
          x[1]=lev*(vspace+(ylen*2))+26;
    // overflow should happen only when the parent node is larger than its children
          if ((x[0]-xlen)<min) { //check uf underflow occurs.
             move_tree(min+xlen-x[0]+1);
             i=x[0]+xlen+5;
          if (childnum==0) x[0]+=2;
        return(i);
    /*** returns the child following nd ***/
    /*** if nd==null -> return 1st child ***/
    /***  if nd==last children -> return null***/
       public node next_child(node nd) {
          nodelist dummy=null;
          if (children==null) return(null);
          if (nd==null) return(children.ptr);
          dummy=children;
          while (dummy.ptr!=nd) {
             if (dummy.next!=null)
                dummy=dummy.next;
             else
                return(null);
          dummy=dummy.next;
          if (dummy!=null) return(dummy.ptr);
             else return(null);
    /*** returns child with first letter==nh ***/
       public node get_childd(char ch) {
          nodelist dummy=null;
          dummy=children;
          while (dummy!=null) {
             if (dummy.ptr!=null) {
                if (dummy.ptr.label.charAt(0)==ch)
                   return(dummy.ptr);
             dummy=dummy.next;
        return(null);
    /*** returns the nodelist containing nd ***/
       public nodelist get_child(node nd) {
          nodelist dummy=children;
          while (dummy!=null) {
             if (dummy.ptr==nd) return(dummy);
             dummy=dummy.next;
        return(null);
    /*** outputs the node to Screen ***/
       public void show_node(Graphics g) {
          if (_ishidden==false) {
             if (level>0) {  //if it is not a root then draw link-line
                g.setColor(bk);
                g.drawLine(x[0],x[1]-ylen,parent.x[0],parent.x[1]+parent.ylen); //from this node to parent node
             if (to_rd==false)
                g.setColor(wh);
             else
                g.setColor(rd);
             g.fillOval(x[0]-xlen,x[1]-ylen,xlen*2,ylen*2); //draws an oval
             g.setColor(bk);
             g.drawString(label,x[0]-xlen+4,x[1]+ylen-12);  //output the text
    /*** class which uses nodes to create a SUFFIX TREE ***/
    class s_tree {
       node root=null;    // root node.
       String str=null;   // 'search' string
       Font fnt=null;     // font type
       int xx=30;         // left limit for graphics
    /*** initialize a SUFFIX TREE with string==nstr and Font==nfnt ***/
       public s_tree(String nstr,Font nfnt) {
          str=new String(nstr);
          fnt=nfnt;
          create();
    /*** uninitialize the structure **/
       public void destruct() {
          root.destruct();
          str=null;
          fnt=null;
    /*** show the tree ***/
       public void show(Graphics g) {
          root.align(xx,fnt,0,g);   // restructure node's coordinates
          root.show_all(g); //show tree
    /*** creates a tree structure from String=str ***/
       public void create() {
          node dummy=null;
          root=new node(0,0,0,0,dummy,0," "); //create root
          root.parent=null; //just to make sure ...
          for (int i=0;i<str.length();i++) {
    // Create subtree of root in the following way :
    //    create subtree ("ASDF$");
    //        "     "    ("aSDF$");
    //       "    "      ("asDF$"); ...
    // where : the UPPERCASE letters is the part of the string sent to insert_string
             insert_string(str.substring(i));
          //root.align(0,fnt,0); //align root now ?
    /*** creates a subtree of ROOT with String=nstr ***/
       public void insert_string(String nstr) {
          node dummy2=null,dummy=null;
          int i=0;
          dummy=root;
          dummy2=root;
    // As long as a children of dummy2 have the letter nstr[i] , dummy==thischildren
    // It is used to make sure that a node does not have two children with the
    // same letter
          while (dummy2!=null) {
             dummy2=dummy2.get_childd(nstr.charAt(i));
             if (dummy2!=null) {
                i++;
                dummy=dummy2;
    //create the nodes for the rest of the string
          for(;i<nstr.length();i++) {
             if (dummy!=null) dummy=dummy.add_child_ret(0,0,0,0,dummy,1,nstr.substring(i,i+1));
    // Compacts the tree node by node and returns the next node to compact
    // if node==null , compacts the first node ...
    //Works in POST-ORDER
       public node step_compact(node nd) {
          node dummy=nd,dummy2=null;
          nodelist ndlst=null;
    // GOES TO THE LOWER LEFT CHILDREN
          if (nd==null) { //first call !
             dummy=root;
             while(dummy.children!=null) {
                if (dummy.children.ptr==null)
                   dummy.children=dummy.children.next;
                else
                   dummy=dummy.children.ptr;
    //*** tries to find a 'compactable' node ***
    //*** It uses the POST-ORDER method      ***
    // if this node is not the last children then try to find next compactable node
    // in the next children.
          if (dummy.parent.childnum!=1) dummy=next_chain(dummy);
          if (dummy==null) return(null); //fully optimized
    //remove parent node.
    /*** THIS IS WHERE COMPACTING TAKES PLACE  **/
          dummy2=dummy.parent.parent;
          ndlst=dummy2.get_child(dummy.parent);
          if (ndlst==null) return(null); //we've got a beeeeg problem if this happens ...
    //*** merges the parent string with this one and delete parent .
          dummy.label=dummy.parent.label.concat(dummy.label);
          ndlst.ptr=dummy;
          //delete parent .
          dummy.parent=null;
          dummy.parent=dummy2;
    //      root.align(0,fnt,0);
        return(dummy);
    /*** finds the next chain in the tree (i.e. the next compactable node) ***/
       public node next_chain(node nd){
          node dummy=null;
          if (nd.parent==null) return(null); //finished ! This is the root
          if (nd.parent.childnum==1) return(nd); //can be optimized
    // finds the nd.parent's child following nd
          dummy=nd.parent.next_child(nd);
          if (dummy==null)  // if OLD_nd==last child
             return(next_chain(nd.parent));      //tries to find a chain upwards
          else {
                 // OLD_nd was not the last child . nd==OLD_nd's next brother
    // GOES TO THE LOWER LEFT most child of nd's subtree.
             while(dummy.children!=null) {
                if (dummy.children.ptr==null)
                   dummy.children=dummy.children.next;
                else
                   dummy=dummy.children.ptr;
             return(next_chain(dummy)); // returns the next compactable node
    };

    First, show me the rupees! Show me the rupees!

  • How do I convert my GUI java app to be an applet or display it on a webpage

    I have created a loan calculator program in netbeans, I got the application to run fine but now I want to add it into a html page.
    I'm just looking for a place to start, I just don't know where to go from here, I want to know if I can actually convert my app with a few changes to an applet or if any one can point me to a forum of similar interest or tutorials that explain what I'm looking for.
    I don't even know what i'm looking for except i want this program to run on a webpage.
    Or is there a way to run my .jar file on a webpage??
    My teacher has not taught us anything on this matter except the below code suggestions on converting and my program is more extensive than her examples for converting. This is what she briefly described on this subject.
    1.To convert an application to an applet the main differences are: import java.awt.Graphics; import javax.swing.JApplet; import javax.swing.JOptionPane;
         Extend JApplet Replace main with public void init() method
    Output with public void paint( Graphics g ) method
    2. Remove calls to setSize, setTitle, pack, and any window listener calls, e.g., setDefaultCloseOperation. Compile the program---if something doesn't compile just comment it out for now.
    3. Create a simple web page with the following body.
    <applet CODE="__________.class" WIDTH="300" HEIGHT="300"
    archive="http://www.cs.duke.edu/courses/fall01/cps108/resources/joggle.jar">
    Your browser does not support applets </applet>
    I understand those steps for a simple program like hello world but not my current app
    Heres my code on the 2 extend off my first GUI of the Loan Application
    public class AnalysisGUI extends GUI {
        /** Creates new form AnalysisGUI */
        public AnalysisGUI(java.awt.Frame parent, boolean modal) {
            super(parent, modal);
            initComponents();
        }//end constructor
        private DecimalFormat currency = new DecimalFormat("0.00");
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
            analysisjButton = new javax.swing.JButton();
            jScrollPane1 = new javax.swing.JScrollPane();
            writejTextArea = new javax.swing.JTextArea();
            clearTextAreajButton = new javax.swing.JButton();
            setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
            analysisjButton.setText("Analysis");
            analysisjButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    analysisjButtonActionPerformed(evt);
            writejTextArea.setColumns(20);
            writejTextArea.setRows(5);
            jScrollPane1.setViewportView(writejTextArea);
            clearTextAreajButton.setText("Clear Analysis Output");
            clearTextAreajButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    clearTextAreajButtonActionPerformed(evt);
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(analysisjButton)
                        .addComponent(clearTextAreajButton))
                    .addGap(18, 18, 18)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 433, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(86, 86, 86))
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap(306, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(analysisjButton)
                            .addGap(84, 84, 84)
                            .addComponent(clearTextAreajButton)
                            .addGap(113, 113, 113))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 263, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(22, 22, 22))))
            java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
            setBounds((screenSize.width-700)/2, (screenSize.height-627)/2, 700, 627);
        }// </editor-fold>
        private void analysisjButtonActionPerformed(java.awt.event.ActionEvent evt) {                                               
            // TODO add your handling code here:   
            //importing values for FOR loop of 13 pyaments a years
            ir13 = super.rate;
            balance13 = super.balance;
            time13 = super.time;
            payment13 = MortgageCalculator.CalculatePayment(ir13, balance13, time13, PayperYear13);           
            interest13 = round((balance13 * (ir13/PayperYear13)));                   
            principle13 = round(payment13 - interest13);
            //set up for 12 pyaments a year
            balance = super.balance;          
            ir = super.rate;
            time = super.time;         
            payment = super.payment;
            interest = round((balance * (ir/PayperYear12)));
            principle = round(payment - interest);
            //set up for 24 payments a year   
            balance24 = super.balance;          
            ir24 = super.rate;
            time24 = super.time;         
            payment24 = super.payment/2;
            interest24 = round((balance24 * (ir/PayperYear24)));
            principle24 = round(payment24 - interest24);
            //set up for 26 payemnts a years
            ir26 = super.rate;
            balance26 = super.balance;
            time26 = super.time;
            payment26 = MortgageCalculator.CalculatePayment(ir26, balance26, time26, PayperYear26);           
            interest26 = round((balance26 * (ir26/PayperYear26)));                   
            principle26 = round(payment26 - interest26);
         double totalPrinciple = 0;              //set to zero
         double totalInterest = 0;          //set to zero       
         for( int n = 0; n < time; n++)     //check Year of Loan
                totalPrinciple = 0;          //reset to zero for totaling Year n totals
                totalInterest = 0;          //reset to zero for totaling Year n totals
                writejTextArea.append("-----Based on 12 Payments Per Year-----\n");
                writejTextArea.append("          "+"          "+"Principle" + "    " +
                    "Interest"+ "    "+
                    "Balance"+"\n");            
                //loops through the monthly payments
                for(int i = 1; i <= PayperYear12; i++ )
                //Calculate applied amounts for chart to be printed
                interest = round((balance * ir)/PayperYear12);
                principle = round(payment - interest);
                balance = round(balance - principle);
                //total year end amounts
                totalPrinciple = totalPrinciple + principle;
                totalInterest = totalInterest + interest;
                writejTextArea.append("Payment " + i + " $" + currency.format(principle) + "     " +
                    currency.format(interest) + "      $" +
                    currency.format(balance)+"\n");     
                }//end for 12 payments per year
                //print 12 payments Totals          
                int yr = n + 1;
                writejTextArea.append("\n---Year " + yr + " Totals Based on 12 Payments Per Year---");
                writejTextArea.append("\nYear Total Principle: $" + currency.format(totalPrinciple));
                writejTextArea.append("\nYear Total Interest: $" + currency.format(totalInterest));
                writejTextArea.append("\nRemaining Balance: $" + currency.format(balance)+"\n");
                writejTextArea.append("\n-------------------------------------------------------\n");     
                //Start 13 PAYMENTS A YEAR TABLE
                double totalPrinciple13 = 0;          //reset to zero for totaling Year n totals
                double totalInterest13 = 0;          //reset to zero for totaling Year n totals
                writejTextArea.append("-----Based on 13 Payments Per Year-----\n");   
                writejTextArea.append("          "+"          "+"Principle" + "    " +
                    "Interest"+ "    "+
                    "Balance"+"\n");            
                //loops through the monthly 13 payments           
                for(int j = 1; j <= PayperYear13; j++ )
                //Calculate applied amounts for chart to be printed
                interest13 = round((balance13 * ir13)/PayperYear13);
                principle13 = round(payment13 - interest13);
                balance13 = round(balance13 - principle13);
                //total year end amounts
                totalPrinciple13 = totalPrinciple13 + principle13;
                totalInterest13 = totalInterest13 + interest13;
                //System.out.printf("\n%-10s %-10s %-10s %-10s %-10s", n + 1 , i + 1,Principle, Interest, Balance);
                //System.out.printf("\n%-10s %-10s %-10.2f %-10.2f %-10.2f", n + 1 , i + 1,round(principle), round(interest), balance);
                writejTextArea.append("Payment " + j + " $" + currency.format(principle13) + "     " +
                    currency.format(interest13) + "      $" +
                    currency.format(balance13)+"\n");         
                }//end for 13 payments per year
                //Print totals for 13 payments a year          
                yr = n + 1;
                writejTextArea.append("\n---Year " + yr + " Totals Based on 13 Payments Per Year---");
                writejTextArea.append("\nYear Total Principle: $" + currency.format(totalPrinciple13));
                writejTextArea.append("\nYear Total Interest: $" + currency.format(totalInterest13));
                writejTextArea.append("\nRemaining Balance: $" + currency.format(balance13)+"\n");
                writejTextArea.append("\n-------------------------------------------------------\n");             
                //Start 24 PAYMENTS A YEAR TABLE
                double totalPrinciple24 = 0;          //reset to zero for totaling Year n totals
                double totalInterest24 = 0;          //reset to zero for totaling Year n totals
                writejTextArea.append("-----Based on 24 Payments Per Year-----\n");
                writejTextArea.append("          "+"          "+"Principle" + "    " +
                    "Interest"+ "    "+
                    "Balance"+"\n");            
                //loops through the monthly payments
                for(int i = 1; i <= PayperYear24; i++ )
                //Calculate applied amounts for chart to be printed
                interest24 = round((balance24 * ir24)/PayperYear24);
                principle24 = round(payment24 - interest24);
                balance24 = round(balance24 - principle24);
                //total year end amounts
                totalPrinciple = totalPrinciple + principle24;
                totalInterest = totalInterest + interest24;
                writejTextArea.append("Payment " + i + " $" + currency.format(principle24) + "     " +
                    currency.format(interest24) + "      $" +
                    currency.format(balance24)+"\n"); 
                }//end for 24 payments per year
                //print 24 payments Totals
                yr = n +1;
                writejTextArea.append("\n---Year " + yr + " Totals Based on 24 Payments Per Year---");
                writejTextArea.append("\nYear Total Principle: $" + currency.format(totalPrinciple24));
                writejTextArea.append("\nYear Total Interest: $" + currency.format(totalInterest24));
                writejTextArea.append("\nRemaining Balance: $" + currency.format(balance24)+"\n");
                writejTextArea.append("\n-------------------------------------------------------\n");                        
                //Start 26 PAYMENTS A YEAR TABLE
                double totalPrinciple26 = 0;//reset to zero for totaling Year n totals
                double totalInterest26 = 0;     //reset to zero for totaling Year n totals
                writejTextArea.append("------Based on 26 Payments Per Year-----\n");
                writejTextArea.append("          "+"          "+"Principle" + "    " +
                    "Interest"+ "    "+
                    "Balance"+"\n");            
                //loops through the monthly payments 26 times
                for(int i = 1; i <= PayperYear26; i++ )
                //Calculate applied amounts for chart to be printed
                interest26 = round((balance26 * ir24)/PayperYear26);
                principle26 = round(payment26 - interest26);
                balance26 = round(balance26 - principle26);
                totalPrinciple = totalPrinciple + principle26;
                totalInterest = totalInterest + interest26;
                writejTextArea.append("Payment " + i + "  $" + currency.format(principle26) + "     " +
                    currency.format(interest26) + "      $" +
                    currency.format(balance26)+"\n");
                }//end for 26 payments per year           
                yr = n + 1;
                //prints 26 payments yearly totals
                writejTextArea.append("\n---Year " + yr + " Totals Based on 26 Payments Per Year---");
                writejTextArea.append("\nYear Total Principle: $" + currency.format(totalPrinciple26));
                writejTextArea.append("\nYear Total Interest: $" + currency.format(totalInterest26));
                writejTextArea.append("\nRemaining Balance: $" + currency.format(balance26)+"\n");
                writejTextArea.append("\n-------------------------------------------------------\n");                
            }//end for years of the loan
        private void clearTextAreajButtonActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
            //clear analysis field
            writejTextArea.setText("");
        public static double round(double r)//round to cents method
              return Math.ceil(r*100)/100;
         }//end round  
        /**HI micha what a long progam
         * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    AnalysisGUI dialog = new AnalysisGUI(new javax.swing.JFrame(), true);
                    dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                        public void windowClosing(java.awt.event.WindowEvent e) {
                            System.exit(0);
                    dialog.setVisible(true);
            });//end announymous
        }//end main mehtod
        //12 year declared varialbes
        //private double balance;   
        private double principle;
        private double ir;
        private double interest;
        private double PayperYear12 = 12;
        //Variables for 13 payments a years
        private int PayperYear13 = 13;
        private double balance13;
        private double principle13;
        private double ir13;
        private double interest13;
        private double payment13;
        private double time13;
        //Varialbes for 24 payments a year
        private int PayperYear24 = 24;
        private double balance24;
        private double principle24;
        private double ir24;
        private double interest24;
        private double payment24;
        private double time24;
        //Varialbes for 24 payments a year
        private int PayperYear26 = 26;
        private double balance26;
        private double principle26;
        private double ir26;
        private double interest26;
        private double payment26;
        private double time26;
        // Variables declaration - do not modify
        private javax.swing.JButton analysisjButton;
        private javax.swing.JButton clearTextAreajButton;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JTextArea writejTextArea;

    Your original program extends "GUI" which appears to extend JFrame (correct me if I'm wrong). If so, the first thing you should do would be to re-write this so that it extends JPanel which shouldn't be that hard to do (at least it's not hard to do if you know a little Swing -- but I worry about someone coming into this from the netbeans-generated code world). Purists will tell you to not even extend this, to have your main GUI class hold an instance of JPanel instead, and this would work fine too, as long as one way or another, the main GUI program can produce your application displayed on a JPanel on demand.
    If you've done this correctly, then using your JPanel in a JFrame is trivial: in a main method create a JFrame, and then simply add your JPanel to the JFrame's contentPane and display it. Likewise using your JPanel in a JApplet is just as trivial as you'd do essentially the same thing: add your JPanel to the JApplet's contentPane, but this time do it in the JApplet's init method.

  • How can i convert java application of bibeans to java applet?

    Hi Bibeans PMTeam,
    Bibeans provide two type client:java application and web client(JSP/Servlet),because web client's function is weaker than java app,so we want to convert java app to java applet,thus,we can embed java applet into web browser(our system framework is in web browser).
    That is,we want one applet client that commution with a server side service(can by socket,just like oracle 9i form service)that provide the data that applet need,or the applet connect to olap server and bibeans catalog server by socket(this need security authentication if olap server,bibeans catalog,web server is not in one machine).
    so we need you provide whole resolve scheme,thanks a lot,if this answer is not clarity,please connect:[email protected],thanks a lot!

    hi tomsong
    well, in my experience 20mb are quite large for an applet. also take into account that you need a certain jvm that supports this type of application (my guess is that internet explorers native vm isnt an option)
    i personally would tend to deliver the functionality via java webstart (look at the sunsite):so you can centrally manage the software, download it once and opertae an application on your client (i mean an APPLICATION and not an applet)
    regarding 2: well but there is NO bibean service in ias: so you have to open the former mentioned jdbc connection to the olap service from your client
    for the availability: you have to check with the pm team
    in the meantime: what about the following approach: give power users a java application and lightweight or random users a handy html client ?
    regards,
    thomas

  • Converting Swing to Applets

    Hello
    I have a swing GUI and my employer asked me to convert the whole thing into applets. I just wonder if there is a simpler way of doing it. My GUI now contains only basic swing components like JTabbedPane, JTable etc...,
    Thanks.

    There may also be resource and security issues associated with the conversion. On the whole modifying the entry point is fairly simple ... convert to JApplet, make sure you have an init method to replace the main method as your entry point. You will need HTML to start the applet.
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Build a .jar from an applet

    Hi. I have the following code.
    import controller.Application;
    import model.Slideshow;
    import view.MainFrame;
    import java.applet.Applet;
    public class Main extends Applet {
        public void init() {
            Slideshow slideshow = new Slideshow("untitled.xml");
            Application app = new Application(slideshow);
            new MainFrame(app);
    }I can create the .jar file but when I open it a message of "couldn't finde main class" appears... obviously... it's an applet ! how can I create an excecutable file? thanks very much

    Akcents wrote:
    public class Main{
    public static void main(String[] args) {
    Slideshow slideshow = new Slideshow("untitled.xml");
    Application app = new Application(slideshow);
    new MainFrame(app);
    how can I make an executable file with this class????
    This question is quite different from your original question. Is it your intent to convert the application into an applet or are you interested in creating an [executable JAR file|http://java.sun.com/javase/6/docs/technotes/guides/jar/jarGuide.html]? If it's the latter, when bundling your application in a JAR file you'll need to update the [JAR file manifest|http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html] with a Main-Class entry. If it's the former, the following link will be helpful:
    [http://java.sun.com/docs/books/tutorial/deployment/applet/getStarted.html |http://java.sun.com/docs/books/tutorial/deployment/applet/getStarted.html ]

  • How can I open a URL in an applet?

    Hi:
    All I want to do is webcrawl through the pages on a website, and extract some indexing information. Now, I have a java class that does this just fine -- for http sites. Except my site is https, and asks for username and password, which my java class cannot handle.
    So I figured one easy solution would be to simply convert my java application into an applet, and then just pass through the username/password authentication, then run the applet. The problem is, after I've converted my application into an applet, i get the following exception (I was using www.yahoo.com just to test the applet before running it on my https site):
    java.security.AccessControlException: access denied (java.net.SocketPermission www.yahoo.com resolve)
    at java.security.AccessControlContext.checkPermission(Unknown Source)
    at java.security.AccessController.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkConnect(Unknown Source)
    at sun.plugin.net.protocol.http.HttpURLConnection.checkPermission(Unknown Source)
    at sun.plugin.net.protocol.http.HttpURLConnection.connect(Unknown Source)
    at sun.plugin.net.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    at java.net.URL.openStream(Unknown Source)
    at Crawler.robotSafe(OgiCrawler.java:77)
    at Crawler.start(OgiCrawler.java:224)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    What am I leaving out? I've pored through much sample code, including the code on the forums, but my code seems the same (though the code on the forums is usually for applications, not applets.) I know there are other webcrawling java applets... how do they successfully connect to a URL?
    Here is my connection code:
    HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
    System.out.println("Downloading " + url.toString());
    urlConnection.setAllowUserInteraction(false);
    InputStream urlStream = url.openStream();
    I'm very new to Java programming, so if I need to include some applet-specific package, please let me know! Thank you very much for your help!!
    Ogi

    ... So I figured one easy solution would be to simply
    convert my java application into an applet...i dont know the solution for ur problem, but you shouldnt convert ur app into an applet, cuz applet has more restrictions...

  • Reading a data file from an Applet

    ...new to Applet Programming. I have a stand-alone application that converts
    an XML file to a DOM, then to a JTree. I have converted the application to an Applet
    But I can't find the trick to having the applet connect to the XML file.
    This is the line of code which works fine in the stand-alone, but hangs the Applet:
    document = builder.parse( new File( "P6B.Xml" ) );
    How can the applet read data located on the host in the same directory as the class?
    Sounds simple, but somehow can't find a way of doing this.
    One suggested solution (when the file is always needed) I have found browsing
    through this site is to wrap both the File and the Class in a JAR.
    In this instance, how can I parse the file?
    Appreciate any help.

    Give the complete URL of your xml file.

  • Problem signing Applets with sound recording

    I'm working on a project to have live conversation in one to many clients scenario. i have tested the code as a command line app No problem but hell let loose when i converted the code into an applet
    here are the error messages i'm getting
    Exception in startCapture.
    java.security.AccessControlException: access denied (javax.sound.sampled.AudioPe
    rmission record)
    java.security.AccessControlException: access denied (javax.sound.sampled.AudioPe
    rmission record)
            at java.security.AccessControlContext.checkPermission(AccessControlConte
    xt.java:323)
            at java.security.AccessController.checkPermission(AccessController.java:
    546)
            at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
            at com.sun.media.sound.JSSecurityManager.checkRecordPermission(JSSecurit
    yManager.java:56)
            at com.sun.media.sound.DirectAudioDevice$DirectDL.implOpen(DirectAudioDe
    vice.java:412)
            at com.sun.media.sound.AbstractDataLine.open(AbstractDataLine.java:107)
            at com.sun.media.sound.AbstractDataLine.open(AbstractDataLine.java:139)
            at SoundController.startCapture(SoundController.java:57)
            at Client.startCapture(Client.java:28)
            at GuiClient$StartTalkingButton.actionPerformed(GuiClient.java:39)
            at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:19
    95)
            at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.jav
    a:2318)
            at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
    .java:377)
            at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:232
            at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL
    istener.java:236)
            at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:2
    31)
            at java.awt.Component.processMouseEvent(Component.java:5999)
            at javax.swing.JComponent.processMouseEvent(JComponent.java:3240)
            at java.awt.Component.processEvent(Component.java:5764)
            at java.awt.Container.processEvent(Container.java:1984)
            at java.awt.Component.dispatchEventImpl(Component.java:4407)
            at java.awt.Container.dispatchEventImpl(Container.java:2042)
            at java.awt.Component.dispatchEvent(Component.java:4237)
            at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4248
            at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3912)
            at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3842)
            at java.awt.Container.dispatchEventImpl(Container.java:2028)
            at java.awt.Component.dispatchEvent(Component.java:4237)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:600)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
    ad.java:273)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
    java:183)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
    ad.java:173)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
    Exception when testing startCapture:access denied (javax.sound.sampled.AudioPerm
    ission record)I have created a policy file
    keystore "file:/C:/Conference/susanstore", "JKS";
    grant codeBase "file: /C:/conference" {
      permission java.security.AllPermission;
    i 've ran it still having the same error
    I 'll gladly appreciate if you could help me on it

    Have you tried signing your applet?
    to sign an applet , you can approach 3d parties like Thawte or you can sign them yourself.
    Package your class file into a .jar, Create your own keystore, sign the jar file using this keystore.
    Then you will be able to open it in a browser.

  • Swing applet view problem in IE

    Hi,
    I am new to Java and have to develop a web enabled tool where the servlets in my Solaris-Tomcat web server is manipulating with data in an oracle database. The client code is on Swing Applet, which is to be opened in Internet Explorer 5.5 from Windows NT platform.
    In view of this, I have written a small swing applet and it is not opening in IE. I heard that I need to use HTML converter to run Swing applets in IE. But, Is it enough to download the HTML converter for Solaris and install it in the server and convert the html pages where <applet> tag is included? Or , do I need to install the HTML converter for windows to all the client machines?
    Please help. This is very urgent.
    Thanks in adance.

    You can use this html code :
    <html>
         <body>
              <OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" WIDTH = 695 HEIGHT = 525 codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,3,0,0">
                   <PARAM NAME = CODE VALUE = MyApplet >
                   <PARAM NAME = CODEBASE VALUE = "." >
                   <PARAM NAME = ARCHIVE VALUE = "MyApplet.jar" >
                   <PARAM NAME="type" VALUE="application/x-java-applet;version=1.3">
                   <PARAM NAME="scriptable" VALUE="false">
              </OBJECT>
         </body>
    </html>
    replacing only the dimension, the code value and removing or modifying archive value.
    Don't modiy the classid. This code indicates to the browser to use the Sun Java VM instead of its own vm.
    I hope this helps,
    Denis

  • Netbeans nightmare Converting a JFrame  class to a JApplet Class

    Hello im not exactly new to java but im having problems getting my applets to work when i try other peoples example applets they always work but mine never seem to. here is what i am doing i wrote a card game in VB6 long story short i completely rewrote it in java because only ie supports ActiveX.
    It works awesome as a stand alone App whilst in Jframe and with a main() sub.
    I tried about 15 tutorials on how to convert a jframe to a applet with no success i always got errors and applet never loaded in browser.
    then i found these tips on how to do it "really easy" of course when my applet loads and im not sure it even really does i get nothing but a grey box i never seem my components a bunch of jlabels with icons loaded that look like card images it all looks great in the design tab of NetBeans. I never see any of the controls in browser. These are the links to the two tutorials that spawned my trying this. http://forums.java.net/jive/thread.jspa?threadID=57965&tstart=0 http://forums.java.net/jive/thread.jspa?threadID=57965&tstart=0
    well to quote this guy it feels like its going to take 100 years to figure this out google has a million links to junk when i try searches and sun has no great help for searching either on their documentation. my program is rediculously low tech and i cant seem to get it to do anything or work at all as an applet.
    my class looks like this: i removed all the constructor code as it was making post too long my applet shows up normal in the preview window of Netbenas but just a grey square of browser not sure whats wrong please someone help me.. Thanks You
    import java.util.Random;
    public class AcesKingsJApplet extends javax.swing.JApplet {
    /** Initializes the applet AcesKingsJApplet */
    public void init() {
    try {
    java.awt.EventQueue.invokeAndWait(new Runnable() {
    public void run() {
    initComponents();
    System.out.println("InitCOmpleted");
    // NewGame(1);
    } catch (Exception ex) {
    ex.printStackTrace();
    public void TableCardClick(int arg1){
    public void DiscardPileClick(int arg1){
    public void PerformUndoAction(){
    public void NewGame(int arg1){
    //new game code here
    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel31;
    private javax.swing.JLabel jLabel32;
    private javax.swing.JLabel jLabel33;
    private javax.swing.JLabel jLabel34;
    private javax.swing.JLabel jLabel35;
    private javax.swing.JLabel jLabel36;
    private javax.swing.JLabel jLabel37;
    private javax.swing.JLabel jLabel38;
    private javax.swing.JLabel jLabel39;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel40;
    private javax.swing.JLabel jLabel41;
    private javax.swing.JLabel jLabel42;
    private javax.swing.JLabel jLabel43;
    private javax.swing.JLabel jLabel44;
    private javax.swing.JLabel jLabel45;
    private javax.swing.JLabel jLabel46;
    private javax.swing.JLabel jLabel47;
    private javax.swing.JLabel jLabel48;
    private javax.swing.JLabel jLabel49;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel50;
    private javax.swing.JLabel jLabel51;
    private javax.swing.JLabel jLabel52;
    private javax.swing.JLabel jLabel53;
    private javax.swing.JLabel jLabel54;
    private javax.swing.JLabel jLabel55;
    private javax.swing.JLabel jLabel56;
    private javax.swing.JLabel jLabel58;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel60;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    // End of variables declaration
    int tableCardIndex = 99; //array only cause it has to be or game fails
    int discardPileIndex = 99;
    int[] cardDeckArray = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54};
    int[] cardDeckArrayPlayed = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
    //int[] precheckarg1;
    boolean GoAheadWithPlay;
    int gameUndoCount;
    int gamePlayCount;
    int gameCurrentRound = 1;
    int cardPointValue;
    int discardCardValue;
    int tableCardValue;
    int tableCardsRemaining = 35;
    int discardPileCards;
    int currentDiscardPileCard;
    int playerScore;
    // loss checking variables
    int badPlaysCount = 0;
    // variables for undo related activity below
    int[] undogamePlayCount = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    int[] undodiscardPileCards = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    int[] undocurrentDiscardPileCard = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    int[] undoMethod = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    int[] undoTableCard ={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    int[] undoDiscardCard ={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    //end undo variable collection
    }

    You shouldn't start a new thread when you've already created a recent one with the exact same subject matter:
    [http://forums.sun.com/thread.jspa?threadID=5447497|http://forums.sun.com/thread.jspa?threadID=5447497]
    And my advice in the previous thread still stands. Put your program in a JPanel so it's environment-agnostic, then create two wrappers for standalone apps and applets.
    (or just use Java Web Start)
    Also your program has all sorts of other problems. This is terrible coding:
    private javax.swing.JLabel jLabel37;If you need lots of labels that all have the same meaning, put them in a collection. Give things meaningful names. etc.
    If that code was generated by Netbeans....then this is an example why you shouldn't use code generation tools...

  • Scrollpane to applet size urgent!!!

    Hi,
    I have 2 issues in my project.
    1. I want JScrollPane container in my applet to take the size of applet.
    2. I want applet to take the size of browser.
    Applet might be run on different computers with different resolutions. So, I want the applet to adjust its size to the browser and the scrollpane to adjust its size to the size of applet.
    Please help me in resolving this problem. as my project is looking ugly without the above features.
    Thanks in advance.
    with regards,
    Dawood.

    851102 wrote:
    I have 2 days to complete the applet.That is not our concern.
    I have an attendance system application.Is that even relevant?
    I've heard that its not a big-complicated job to convert it to an applet.Heard where? Not that it is not correct - but you should probably ask the person who told you for more information.
    But I dunno how to do it.I just need a few guidelines.Google ( [url http://www.google.com/search?q=convert+swing+application+to+a+applet]convert swing application to a applet ).

  • JAXP in Applet ?

    Hi !
    I have a small problem (yep, I am pretty new to Java so the possibility that I am doing somethere very stupid is great).
    A have Java class that use JAXP to parse an xml file and this works great, but when I try to convert my class to an applet it no longer works, it compiles ok, but when I run it I get:
    java.lang.NoClassDefFoundError: org/xml/sax/SAXException
    at java.lang.Class.newInstance0(Native Method)
    at java.lang.Class.newInstance(Class.java:237)
    at sun.applet.AppletPanel.createApplet(AppletPanel.java:579)
    at sun.applet.AppletPanel.runLoader(AppletPanel.java:515)
    at sun.applet.AppletPanel.run(AppletPanel.java:293)
    at java.lang.Thread.run(Thread.java:484)
    I have set the classpath to crimson.jar and jaxp.jar just as I did with the non-applet version, but it still does not work:
    Like this:
    set CLASSPATH=v:/blabla/lib/crimson.jar;V:/blabla/lib/jaxp.jar;.
    appletviewer test.html
    I also tried to run the applet in Tomcat, but I get the same error.
    Any ideas ?
    Mikael

    I have searched the forum for any help on this, and I did find a few other posts that have the same problem as me, but so far I have not been able to find a solution to it (I am using JAXP 1.1, 1.0 had a problem with Applets).
    Mikael

Maybe you are looking for

  • Query Help with Parent, Child, Child's Child

    Hi all, Need some help with a query.  I'm trying to create a stored procedure that is sort of like a Customer, Order, Order, Details.  In my situation the tables are different but nevertheless, I want to grab all the fields from the  Parent, Child, a

  • Non stock material and quality inspection

    Hi All, We are using a material short text for a material procurement. System allows me to post the goods receipt with mvt type 101 into quality inspection stock. However once posted to QI stock, we can not enter 321 movement with reference to GR doc

  • How to refactor managed bean

    Disclaimer: I am very new to ADF. I have a fragment that uses a pageFlow scoped managed bean. Everything works fine but now I have to extract a piece of that fragment and use it into another fragment. I would like to extract all parts related to that

  • Optimum HD setup for Server on Mac Pro

    We are currently running Tiger Server on a Dual 2 G5 and are preparing to migrate to Leopard Server on a new 8-core Mac Pro (I wanted an Xserve, but given the tight purse strings lately, will happily settle for the Mac Pro!!). I will be doing a clean

  • BUDGET PLAN VALUE AND DISTRIBUTABLE VALUE ERROR

    Hey Experts, We have user Investment management for Budgeting process. We have been using this for last 5 years. After creating the AR and assigning them to the Budget program, we use IM34 to do the rollup of the plan values. After that to allocate t