Help explaining Code

INSERT INTO TABLE (SELECT c.consists_of
FROM programme_tab c WHERE programme# = 'P111')
(SELECT REF(m) FROM module_tab m WHERE module# = 'a111' OR module# = 'a112');
Can someone help me explain this code in plain English , it is for revision reasons

Thanks for the help guys
a bit more code
create TYPE module_m;/
CREATE TYPE programme_p;/
CREATE OR REPLACE TYPE "ADDRESS2_T" as object(
street varchar2(200),
town varchar2(200),
county char(20),
postcode varchar2(20)
CREATE OR REPLACE TYPE MODULE_LIST_T AS TABLE OF REF module_t;
CREATE OR REPLACE TYPE MODULE_T as object (
module_id char(4),
module_title varchar2(20),
no_credits number(2),
is_part_of REF programme_p
CREATE OR REPLACE TYPE "PERSON2_T" as object(
person_id char(4),
pname varchar2(200),
address address2_t,
DOB date,
)NOT FINAL;
CREATE OR REPLACE TYPE PROGRAMME_P AS OBJECT(
programme_id char(4),
programme_title varchar2(20),
dept_id varchar2(20),
consists_of module_list_t,
contains student_list_t,
MEMBER FUNCTION
number_of_students RETURN NUMBER);
CREATE OR REPLACE TYPE BODY PROGRAMME_P AS
MEMBER FUNCTION number_of_students RETURN NUMBER IS
Value NUMBER;
BEGIN
Value:=SELF.consists_of.count;
RETURN value;
END;
END;
CREATE OR REPLACE TYPE STUDENT_LIST_T AS TABLE OF REF student_t;
CREATE OR REPLACE TYPE STUDENT_T UNDER person2_t (
is_enrolled_on REF programme_p,
MEMBER FUNCTION
age RETURN NUMBER
)FINAL;
CREATE OR REPLACE TYPE BODY STUDENT_T AS
MEMBER FUNCTION age RETURN NUMBER IS
Value NUMBER;
BEGIN
Value := (SYSDATE -self.dob)/365;
RETURN value;
END;
END;
CREATE TABLE MODULE_TAB OF MODULE_T
(     SCOPE FOR ("IS_PART_OF") IS "PROGRAMME_TAB" ,
     PRIMARY KEY ("MODULE_ID") ENABLE
CREATE TABLE PERSON2_TAB OF PERSON2_T
( pname PRIMARY KEY);
CREATE TABLE PROGRAMME_TAB OF PROGRAMME_P
(PRIMARY KEY programme_id)
NESTED TABLE CONSISTS_OF STORE AS MODULE_NEST_TAB;
CREATE TABLE PROGRAMME_TAB OF PROGRAMME_P
(PRIMARY KEY programme_id)
NESTED TABLE CONTAINS STORE AS STUDENT_NEST_TAB;
yes its using nested tables, I have a pdf that explains to a degree but am looking for a real idiots (not dummies) guide to object orientated approach to database within oracle
the code works to a degree using sqlplus but if i try the graphical interface ,shows no table data
regards

Similar Messages

  • Help with code explanation

    Help explaining this section of the code, mainly the loop part. A pseudo code explaination would be greatful. What I confuses me is how the two consective loops work? Let say if the first loop on line 260 is terminated then what?{color:#808080}
    239 public static class RandomIvValidator {
    240 private long m_rand = 0;
    241 public char next() {
    242 m_rand = (m_rand * 1103515245) + 24691;
    243 return (char)(m_rand >>> 16);
    244 }
    245 /** This function takes the random number generator back a step.
    246 *
    247 */
    248 public char prev() {
    249 m_rand = (m_rand * 4005161829L) + 171270561;
    250 return (char)(m_rand >>> 16);
    251 }{color}
    {color:#808080} 252 public boolean isLegal(int[] ivs, AnimalNature nature, boolean dp) {
    253 int internal = nature.getInternalValue();
    254 long num1 = (ivs[Char.S_DEFENCE] << 10)
    255 + (ivs[Char.S_ATTACK] << 5)
    256 + ivs[Char.S_HP];
    257 long num2 = (ivs[Char.S_SPDEFENCE] << 10)
    258 + (ivs[Char.S_SPATTACK] << 5)
    259 + ivs[Char.S_SPEED];
    {color}{color:#ff0000} 260 for (int i = 0; i < 2; ++i) {
    261 for (int j = 0; j < 65536; ++j) {
    262 m_rand = (i << 31) + (num1 << 16) + j;
    {color} {color:#808080}263 long first = m_rand;
    264 long second = next();
    265 if (second >= 32768) {
    266 second -= 32768;
    267 }{color}
    Edited by: Bakery on May 15, 2008 5:23 AM

    They're not consecutive, because that means "one after another". These loops are nested. If the outer loop, which starts on 260, were to be broken, it would proceed to the next line after the loop's closing brace, which is not shown in this snippet.
    I'm not even going to bother trying to pseudo-code this, because it's written at such a low level that all the high-level semantic information is lost, other than what's provided in the comments. It looks like C code that was directly ported to Java.
    for(...) { //outer loop runs n times
       outer loop statements //I am executed n times
       for(...) { //inner loop runs m times
          inner loop statements //I am executed n * m times
    }Edited by: nclow on May 15, 2008 1:20 PM

  • Maestro need help also code is 75957252

    maestro need help also code is 75957252 for bios password reset
    This question was solved.
    View Solution.

    Try
    60635894
    ****Please click on Accept As Solution if a suggestion solves your problem. It helps others facing the same problem to find a solution easily****
    2015 Microsoft MVP - Windows Experience Consumer

  • Maestro need help also code is 75957252 for bios password reset

    maestro need help also code is 75957252 for bios password reset
    This question was solved.
    View Solution.

    Check your other post. I replied there.
    ****Please click on Accept As Solution if a suggestion solves your problem. It helps others facing the same problem to find a solution easily****
    2015 Microsoft MVP - Windows Experience Consumer

  • Differnces between Search Help & Match Codes

    Hi,
    what is the Differences between Search Help & Match Codes ? which is goof to use ?

    Matchcodes were replaced with Search Helps starting with Release 4.0. Please use search helps to assign an input help to a field.
    Existing matchcodes were automatically converted to search helps. A matchcode object is hereby converted to a collective search help with the same name. Each matchcode ID of the matchcode object is converted into an elementary search help with the same name and assigned to the collective search help created from the matchcode object.
    A matchcode is a means of finding data records stored in the system. The matchcode is defined in the ABAP Dictionary in two steps:
    You first define the relevant tables and fields for the search in a matchcode object. A matchcode object describes the set of all possible search paths for a search string.
    You then create one or more matchcode IDs for a matchcode object. A matchcode ID describes a special search path for a search string. The matchcode ID defines the fields or field combinations to be used in the search.
    Search Help
    Use
    With this function you can search for objects, thereby defining and linking different selection conditions for the search help.
    Prerequisites
    You can call this function by:
    · Selecting Object ® Search... () in the main menu bar of the Integration Builder
    · Placing the cursor on a software component version and selecting Search... () in the context menu (only in the Integration Repository)
    In this case the software component version is defined as the search criteria.
    Features
    Defining the Object Type
    You can select the object type in a dropdown list in field Object Type.
    In the design (Integration Repository) you can
    · Select an object type (for example Message Interface)
    · Select a cross-object category (for example Interface Objects)
    In the configuration (Integration Directory) you can select types Values Mapping Group and schema in addition to the individual object types.
    CHECK THIS LINK TO CREATE A SEARCH HELP.
    http://www.sapdevelopment.co.uk/dictionary/shelp/shelp_basic.htm
    CHECK THIS LINK TO CREATE A MATCHCODE OBJECT
    http://searchsap.techtarget.com/tip/1,289483,sid21_gci553386,00.html
    more details...

  • Search helps & match codes - Urgent plz

    Hi ,
    1.   Could any one give me the difference between search helps & match codes.
    2. assume that you are giving input matnr from selection screen.and executed based on input matnr you have generated an interactive report with fields matnr,etc...
    if i want to change that particular matnr realted fields how can i do that from this report.Shell i call mm02 tcode.How to do that.how to pass the selected parameter to the transaction.(screen matnr field.please give me an example.
    Regards
    SAISRI

    Hi,
    Check this example for interactive reporting..which will take you MM02
    TYPE-POOLS: slis.
    DATA: gt_fieldcat TYPE slis_t_fieldcat_alv.
    DATA: BEGIN OF wa_material,
    MATNR LIKE MARA-MATNR,
    END OF wa_material.
    DATA: v_repid TYPE syrepid.
    v_repid = sy-repid.
    DATA it_material LIKE STANDARD TABLE OF wa_material WITH HEADER LINE.
    SELECT * UP TO 100 ROWS
    FROM MARA
    INTO CORRESPONDING FIELDS OF TABLE it_material.
    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
         EXPORTING
              i_program_name     = v_repid
              i_internal_tabname = 'WA_MATERIAL'
              i_inclname         = v_repid
         CHANGING
              ct_fieldcat        = gt_fieldcat.
    * have hotspot for a PO.
    DATA: s_fieldcat LIKE LINE OF gt_fieldcat.
    s_fieldcat-hotspot = 'X'.
    MODIFY gt_fieldcat FROM s_fieldcat TRANSPORTING hotspot
           WHERE fieldname = 'MATNR'.
    * Pass the program.
    v_repid = sy-repid.
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
         EXPORTING
              i_callback_program      = v_repid
              it_fieldcat             = gt_fieldcat
              i_callback_user_command = 'USER_COMMAND'
         TABLES
              t_outtab                = it_material.
    *       FORM display_detail                                           *
    *  -->  UCOMM                                                         *
    *  -->  SELFIELD                                                      *
    FORM user_command USING ucomm LIKE sy-ucomm
    selfield TYPE slis_selfield.
      IF ucomm = '&IC1' AND selfield-fieldname = 'MATNR'.
        READ TABLE it_material INDEX selfield-tabindex.
        IF sy-subrc = 0.
          SET PARAMETER ID 'MAT' FIELD it_material-matnr.
          CALL TRANSACTION 'MM02' AND SKIP FIRST SCREEN.
        ENDIF.
      ENDIF.
    ENDFORM.
    Thanks
    Naren

  • Combo box and Check box..help with code please?

    Here is my problem...i have a list of check boxes and according to which one is checked, i need combo boxes to populate different choices.
    as an easy example im only using 2 check boxes and two combo boxes.
    the check boxes are named Choice 1or2 with export values of 1 and 2
    the Combo Boxes are named List A and List B..
    both containing options that say you checked box 1 and you checked box 2
    any help would be greatly appreciated

    Implode wrote:
    "Help with code please."
    In the future, please use a meaningful subject. Given that you're posting here, it's kind of a given that you're looking for help with the code. The whole point of the subject is to give people a high level idea of what KIND of help with what KIND of code you need, so they can decide if they're interested and qualified to help.
    Exception in thread "main" java.lang.NumberFormatException: For input string: "fgg"
         at java.lang.NumberFormatException.forInputString(Unknown Source)
         at java.lang.Integer.parseInt(Unknown Source)
         at java.lang.Integer.parseInt(Unknown Source)
         at assignment1.Game.Start(Game.java:120)
         at assignment1.RunGame.main(RunGame.java:18)This error message is telling you exactly what's wrong. At line 120 of Game.java, in the Start method (which should start with lowercase "s" to follow conventions, by the way), you're calling Integer.parseInt, but "fgg" is not a valid int.

  • My iphone wont turn on or restore,HELP error code 1015

    My iphone wont turn on or restore,HELP error code 1015

    jailbroken? if so we can't help here, try google.

  • Can someone please help me code scrollbars to scroll a movieclip?

    Hi guys,
    Thanks for the interest in my post...
    I've created a scrollbar with up and down buttons for a site
    in Flash 8 but the up button was behaving very oddly even though
    there were no syntax errors.
    Because of this I have decided to start again as nobody could
    find what was going wrong.
    I've created an fla (www.spindriftmedia.com/scroll.fla) with
    all all the elements that will be used but would really appreciate
    it if you wouldn't mind taking a few moments to add the code to the
    buttons and dragger to make it work if that's alright please. I've
    looked all over for tutorials but just can't find anything relevant
    other than the one I used originally.
    Thank you very much and I hope to hear from you.
    Take care,
    Mark

    Generally, people will not download files, so your chances of getting help improve if you include everything in your posting.  In this case you should include the relevant code with which you are having trouble.  Since you say it goes one way or another, I assume that involves coding it different ways, so it might be helpful to show and explain both.

  • Help with code errors

    Can somebody help me get rid of the following compile errors:
    coreservlets/OrderPage.java:61: setNumOrdereed(int, int) in coreservlets.ShoppingCart
    cannont be applied to (java.lang.String,int)
    cart.setNumOrdered(recordingid, numItems);
    .\coreservlets\shoppingCart.java:44 cannot resolve symbol
    symbol : variable recordingid
    location: class coreservlets.ShoppingCart
    if (order.getrecordingid() == (recordingid)) {
    .\coreservlets\ShoppingCart.java:49: cannot resolve symbol
    symbol : variable recordingid
    location: class coreservlets.ShoppingCart
    itemOrder new order = new ItemOrder(Catalog.getItem(recordingid));I know that not very helpful with out the code but the code is very big so if anyone wants me to post extracts from the code please tell me.

    Thank you i put that code in but now get the following:
    coreservlets/OrderPage.java:40:  incompatible types
    found : java.lang.strgin
    required: int int recordingid = request.getParameter("recordingid")!=null?request.getParameter("recordingid"):1;
    ^/code]
    coreservlets/OrderPage.java:48: addItem(java.lang.String) in coreservlets.ShoppingCart cannot be applied to (int)
    cart.additem(recordingid);
    .\coreservlets\AhoppingCart.java:44: cannot resolve symbol
    symbol: variable recordingid
    location: class coreservlets.ShoppingCart
    if (order.getrecordingid() == (recordingid)) {
    .\coreservlets\AhoppingCart.java:49: cannot resolve symbol
    symbol: variable recordingid
    location: class coreservlets.ShoppingCart
    ItemOrder newOrder = new ItemOrder(Catalog.getItem(recordingid));
    4 errors.
    Also could you explain what the line you added to the code means:
    !=null?request.getParameter("recordingid"):1;
    !=null?request.getParameter("numItems"):"1";and how come you got rid of if (recordingid != null) {Thanks for any help with these errors
    OK I HAVE GOT RID OF ALL THE ERRORS APART FROM THE TOP ONE:
    code]coreservlets/OrderPage.java:40: incompatible types
    found : java.lang.strgin
    required: int
    int recordingid = request.getParameter("recordingid")!=null?request.getParameter("recordingid"):1;
                                            /code]
    Message was edited by:
            ajrobson                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Borderless Window help with code please!

    I am using Dreamweaver MX 2004.
    I just cannot get my head round this Java code and would really appreciate some help or direction!
    I want to make a nice little window to show a few lines of text, with a close button or X in the corner (not fussed). I have looked at lots of tutorials and produced numerous codes to use.
    OK, fine I get that bit. My problem comes with placing the codes in the right places. I paste the HEAD portion in the head of the doc. The BODY in the body. BUT is this the doc I am going to call up with my few lines of text in, or the doc I am going to call from? Get what I mean? Also I want to call from a link and haven't had much luck with the line of code I put in the link box. I have tried lots ways and have just managed to confuse myself.
    I am not asking for someone to do it for me and believe me I have tried to work this out for myself but it's not happening for me. Please can someone explain this to me in very plain English as I am obviously some sort of delinquent!
    Thank you

    Yes I am using HTML and Javascript. So Java and Javascript are not the same thing? Right ,OK ,well that has taught me something. Don't suppose you can help me with script on this forum then. Sorry!

  • Help for code

    I am unable to recognize the problem in the following code. My paint() in defined in a class ImagePanel and I am unable to access paint() from outside.
    Please Help!
    import javax.swing.*;
    import javax.swing.event.*;
    import java.io.*;
    import javax.media.*;
    import javax.media.format.*;
    import javax.media.util.*;
    import javax.media.control.*;
    import javax.media.protocol.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.image.*;
    import java.awt.event.*;
    import com.sun.image.codec.jpeg.*;
    import javax.media.*;
    import javax.media.protocol.*;
    import javax.media.control.*;
    import javax.media.format.*;
    import javax.media.util.BufferToImage;
    import java.io.IOException;
    import java.net.*;
    import java.awt.*;
    ////////////////////FROM GESTURE
    import java.io.*;
    import java.awt.*;
    import java.awt.image.*;
    import java.applet.*;
    import java.util.*;
    import java.lang.*;
    //import Gesture.class;
    import com.sun.image.codec.jpeg.*;
    import sun.awt.image.BufferedImageGraphics2D;
    public class SwingCapture extends Panel implements ActionListener, Runnable { 
    public static Player player = null; 
    public CaptureDeviceInfo di = null; 
    public MediaLocator ml = null; 
    public JButton capture = null; 
    public Buffer buf = null; 
    public Image img = null; 
    //public VideoFormat vf=null
    public BufferToImage btoi = null; 
    public ImagePanel imgpanel = null;   
    Thread thr;
    String str1=new String();
    //from gesture
    int xcentre, ycentre,ij;
         static int iw = 320;
         static int ih = 240;
         static int  attenH = 400;
         static int attenW = 200;
         static int PIXCOUNTBB=5;
         static int IMIN=40;   //approximate location of hand
        static int IMAX=239;
        static int JMIN=5;
        static int JMAX=300;
         Image imgprocess;
         Image im;
         int xmin,xmax,ymin,ymax;
    int pix_fill[][]= new int [320][240];
    int pixel2[] = new int[76800];
    int pixel3[] = new int[76800];
    int pixel4[] = new int[76800];
    int pixel5[] = new int[76800];
    int pixel6[] = new int[attenH * attenW];
    double arr[][] = new double[21][2];
    int flag = 0;
    int ixmean = 0;
    int iymean = 0;
    //MyThread thread ;
    int threadflag = 1;
    public SwingCapture()   {
         setLayout(new BorderLayout());   
    //setSize(320,550);
    //setSize(320,550);      
    imgpanel = new ImagePanel();   
    capture = new JButton("Capture");   
    capture.addActionListener(this);       
    //String str1 = "vfw:Philips USB PC-Camera:0";   
    //String str2 = "vfw:Microsoft WDM Image Capture:2"; 
    //String str3 = "vfw:Video Blaster WebCam Go (VFW):0";  
      String str3 = "vfw:Video Blaster WebCam 3/WebCam Plus (VFW):1";  
    System.out.println("sur");
      String str2= "vfw:Microsoft WDM Image Capture (Win32):0";
    di =(CaptureDeviceInfo) CaptureDeviceManager.getDevice(str3);
    System.out.println("sur" + di);
    ml = di.getLocator();       
    try     {     
    player = Manager.createRealizedPlayer(ml);     
    player.start();     
    Component comp;           
    if ((comp = player.getVisualComponent()) != null)                   
          {add(comp,BorderLayout.NORTH);     
    add(capture,BorderLayout.CENTER);     
    add(imgpanel,BorderLayout.SOUTH);}   
    catch (Exception e)    
              e.printStackTrace();   
    thr = new Thread(this);
    public static void main(String[] args)   {   
    Frame f = new Frame("SwingCapture");   
    SwingCapture cf = new SwingCapture();       
    f.addWindowListener(new WindowAdapter() {      //overriding windowClosing
                                             public void windowClosing(WindowEvent e) {     
                                             playerclose();     
                                             System.exit(0); }       
    f.add("Center",cf);   
    f.pack();   
    f.setSize(new Dimension(320,550));   
    f.setVisible(true);
    /*for(int i=0;i<=10;i++)
         FrameGrabbingControl fgc = (FrameGrabbingControl)  player.getControl("javax.media.control.FrameGrabbingControl");     
    buf = fgc.grabFrame();           
    // Convert it to an image     
    btoi = new BufferToImage((VideoFormat)buf.getFormat());     
    img = btoi.createImage(buf);           
    // show the image     
    imgpanel.setImage(img);
    Gesture(img);
    imgprocess.flush();
    img.flush();
    try{
         Thread.sleep(10000);}
         catch(Exception e1){};
    public static void playerclose()   {   
    player.close();   
    player.deallocate(); 
    public synchronized void actionPerformed(ActionEvent e)   {   
    JComponent c = (JComponent) e.getSource();       
    if (c == capture)     {
         //thread started
         thr.start();
         while(ij<=7)
           if(threadflag ==1)
               try{
              System.out.println("Waiting");
                     wait();
                     System.out.println("Finished Waiting");
                catch(Exception e3)
                threadflag =0;
                System.out.println("Back");
                imgpanel.callPaint("<");
                threadflag=1;
                notify();
    public synchronized void run()
           ij = 0;
           while(ij<=7)
         if(threadflag ==1)
              //for( ij = 0; ij<=20;ij++)
    // Grab a frame   
    //this.imgpanel=imgpanel;
    System.out.println("ij : " + ij);
    FrameGrabbingControl fgc = (FrameGrabbingControl)  player.getControl("javax.media.control.FrameGrabbingControl");     
    System.out.println("After buf1 " + fgc);
    buf = fgc.grabFrame();
    System.out.println("After buf " + buf);
    // Convert it to an image     
    btoi = new BufferToImage((VideoFormat)buf.getFormat());     
    System.out.println("After btoi "+ btoi);
    img = btoi.createImage(buf);
    System.out.println("After img "+ img);
    //imgpanel.callpaint(">");
    // show the image     
    //System.out.println("rhododendron");
    //imgpanel.setImage(imgprocess);
    //System.out.println("cacatua");
    //pixel2=Gesture(img);
    Gesture(img);
    //imgpanel.repaint();
    //repaint();
    System.out.println("After Gesture");
    //String str = new String("C:\\test");
                   //str = str + ij + ".jpg";
    //System.out.println("After ");               
              //     SaveImage(str,imgprocess);
    //imgprocess=createImage(new MemoryImageSource(iw,ih,pixel2,0,iw));
    //repaint();
    /*try{
         Thread.sleep(10000);}
         catch(Exception e1){};*/
    //imgprocess.flush();
    //img.flush();
    ij++;
    System.out.println("ij: " + ij);
    threadflag = 0;
    notify();
    //System.out.println("After Notify");
    if(threadflag==0)
         try{
         wait();
    //     notify();
    //repaint();
         catch(Exception e2)
    //System.out.flush();
    /*flag =1;
         int cntleft=0;
         int cntright=0;
    for(int i=1;i<=7;i++)
        if(arr[i-1][0]<arr[0])
         cntright++;
    else
              cntleft++;
    if(cntleft>5)
         str1 = "Moving right";
         System.out.println("Moving right");
         imgpanel.callPaint(str1);
         else
    if(cntright>5)
         str1 = "Moving left";
              System.out.println("Moving left");
         imgpanel.callPaint(str1);
    else
         str1 = "No Movement";
              System.out.println("No Movement");
         imgpanel.callPaint(str1);
    /*class MyThread extends Thread
    MyThread()
         if(threadflag ==1)
              wait();
         else
              threadflag =0;
              imgpanel.callPaint();
              threadflag=1;
              notify();
    class ImagePanel extends Panel {   
    public Image myimg = null;
    String str2 = new String();
    public ImagePanel() {     
    setLayout(null);
    setSize(320,240);
    public void setImage(Image img) {     
    //System.out.println("cacatua");
    //this.myimg = img;
    //repaint();
    public void callPaint(String st)
         //this.str2 = st;
         System.out.println("in callPaint");
         System.out.println("xmean: "+ixmean);
         imgpanel.repaint();
         System.out.println("in out callPaint");
    public void paint(Graphics g) {     
    //if (myimg != null) {  
    //g.drawImage(imgprocess, 0, 0, null);
         System.out.println("xmean: "+ixmean);
         //System.out.println("in Paint of imgpanel");
    //g.drawImage(imgprocess,0,0,null);
    //if(flag==1)
    //g.drawString(str2, 20,20);
    //     else
              //repaint();
              g.drawString(">",ixmean,iymean);
              //repaint();
    //g.drawImage(imgprocess,0,0,null);
    //class Gesture //extends Applet
         /*int xcentre, ycentre;
         static int iw = 320;
         static int ih = 240;
         static int attenH = 400;
         static int attenW = 200;
         static int PIXCOUNTBB=5;
         static int IMIN=40; //approximate location of hand
    static int IMAX=239;
    static int JMIN=5;
    static int JMAX=300;
         Image imgprocess;
         Image im;
         int xmin,xmax,ymin,ymax;
    int pix_fill[][]= new int [320][240];
    int pixel2[] = new int[76800];
    int pixel3[] = new int[76800];
    int pixel4[] = new int[76800];
    int pixel5[] = new int[76800];
    int pixel6[] = new int[attenH * attenW];
         //public int intensity(int pix[][], int x, int y)*/
         public int intensity(int pix[][], int x, int y)
         int p, r, g, b, inten;
              //p=pix[x][y];
    p=pix[x][y];
              r = 0xff & p>>16 ;
              g = 0xff & p>>8;
              b = 0xff & p;
              //inten = (int)(0.33 * r + 0.56 g + 0.11b);
              inten = (int)(0 * r + 0 g + 0.11b);
              //inten = (int)( 0.11*b);
              return(int)(inten);
    public int min(int x, int y)
         if(x<y)
                   return(x);
              else
                   return(y);
         //public void init()
         public void Gesture(Image im)
              //int pixel3[] = new int[80000];
              //int pixel2[] = new int[76800];
         int whitepix=0;
              int coord[][] = new int[2][256];
              //int ymin, xmax,ymax,xmin;
              int no_elem_comp[] = new int[76800];
              int count = 0;
              float pskin[][] = new float[241][241];
              float pnoskin[][] = new float[241][241];
              int num = 0;
              String imname;
              //Image im;
              for(int i=0;i<2;i++)
                   for(int j=0;j<256;j++)
                   coord[i][j] = 0;
              //imname = getParameter("img");
              //im = getImage(getDocumentBase(),imname);
              int pixels[] = new int [iw * ih];
              int pix[][] = new int[iw][ih]; //changed iw and ih
              FileReader fr;
              BufferedReader br ;
              String s = new String();
              int l;
              int total;
              PixelGrabber pg = new PixelGrabber(im,0,0,iw,ih,pixels,0,iw);
              try
                   pg.grabPixels();
              catch(InterruptedException e) {}
              int size = iw * ih;
              for(int m=240; m<480;m++)
                   //System.out.println(m + " : " + pixels[m] );
                   int p = pixels[m];
                   int r = 0xff & (p>>16);
                   int g = 0xff & (p>>8);
                   int b = 0xff & (p);
                   //System.out.println("r : " + r + " g : " + g + " b : " + b);
              //imgprocess=createImage(new MemoryImageSource(iw,ih,pixels,0,iw));
              //repaint();
              ///////controller
              float C[][] = new float[16][size];
              for(int i=0;i<16;i++)
                   for ( int j=0;j<size;j++ )
                   C[i][j]=0;
              //System.out.println("End Controller");
    ////////fingerinit
              try{
              fr = new FileReader("skin");
              br = new BufferedReader(fr);
              //String s;
              s=br.readLine();
              l = Integer.parseInt(s);
              System.out.println("l : " + l);
              s=br.readLine();
              total = Integer.parseInt(s);
              System.out.println("total : " + total);
    String val = new String();
              for(int i=0; i<241; i++)
    for(int j=0; j<241; j++)
         s=br.readLine();
         int intval = Integer.parseInt(s);
              //pskin[i][j] = ((float)intval)/total;
         pskin[i][j] = (float)intval;
              fr.close();
              catch(Exception e)
              {System.out.println("Hello");
    try{
         fr = new FileReader("noskin");
         br = new BufferedReader(fr);
              s=br.readLine();
         l = Integer.parseInt(s);
              s=br.readLine();
         total = Integer.parseInt(s);
              for(int i=0; i<241; i++)
    for(int j=0; j<241; j++)
         s=br.readLine();
         int intval = Integer.parseInt(s);
              //pskin[i][j] = ((float)intval)/total;
         pnoskin[i][j] = (float)intval;
              fr.close();
              catch(Exception e)
                   System.out.println("Here:");
    System.out.println("after noskin");
              float A[][] = new float[size+1][20];
              try{
    System.out.println("in try");
              fr = new FileReader("svdnewdata");
              if(fr==null)
                   System.out.println("Could not open svdnewdata ");
                   System.exit(0);
              br = new BufferedReader(fr);
              for(int i1=0;i1<size;i1++)
                   s=br.readLine();
                   StringTokenizer st =new StringTokenizer(s,"\t");
                   //System.out.println("svd :" + s);
                   for(int j1=0;j1<20;j1++)
                             String val = st.nextToken();
                   //          System.out.println("val : " + val);
                             int intval=Integer.parseInt(val);
                             A[i1][j1]=intval;
              fr.close();
              catch(Exception e)
                   System.out.println("surbhi");
    System.out.println("after svdnewdata");
              ////////Process
              int points[][] = new int[2][size];
              int colors[][] = new int[3][size];
              int data[][] = new int[2][size];
              float prob[] = new float[size];
              ////////fingerpoint
              for(int i=0;i<size;i++)
                   int p = pixels[i];
                   int r=0xff & (p>>16);
                   int g=0xff & (p>>8);
                   int b=0xff & (p);
                   colors[0][i] = r;
    colors[1][i] = g;
                   colors[2][i] = b;
                   data[0][i] = (int)(i/iw)-1;
                   data[1][i] = (int)(i%iw)-1;
    float Cb_f = (float)(((-4818.0*r - 9527.0*g + 14345.0*b)/32768.0)+128.5);
                   float Cr_f = (float)(((14345.0*r - 12045.0*g - 2300.0*b)/32768.0)+128.5);
                   int Cb = (int)Cb_f;
                   int Cr = (int)Cr_f;
                                  //System.out.println("Cb :" + Cb);
                                  //System.out.println("Cr :" + Cr);
                   if(pnoskin[Cb][Cr] ==0)
    //System.out.println("sur :" );
                        prob[i]=1;
                   else
                        prob[i]=pskin[Cb][Cr]/pnoskin[Cb][Cr];
              //System.out.println("anui");
    for(int a=0;a<size ;a++)
         if( prob[a]>0.05)
         //     { System.out.println("Ishsani"); 
              pixel2[a]=0xff000000 | 0x000000ff;//}
         else
         //     {System.out.println("Ishsani11");
              pixel2[a]=0xff000000 | 0x00ff0000;
                   int k=0;
                   int buffer[] = new int[3];
                   //int pix[][] = new int[ih][iw];
                   for(int i=0;i<ih;i++)
                        for(int j=0;j<iw;j++)
                        pix[j][i]= pixel2[k++];
    //System.out.println("out k:" + k);
                   for(int i=1;i<ih-1;i++)
                   for(int j=1;j<iw-1;j++)
                        whitepix = 0;
                        for(int i1=i-1;i1<=i+1;i1++)
                             for(int j1=j-1;j1<j+1;j1++)
                        buffer[0]= 0x000000ff & (pix[j1][i1]>>16);
                        buffer[1]= 0x000000ff & (pix[j1][i1]>>8);
                             buffer[2]= 0x000000ff & (pix[j1][i1]);
                             //if(((buffer[0]==-1)&&(buffer[1]==-1))||((buffer[2]==-1)&&(buffer[1]==-1))||((buffer[0]==-1)&&(buffer[2]==-1)))
                             if(buffer[2]==255)
                                  whitepix++;
                        if(whitepix>=3)
                             //pix[j][i] = (255<<24) | (255 << 16) | (255<<8) | (255);
                             pix[j][i] = 0xff000000 | 0x000000ff;
              //               System.out.println("if : " + pix[j][i]);
                        else
                             //pix[j][i] = 0xff|(0<<16)|(0<<8)|0;
                             pix[j][i] = 0xff000000 | 0x00ff0000;
              //               System.out.println("else : " + pix[j][i]);
                   }//end for
         int b=0;
                   for(int i=0;i<ih;i++)
                   for(int j=0;j<iw;j++)
                        pixel2[b++] = pix[j][i];
    //imgprocess=createImage(new MemoryImageSource(iw,ih,pixel3,0,iw));
    //repaint();
              IdenOutline(pix);
              IdenOutline(pix_fill);
              IdenOutline(pix_fill);
              IdenOutline(pix_fill);
              IdenOutline(pix_fill);
              IdenOutline(pix_fill);
              //IdenOutline(pix_fill);
    calcBoundary();
              System.out.println("xmax : " + xmax + " xmin : " + xmin);
    System.out.println("ymax : " + ymax + " ymin : " + ymin);
              BBox();
              CalcMvt();
              b=0;
                   for(int i=0;i<ih;i++)
                   for(int j=0;j<iw;j++)
                        pixel2[b++] = pix_fill[j][i];
    //imgpanel.callPaint(">");
    //imgpanel.repaint();
    // imgprocess.flush();
    //imgprocess=createImage(new MemoryImageSource(iw,ih,pixel2,0,iw));
    //repaint();
    //thread.start();
    //try{
    //wait();
    //catch(Exception e)
    //imgpanel.callPaint(">");
    //repaint();
    //imgprocess.flush();
    /*          public void run()
                   imgpanel.callPaint(">");
                   notify();
    /*public void paint(Graphics g)
         g.drawString(str1, 310,300);
         System.out.println("Came in paint");
    //g.drawString("Coordinates of the Centroid is "+ xcentre + " , " + ycentre , 10,40);
    //g.drawImage(imgprocess,0,0,null);
         //System.out.println("Came in paint out");
    //g.drawImage(im,0,0,this);
    //if(imgprocess==null){
              System.out.println("ishani1");
              //imgprocess=createImage(new MemoryImageSource(iw,ih,pixel2,0,iw));
              //repaint();
         System.out.println("ishani2");
    //g.drawImage(imgprocess,0,0,null);
    //g.drawImage(imgprocess,0,400,null);
    System.out.println("ishani3");
    //repaint();
    void BBox()
    for(int i=xmin ; i<=xmax;i++)
         pix_fill[i][ymax] = 0xff0000ff;
         pix_fill[i][ymin] = 0xff0000ff;
         System.out.println("Came here");
         for(int j=ymin;j<=ymax;j++)
              pix_fill[xmax][j] = 0xff0000ff;
    pix_fill[xmin][j] = 0xff0000ff;
         System.out.println("Came here2");
    void calcBoundary()
    int minrow,maxrow,mincol,maxcol,flag=0;
         minrow=maxrow=mincol=maxcol=0;
         for(int i=0;i<ih;i++)
         for(int j=0;j<iw;j++)
         if(pix_fill[j][i] == 0xff0000ff)
              flag = 1;
              minrow = i;
              break;
         if(flag==1)
         break;
         flag=0;
    for(int i=(ih-1);i>=0;i--)
         for(int j=0;j<iw;j++)
              if(pix_fill[j][i] == 0xff0000ff)
                   flag =1;
                   maxrow=i;
                   break;
              if(flag==1)
              break;
         flag =0;
    for(int j=0;j<iw;j++)
         for(int i=0;i<ih;i++)
              if(pix_fill[j][i] == 0xff0000ff)
                   flag=1;
                   mincol = j;
                   //System.out.println("row : " + i + " Col : " + mincol);
                   break;
              if(flag==1)
                   break;
         flag =0;
    for(int j=(iw-1);j>=0;j--)
         for(int i=0;i<ih;i++)
              if(pix_fill[j][i] == 0xff0000ff)
                   flag =1;
                   maxcol = j;
                   System.out.println("row : " + i + " Col : " + maxcol);
                   break;
              if(flag==1)
    break;
    xmax = maxcol;
    xmin = mincol;
    ymax = maxrow;
    ymin = minrow;
    return;
    void IdenOutline(int pix_temp[][])
         int n,k,l,i,j;
         for(i=0;i<ih;i++)
              for(j=0;j<iw;j++)
         if(pix_temp[j][i]==0xffff0000)
                        continue;
                   else
                        for(k=1;(j+k)<320;k++)
                        if(pix_temp[j+k][i]!=0xffff0000)
                        continue;
                        else
                             break;
                             for(l=1;(i-l)>0;l++)
                        if(pix_temp[j][i-l]!=0xffff0000)
                                  continue;
                             else
                                            break;
                                       /*for(m=1;j-m>0;m++)
                                            if(pix_fill[j-m][i])!=0xff0000ff)
                                            continue;
                                       else*/
                                                 for(n=1;(i+n)<240;n++)
                        if(pix_temp[j][i+n]!=0xffff0000)
                                                 continue;
                                                 else
    break;
                                                      if((k<15)&&(n<20)&&(l<20))
                                                           pix_temp[j][i]=0xffff0000;
                                                      else
                                                                     if((k<15)&&(l<10)&&(n>10))
    pix_temp[j][i]=0xff0000ff;
                                                                else
                                                                          if((n<10)&&(k<15)&&(l>10))
                                                                          pix_temp[j][i]=0xff0000ff;
                                                                     else
                                                                          if((n<10)&&(l<10)&&(k>15))
                                                                          pix_temp[j][i]=0xff0000ff;
    int b1=0;
                        for(int a=0;a<ih;a++)
                        for(int d=0;d<iw;d++)
                        pixel2[b1++] = pix_temp[d][a];
                        pix_fill[d][a] = pix_temp[d][a];
    //imgprocess=createImage(new MemoryImageSource(iw,ih,pixel4,0,iw));
              //repaint();
    public void SaveImage(String s,Image im)
         System.out.println("i m here" + im);
         /* try{
              Thread.sleep(1000);
         catch(Exception e)
         //BufferedImage bi = new BufferedImage(im.getWidth(null, im.getHeight(null), BufferedImage.TYPE_INT_RGB);
    BufferedImage bi = new BufferedImage(320, 240, BufferedImage.TYPE_INT_RGB);
         System.out.println("i m here" + bi);
         Graphics2D g2 = bi.createGraphics();
         g2.drawImage(im, null, null);
         System.out.println("i m here" + g2);
         FileOutputStream out = null;
         try {      
              out = new FileOutputStream(s);
         catch (java.io.FileNotFoundException io)
              System.out.println("File Not Found");
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
         JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
         param.setQuality(0.5f,false);
         encoder.setJPEGEncodeParam(param);
         try
              encoder.encode(bi);
              out.close();
         catch (java.io.IOException io)
              System.out.println("IOException");
         public void CalcMvt()
              double xmean=(xmax+xmin)/2;
              double ymean=(ymax+ymin)/2;
              ixmean = (int) xmean;
              iymean = (int)ymean;
              arr[ij][0]= xmean;
              arr[ij][1]=ymean;
         }//end of class
    /*public class SCapture
    public static void main(String[] args) {   
    Frame f = new Frame("SwingCapture");
    SwingCapture cf = new SwingCapture();
    f.addWindowListener(new WindowAdapter() {      //overriding windowClosing
    public void windowClosing(WindowEvent e) {     
    playerclose();
    System.exit(0); }
    f.add("Center",cf);
    f.pack();
    f.setSize(new Dimension(320,550));
    f.setVisible(true);*/
    /*for(int i=0;i<=10;i++)
         FrameGrabbingControl fgc = (FrameGrabbingControl) player.getControl("javax.media.control.FrameGrabbingControl");
    buf = fgc.grabFrame();
    // Convert it to an image
    btoi = new BufferToImage((VideoFormat)buf.getFormat());
    img = btoi.createImage(buf);
    // show the image
    imgpanel.setImage(img);
    Gesture(img);
    imgprocess.flush();
    img.flush();
    try{
         Thread.sleep(10000);}
         catch(Exception e1){};

    Not sure exactly what you mean...
    Here, try this sample, use your ImagePanel with a standard frame. Just add the panel to the frame, make the frame visible, shrink and restore it a few time, see if your paint method gets called...
    If it works correctly, good, you know the ImagePanel is fine, and yout problem is with your other class. If it doesn't work, then concentrate on your ImagePanel and explain exactly HOW it doesn't work... (like any errors, what gets shown/printed to the command line, exactly how it misbehaves...
    public void ImagePanelTest extends Frame {
      public ImagePanelTest (String title) {
        super(title);
      public void main(String[] args) {
        ImagePanel ip = new ImagePanel();
        ImagePanelTest ipt = new ImagePanelTest("ImagePanel Test");
          ipt.add(ip);
          ipt.setSize(new Dimension(300,300));
          ipt.addWindowListener(new WindowAdapter() {
            public void windowClosing(windowEvent we) {
              dispose();
              System.exit(0);
          ipt.show();
      }

  • Please help explain these bitwise operations!

    I am working with a file that has a header with the size of the file encoded into 4 bytes like:
    >
    The ID3v2 tag size is encoded with four bytes where the most significant bit (bit 7) is set to zero in every byte, making a total of 28 bits. The zeroed bits are ignored, so a 257 bytes long tag is represented as $00 00 02 01.
    I have found someone's code that puts this together into the integer value, but i don't understand why they do each step. Is there anyone here who can explain this code to me?
    //Read in the bytes (why do they read char[] instead of byte[]?)
    char[] tagSize = br.ReadChars(4);    // I use this to read the bytes in from the file
    //Store the shifted bytes (why is it int[], not byte[]?)
    int[] bytes = new int[4];      // for bit shifting
    int size = 0;    // for the final number
    * Why are they combining these bytes in this way if they're
    * going to again combine them below (in the line setting "size")?
    //how do they know they only care about the rightmost bit on the 3rd byte?
    //how do they know to shift it 7 to the left?
    bytes[3] =  tagSize[3] | ((tagSize[2] & 1) << 7) ;
    //Why do they use 63 here (I know it's 111111)?
    //how do they know they only want the 3 rightmost of byte 2nd byte?
    //And how know to shift it 6 to the left?
    bytes[2] = ((tagSize[2] >> 1) & 63) | ((tagSize[1] & 3) << 6) ;
    bytes[1] = ((tagSize[1] >> 2) & 31) | ((tagSize[0] & 7) << 5) ;
    bytes[0] = ((tagSize[0] >> 3) & 15) ;
    //how do they know to shift these bytes the amount that they do to the left?
    size  = ((UInt64)bytes[3] | ((UInt64)bytes[2] << 8)  | ((UInt64)bytes[1] << 16) | ((UInt64)bytes[0] << 24)) ;

    6tr6tr wrote:
    You've GOT to be kidding! I posted only ONCE on THIS forum. Javaranch is owned by a different company and does NOT have all the same members that this web forum has. Posting the same question on completely different websites' forums is NOT cross-posting. Cross-posting is posting the same thing in different boards of ONE website's forums.Absolute rubbish. Here a couple of links for you:
    Wikipedia:
    [Crossposting is the act of posting the same message to multiple forums, mailing lists, or newsgroups.|http://en.wikipedia.org/wiki/Crossposting]
    JavaRanch's FAQ:
    [There might be times when you are inclined to post a question not only at JavaRanch, but also at some other site. When you do so, keep in mind that this is not generally in the interests of the posters who might be responding to your posts - those folks may find they've wasted their time. You certainly don't want to annoy those you want to help you, so you might want to make the experience as painless as possible.|http://faq.javaranch.com/java/BeForthrightWhenCrossPostingToOtherSites]
    Sun's FAQ, section C2:
    [Post once and in the right area: Multiple postings are discouraged, because they make the category lists longer and create more email traffic for developers who have placed watches on multiple categories. Because of this, duplicate posts are considered a waste of time and an annoyance to many community members, that is, the people who might help you.|http://wikis.sun.com/display/SunForums/Forums.sun.com+FAQ]

  • Checking Account and help with code ?

    Hi all..my computer hung up on me, so I'm not sure if my last post went through. First of all thank you all for helping me out the other day with my question on the Bank Account. It continues :)
    I'm trying to work on each class one by one..when I test my Checking Account, it isn't printing out the correct balance. The string method to print this is coming from the Withdrawal class...so I know it has to be somewhere in there but I can't seem to figure out why it isn't totalling the balance...or how to get it too.
    Then when I test my MyBank class, it hangs up on line 63..which I could swear I have written correctly. Again I am getting a NullPointerException and I honestly think I have the line of code written right, but I'm guessing I dont.
    Any help would be appreciated.
    public abstract class BankAccount {
        public static final String bankName = "BrianBank";
        protected String custName;
        protected String pin;
        protected Transaction[] history;
        private double balance;
        private double amt, amount;
        private double bal, initBal;
        private int transactions;
        private final int MAX_HISTORY = 100;
        private int acct;
        protected BankAccount(String cname, String cpin, double initBal) {
         custName = cname;
         pin = cpin;
         balance = initBal;
         history = new Transaction[MAX_HISTORY];
         transactions =0;
        public double getBalance() {
         return balance;
        public void withdraw(double amt) {
         history [transactions] = new Withdrawal (bal, amt);
       balance = bal;
         amount = amt;
         balance -= amt;
       transactions = transactions + 1;     
        public void deposit(double amt) {     
         history [transactions] = new Deposit (bal, amt);
         balance = bal;
         amount = amt;
         balance += amt;
         transactions = transactions +1;
        // abstract method to return account number
        public abstract int getAcctNum();
        // abstract method to return a summary of transactions as a string
        public abstract String getStatement();
    public class CheckingAccount extends BankAccount implements IncursFee
          private int transactions;
          private double balance, initBal, amt;
          private static final int NOFEE_WITHDRAWALS = 10;
          private static final double TRANSACTION_FEE = 5.00;
          public static final String bankName = "iBank";
          public static final int STARTING_ACCOUNT_NUMBER = 10000;
          private int checkingAccountNumber = STARTING_ACCOUNT_NUMBER;
          private static int accountNumberCounter = STARTING_ACCOUNT_NUMBER;
          private String custName;
          private String pin;
          public CheckingAccount (String cname, String cpin, double initBal)
             super (cname, cpin, initBal);
              custName = cname;
              pin = cpin;
             balance = initBal;
             accountNumberCounter++; 
             checkingAccountNumber = accountNumberCounter;
          //initialize a count of transactions
             transactions = 0;          
           public double getBalance()
             return balance;
           public void withdraw(double amt)
            super.withdraw (amt);
             transactions ++;
           public void deposit(double amt)
           super.deposit (amt);
             transactions ++;
           public int getAcctNum ()
             return checkingAccountNumber;     
           public String getStatement ()
             int i = 0;
             String output = "";
             while ( i < history.length && history[i] != null )
                output += history.toString () + "\n";
    i++;
    return output;     
    public void deductFee(double fee)
    if (transactions > NOFEE_WITHDRAWALS)
    {  fee = TRANSACTION_FEE *(transactions - NOFEE_WITHDRAWALS);
    super.withdraw(fee);
    balance -=fee;
    transactions = 0;
    public interface IncursFee {
    public abstract void deductFee(double fee);
    public abstract class Transaction {
    protected double initBal;
    protected double tranAmt;
    // constructor
    protected Transaction(double bal, double amt) {
         initBal = bal;
         tranAmt = amt;
    abstract public String toString();
    public class Withdrawal extends Transaction
         private double initBal;
         private double amount;
         private static NumberFormat fmt = NumberFormat.getCurrencyInstance();
         public Withdrawal (double bal, double amt)
              super (bal, amt);
              initBal = bal;
              amount = amt;
         public String toString ()
         return "Balance : " + fmt.format(initBal) + "\n" + "Withdrawal : " + fmt.format(amount);
    import java.text.NumberFormat;
    public class Deposit extends Transaction
         private double initbal, balance;
         private double amount;
         private static NumberFormat fmt = NumberFormat.getCurrencyInstance();
         public Deposit (double bal, double amt)
         super (bal, amt);
         initbal = bal;
         amount = amt;
         public String toString ()
         return "Balance : " + fmt.format(initbal) + "\n" + "Deposit : " + fmt.format(amount);
    public class TestCheckingAcct {
    public static void main(String[] args) {
         BankAccount b1 = new CheckingAccount("Harry", "1234", 500.0);
         System.out.println (b1.getBalance ());
         b1.withdraw(1);
         b1.withdraw(1);
         b1.withdraw(1);
         b1.withdraw(1);
         b1.withdraw(1);
         b1.deposit(50);
         b1.withdraw(1);
         b1.withdraw(1);
         b1.withdraw(1);
         b1.withdraw(1);
         b1.withdraw(1);
         b1.withdraw(1);
         b1.withdraw(1);
         b1.deposit(10);
         b1.withdraw(1);
         System.out.println(b1.getStatement());
    // This interface specifies the functionality requirements of a bank
    public interface Bank {
    public abstract int openNewAccount(String customerName, String customerPIN, String accType, double initDepAmount);
    public abstract void processWithdrawal(int accNum, String pin, double amount);
    // executes a deposit on the specified acct by the amount
    public abstract void processDeposit(int accNum, String pin, double amount);
    // returns the balance of acct
    public abstract double processBalanceInquiry(int accNum, String pin);
    // returns summary of transactions
    public abstract String processStatementInquiry(int accNum, String pin);
    import java.util.ArrayList;
    public class MyBank implements Bank
    private ArrayList<BankAccount> savAccounts = new ArrayList<BankAccount>(); //dynamically grows
    private ArrayList<BankAccount> chkAccounts = new ArrayList<BankAccount>(); //dynamically grows
    private SavingsAccount sav;
    private CheckingAccount chk;
    private int accNum;
    private String customerName, customerPIN, accType, pin;
    private double initDepAmount, amount, balance;
    public int openNewAccount(String customerName, String customerPIN, String accType, double initDepAmount)
    this.customerName = customerName;
    this.customerPIN = customerPIN;
    this.accType = accType;
    this.initDepAmount = initDepAmount;
    if ( accType.equals("Savings"))
    BankAccount savAcct = new SavingsAccount(customerName, customerPIN, initDepAmount);
    try
    savAccounts.add(savAcct);
    catch (ArrayIndexOutOfBoundsException savAccounts)
    return savAcct.getAcctNum();
    else
    CheckingAccount chkAcct = new CheckingAccount(customerName, customerPIN, initDepAmount);
         try
    chkAccounts.add(chkAcct);
    catch (ArrayIndexOutOfBoundsException chkAccounts)
    return chkAcct.getAcctNum();
    public void processWithdrawal (int accNum, String pin, double amount)
         this.accNum = accNum;
         this.pin = pin;
         this.amount = amount;
    if (accNum >10000 && accNum < 20000)
         chk.withdraw (amount);
    if (accNum >50000 && accNum <60000)
         sav.withdraw (amount);
    public void processDeposit (int accNum, String pin, double amount)
         this.accNum = accNum;
         this.pin = pin;
         this.amount = amount;
    if (accNum >10000 && accNum < 20000)
         chk.deposit (amount);
    if (accNum >50000 && accNum <60000)
         sav.deposit (amount);
    public double processBalanceInquiry (int accNum, String pin)
         this.accNum = accNum;
         this.pin = pin;
         this.balance = 0;
    if (accNum >10000 && accNum <20000)
         balance = chk.getBalance ();
    if (accNum >50000 && accNum <60000)
         balance = sav.getBalance ();
    return balance;
    public String processStatementInquiry(int accNum, String pin)
         this.accNum = accNum;
         this.pin = pin;
         this.statement = "";
    if (accNum >10000 && accNum <20000)
    statement = chk.getStatement ();
    if (accNum >50000 && accNum <60000)
    statement= sav.getStatement ();
         return statement;

    Here's some quick code review:
    public abstract class BankAccount {
    public static final String bankName =
    me = "BrianBank";
    protected String custName;
    protected String pin;
    protected Transaction[] history;
    private double balance;
    private double amt, amount;
    private double bal, initBal;
    private int transactions;// make MAX_HISTORY private static final, too.
    private final int MAX_HISTORY = 100;
    private int acct;
    protected BankAccount(String cname, String cpin,
    pin, double initBal) {
         custName = cname;
         pin = cpin;
         balance = initBal;
         history = new Transaction[MAX_HISTORY];
         transactions =0;
    public double getBalance() {
         return balance;
    public void withdraw(double amt) {
         history [transactions] = new Withdrawal (bal, amt);
    balance = bal;
         amount = amt;
         balance -= amt;// ++transactions above would be elegant.
    transactions = transactions + 1;     
    public void deposit(double amt) {     
         history [transactions] = new Deposit (bal, amt);
         balance = bal;
         amount = amt;
         balance += amt;
         transactions = transactions +1;
    // abstract method to return account number// why abstract?
    public abstract int getAcctNum();
    // abstract method to return a summary of
    y of transactions as a string// why abstract?
    public abstract String getStatement();
    public class CheckingAccount extends BankAccount
    implements IncursFee
    private int transactions;
    private double balance, initBal, amt;
    private static final int NOFEE_WITHDRAWALS =
    WALS = 10;
    private static final double TRANSACTION_FEE =
    _FEE = 5.00;
    public static final String bankName = "iBank";
    public static final int STARTING_ACCOUNT_NUMBER
    NUMBER = 10000;
    private int checkingAccountNumber =
    mber = STARTING_ACCOUNT_NUMBER;
    private static int accountNumberCounter =
    nter = STARTING_ACCOUNT_NUMBER;// BankAccount has a custName attribute; why does CheckingAccount need
    // one if it extends BankAccount?
    private String custName;
    private String pin;
    public CheckingAccount (String cname, String
    String cpin, double initBal)
    super (cname, cpin, initBal);
    custName = cname;
    pin = cpin;
    balance = initBal;
    accountNumberCounter++;
    checkingAccountNumber =
    tNumber = accountNumberCounter;
    //initialize a count of transactions
    transactions = 0;          
    // same as BankAccount - why rewrite it?
    public double getBalance()
    return balance;
    // same as BankAccount - why rewrite it?
    public void withdraw(double amt)
    super.withdraw (amt);
    transactions ++;
    // same as BankAccount - why rewrite it?
    public void deposit(double amt)
    super.deposit (amt);
    transactions ++;
              // same as BankAccount - why rewrite it?
    public int getAcctNum ()
    return checkingAccountNumber;     
    public String getStatement ()
    int i = 0;
    String output = "";
    while ( i < history.length && history[i] !=
    ory[i] != null )
    output += history.toString () + "\n";
    i++;
    return output;     
    public void deductFee(double fee)
    if (transactions > NOFEE_WITHDRAWALS)
    {  fee = TRANSACTION_FEE *(transactions -
    ansactions - NOFEE_WITHDRAWALS);
    super.withdraw(fee);
    balance -=fee;
    transactions = 0;
    public interface IncursFee {
    public abstract void deductFee(double fee);
    public abstract class Transaction {
    protected double initBal;
    protected double tranAmt;
    // constructor
    // why protected? make it public.
    protected Transaction(double bal, double amt) {
         initBal = bal;
         tranAmt = amt;
    abstract public String toString();
    public class Withdrawal extends Transaction
         private double initBal;
         private double amount;
    private static NumberFormat fmt =
    = NumberFormat.getCurrencyInstance();
         public Withdrawal (double bal, double amt)
              super (bal, amt);
              initBal = bal;
              amount = amt;
         public String toString ()
    return "Balance : " + fmt.format(initBal) + "\n" +
    + "Withdrawal : " + fmt.format(amount);
    import java.text.NumberFormat;
    public class Deposit extends Transaction
         private double initbal, balance;
         private double amount;
    private static NumberFormat fmt =
    = NumberFormat.getCurrencyInstance();
         public Deposit (double bal, double amt)
         super (bal, amt);
         initbal = bal;
         amount = amt;
         public String toString ()
    return "Balance : " + fmt.format(initbal) + "\n" +
    + "Deposit : " + fmt.format(amount);
    public class TestCheckingAcct {
    public static void main(String[] args) {
    BankAccount b1 = new CheckingAccount("Harry",
    , "1234", 500.0);
         System.out.println (b1.getBalance ());
         b1.withdraw(1);
         b1.withdraw(1);
         b1.withdraw(1);
         b1.withdraw(1);
         b1.withdraw(1);
         b1.deposit(50);
         b1.withdraw(1);
         b1.withdraw(1);
         b1.withdraw(1);
         b1.withdraw(1);
         b1.withdraw(1);
         b1.withdraw(1);
         b1.withdraw(1);
         b1.deposit(10);
         b1.withdraw(1);
         System.out.println(b1.getStatement());
    // This interface specifies the functionality
    requirements of a bank
    public interface Bank {
    public abstract int openNewAccount(String
    String customerName, String customerPIN, String
    accType, double initDepAmount);
    public abstract void processWithdrawal(int
    (int accNum, String pin, double amount);
    // executes a deposit on the specified acct by
    t by the amount
    public abstract void processDeposit(int accNum,
    Num, String pin, double amount);
    // returns the balance of acct
    public abstract double processBalanceInquiry(int
    (int accNum, String pin);
    // returns summary of transactions
    public abstract String
    ring processStatementInquiry(int accNum, String
    pin);
    import java.util.ArrayList;
    public class MyBank implements Bank
    private ArrayList<BankAccount> savAccounts =
    unts = new ArrayList<BankAccount>(); //dynamically
    grows
    private ArrayList<BankAccount> chkAccounts =
    unts = new ArrayList<BankAccount>(); //dynamically
    grows
    private SavingsAccount sav;
    private CheckingAccount chk;
    private int accNum;
    private String customerName, customerPIN,
    erPIN, accType, pin;
    private double initDepAmount, amount, balance;
    public int openNewAccount(String customerName,
    erName, String customerPIN, String accType, double
    initDepAmount)
    this.customerName = customerName;
    this.customerPIN = customerPIN;
    this.accType = accType;
    this.initDepAmount = initDepAmount;
    if ( accType.equals("Savings"))
    BankAccount savAcct = new
    vAcct = new SavingsAccount(customerName, customerPIN,
    initDepAmount);
    try
    savAccounts.add(savAcct);
    catch (ArrayIndexOutOfBoundsException
    Exception savAccounts)
    return savAcct.getAcctNum();
    else
    CheckingAccount chkAcct = new
    hkAcct = new CheckingAccount(customerName,
    customerPIN, initDepAmount);
         try
    chkAccounts.add(chkAcct);
    catch (ArrayIndexOutOfBoundsException
    Exception chkAccounts)
    return chkAcct.getAcctNum();
    public void processWithdrawal (int accNum,
    accNum, String pin, double amount)
         this.accNum = accNum;
         this.pin = pin;
         this.amount = amount;
    if (accNum >10000 && accNum < 20000)
         chk.withdraw (amount);
    if (accNum >50000 && accNum <60000)
         sav.withdraw (amount);
    public void processDeposit (int accNum, String
    String pin, double amount)
         this.accNum = accNum;
         this.pin = pin;
         this.amount = amount;
    if (accNum >10000 && accNum < 20000)
         chk.deposit (amount);
    if (accNum >50000 && accNum <60000)
         sav.deposit (amount);
    public double processBalanceInquiry (int accNum,
    String pin)
         this.accNum = accNum;
         this.pin = pin;
         this.balance = 0;
    if (accNum >10000 && accNum <20000)
         balance = chk.getBalance ();
    if (accNum >50000 && accNum <60000)
         balance = sav.getBalance ();
    return balance;
    public String processStatementInquiry(int accNum,
    m, String pin)
         this.accNum = accNum;
         this.pin = pin;
         this.statement = "";
    if (accNum >10000 && accNum <20000)
    statement = chk.getStatement ();
    if (accNum >50000 && accNum <60000)
    statement= sav.getStatement ();
         return statement;
    Very bad style with those brace placements. Pick a style and stick with it. Consistency is the key.
    Your code isn't very readable.
    You don't have a SavingsAccount here anywhere, even though your MyBank uses one.
    You use JDK 1.5 generics yet you've got ArrayList as the static type on those declarations. Better to use the interface type List as the compile time type on the LHS.
    You have a lot of compile time problems, and some incomprehensible stuff, but I was able to change it enough to my TestCheckingAcct run to completion. No NPE exceptions.
    I'm not sure I agree with your design.
    No SavingsAccount. The accounts I have ALL incur fees - no need for a special interface there. Savings accounts are usually interest bearing. That's the way they behave differently from checking accounts. Where do you have that?
    You rewrite too much code. If you put behavior in the abstract BankingAccount class (a good idea), the whole idea is that concrete classes that extend BankingAccount don't need to overload any methods whose default behavior is correct for them.
    I don't know that I'd have separate Deposit and Withdrawal to implement Transaction. I'd make Transaction concrete and have starting balance, ending balance, and a transaction type String (e.g., "DEPOSIT", "WITHDRAWAL")
    It'd be good to see some thought put into exception handling. I don't see an OverdrawnException anywhere. Seems appropriate.
    No transfer methods from one account to another. I often do that with my bank.
    That's enough to get started.

  • Help with code to print HTML in Java 5

    Hi,
    The following code works and runs successfully..
    However, the printing in Java 1.4.2_03 is better than Java 5 (latest version).
    i.e in particular the characters are not monospaced compared with compiling with Java 1.4.2_03. e.g si so ss squashed together.
    This issue does not seem to occur when running the same code in Java 1.4.2_03. (I haven't tried other 1.4.2 java versions).
    Any help would be appreciated. We really need this working under Java 5 or bust.
    Here is the complete listing ... PrintHtml.java (it uses the DocumentRenderer)
    and following this is the input file.
    import javax.swing.text.html.HTMLDocument;
    import java.net.URL;
    import java.net.MalformedURLException;
    import java.io.IOException;
    import java.io.DataInputStream;
    import java.io.InputStream;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import javax.swing.text.html.*;
    import java.lang.reflect.*;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Rectangle;
    import java.awt.Shape;
    import java.awt.print.PageFormat;
    import java.awt.print.Printable;
    import java.awt.print.PrinterException;
    import java.awt.print.PrinterJob;
    import javax.swing.JEditorPane;
    import javax.swing.text.Document;
    import javax.swing.text.PlainDocument;
    import javax.swing.text.View;
    import javax.swing.text.html.HTMLDocument;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.print.*;
    import java.text.ParseException;
    public class PrintHtml {
         * Utility helper to convert HTML Text to HTML Document.
         * @param baseUrl URL to be used in order
         * to resolve relative HTML references, in lieu of an
         * HTML BASE tag. May be null, if not required or HTML
         * BASE tag is to be used.
         * @see jbox.view.jfx.JboxHtmlEditor
         * @see jbox.utility.JboxPrint
         * @see jbox.utility.JboxPrintUtil
      public static HTMLDocument htmlTextToHtmlDoc(String htmlText, URL baseUrl)
              try
              //  JboxHtmlEditorKit editorKit = new JboxHtmlEditorKit();
                HTMLEditorKit editorKit = new HTMLEditorKit();
                HTMLDocument doc = (HTMLDocument)editorKit.createDefaultDocument();
                   if (baseUrl != null)
                        try
                             doc.setBase(baseUrl);
                        catch(Exception e)
                             //JboxTraceManager.trace(e);
                   StringReader reader = new StringReader(htmlText);
                   editorKit.read(reader, doc, 0);
             return doc;
              catch(Exception e)
                   //JboxTraceManager.trace(e);
                   return null;
       public static void main(String[] args) {
          System.out.println("printing...");
          HTMLDocument x = new HTMLDocument();
          DocumentRenderer invoice = new DocumentRenderer();
          //invoice.setScaleWidthToFit(false);
          String s = "";
          try {
            BufferedInputStream bis = new BufferedInputStream(new FileInputStream("mark.html"));
            InputStreamReader in = new InputStreamReader(bis , "ASCII");
            StringWriter sw = new StringWriter();
            while (true) {
               int datum = in.read();
               if (datum == -1) break;
               sw.write(datum);
            in.close();
            s = sw.toString();
            System.out.println("s="+s);
          catch (IOException e) {
             System.err.println(e);
          HTMLDocument htmldoc = htmlTextToHtmlDoc(s, null);
          invoice.print(htmldoc);
    // the good old infamous DocumentRenderer.
    /*  Copyright 2002
        Kei G. Gauthier
        Suite 301
        77 Winsor Street
        Ludlow, MA  01056
    class DocumentRenderer implements Printable {
    /*  DocumentRenderer prints objects of type Document. Text attributes, including
        fonts, color, and small icons, will be rendered to a printed page.
        DocumentRenderer computes line breaks, paginates, and performs other
        formatting.
        An HTMLDocument is printed by sending it as an argument to the
        print(HTMLDocument) method. A PlainDocument is printed the same way. Other
        types of documents must be sent in a JEditorPane as an argument to the
        print(JEditorPane) method. Printing Documents in this way will automatically
        display a print dialog.
        As objects which implement the Printable Interface, instances of the
        DocumentRenderer class can also be used as the argument in the setPrintable
        method of the PrinterJob class. Instead of using the print() methods
        detailed above, a programmer may gain access to the formatting capabilities
        of this class without using its print dialog by creating an instance of
        DocumentRenderer and setting the document to be printed with the
        setDocument() or setJEditorPane(). The Document may then be printed by
        setting the instance of DocumentRenderer in any PrinterJob.
      protected int currentPage = -1;               //Used to keep track of when
                                                    //the page to print changes.
      protected JEditorPane jeditorPane;            //Container to hold the
                                                    //Document. This object will
                                                    //be used to lay out the
                                                    //Document for printing.
      protected double pageEndY = 0;                //Location of the current page
                                                    //end.
      protected double pageStartY = 0;              //Location of the current page
                                                    //start.
      protected boolean scaleWidthToFit = true;     //boolean to allow control over
                                                    //whether pages too wide to fit
                                                    //on a page will be scaled.
    /*    The DocumentRenderer class uses pFormat and pJob in its methods. Note
          that pFormat is not the variable name used by the print method of the
          DocumentRenderer. Although it would always be expected to reference the
          pFormat object, the print method gets its PageFormat as an argument.
      protected PageFormat pFormat;
      protected PrinterJob pJob;
    /*  The constructor initializes the pFormat and PJob variables.
      public DocumentRenderer() {
        pFormat = new PageFormat();
        pJob = PrinterJob.getPrinterJob();
    /*  Method to get the current Document
      public Document getDocument() {
        if (jeditorPane != null) return jeditorPane.getDocument();
        else return null;
    /*  Method to get the current choice the width scaling option.
      public boolean getScaleWidthToFit() {
        return scaleWidthToFit;
    /*  pageDialog() displays a page setup dialog.
      public void pageDialog() {
        pFormat = pJob.pageDialog(pFormat);
    /*  The print method implements the Printable interface. Although Printables
        may be called to render a page more than once, each page is painted in
        order. We may, therefore, keep track of changes in the page being rendered
        by setting the currentPage variable to equal the pageIndex, and then
        comparing these variables on subsequent calls to this method. When the two
        variables match, it means that the page is being rendered for the second or
        third time. When the currentPage differs from the pageIndex, a new page is
        being requested.
        The highlights of the process used print a page are as follows:
        I.    The Graphics object is cast to a Graphics2D object to allow for
              scaling.
        II.   The JEditorPane is laid out using the width of a printable page.
              This will handle line breaks. If the JEditorPane cannot be sized at
              the width of the graphics clip, scaling will be allowed.
        III.  The root view of the JEditorPane is obtained. By examining this root
              view and all of its children, printView will be able to determine
              the location of each printable element of the document.
        IV.   If the scaleWidthToFit option is chosen, a scaling ratio is
              determined, and the graphics2D object is scaled.
        V.    The Graphics2D object is clipped to the size of the printable page.
        VI.   currentPage is checked to see if this is a new page to render. If so,
              pageStartY and pageEndY are reset.
        VII.  To match the coordinates of the printable clip of graphics2D and the
              allocation rectangle which will be used to lay out the views,
              graphics2D is translated to begin at the printable X and Y
              coordinates of the graphics clip.
        VIII. An allocation Rectangle is created to represent the layout of the
              Views.
              The Printable Interface always prints the area indexed by reference
              to the Graphics object. For instance, with a standard 8.5 x 11 inch
              page with 1 inch margins the rectangle X = 72, Y = 72, Width = 468,
              and Height = 648, the area 72, 72, 468, 648 will be painted regardless
              of which page is actually being printed.
              To align the allocation Rectangle with the graphics2D object two
              things are done. The first step is to translate the X and Y
              coordinates of the graphics2D object to begin at the X and Y
              coordinates of the printable clip, see step VII. Next, when printing
              other than the first page, the allocation rectangle must start laying
              out in coordinates represented by negative numbers. After page one,
              the beginning of the allocation is started at minus the page end of
              the prior page. This moves the part which has already been rendered to
              before the printable clip of the graphics2D object.
        X.    The printView method is called to paint the page. Its return value
              will indicate if a page has been rendered.
        Although public, print should not ordinarily be called by programs other
        than PrinterJob.
      public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) {
        double scale = 1.0;
        Graphics2D graphics2D;
        View rootView;
    //  I
        graphics2D = (Graphics2D) graphics;
        disableDoubleBuffering(jeditorPane);
    //  II
        jeditorPane.setSize((int) pageFormat.getImageableWidth(),Integer.MAX_VALUE);
        jeditorPane.validate();
    //  III
        rootView = jeditorPane.getUI().getRootView(jeditorPane);
    //  IV
        if ((scaleWidthToFit) && (jeditorPane.getMinimumSize().getWidth() >
        pageFormat.getImageableWidth())) {
          scale = pageFormat.getImageableWidth()/
          jeditorPane.getMinimumSize().getWidth();
          graphics2D.scale(scale,scale);
    //  V
        graphics2D.setClip((int) (pageFormat.getImageableX()/scale),
        (int) (pageFormat.getImageableY()/scale),
        (int) (pageFormat.getImageableWidth()/scale),
        (int) (pageFormat.getImageableHeight()/scale));
    //  VI
        if (pageIndex > currentPage) {
          currentPage = pageIndex;
          pageStartY += pageEndY;
          pageEndY = graphics2D.getClipBounds().getHeight();
    //  VII
        graphics2D.translate(graphics2D.getClipBounds().getX(),
        graphics2D.getClipBounds().getY());
    //  VIII
        Rectangle allocation = new Rectangle(0,
        (int) -pageStartY,
        (int) (jeditorPane.getMinimumSize().getWidth()),
        (int) (jeditorPane.getPreferredSize().getHeight()));
    //  X
        if (printView(graphics2D,allocation,rootView)) {
          return Printable.PAGE_EXISTS;
        else {
          pageStartY = 0;
          pageEndY = 0;
          currentPage = -1;
          return Printable.NO_SUCH_PAGE;
      /** The speed and quality of printing suffers dramatically if
       *  any of the containers have double buffering turned on.
       *  So this turns if off globally.
       *  @see enableDoubleBuffering
      public static void disableDoubleBuffering(Component c) {
        RepaintManager currentManager = RepaintManager.currentManager(c);
        currentManager.setDoubleBufferingEnabled(false);
      /** Re-enables double buffering globally. */
      public static void enableDoubleBuffering(Component c) {
        RepaintManager currentManager = RepaintManager.currentManager(c);
        currentManager.setDoubleBufferingEnabled(true);
    /*  print(HTMLDocument) is called to set an HTMLDocument for printing.
      public void print(HTMLDocument htmlDocument) {
        setDocument(htmlDocument);
        printDialog();
    /*  print(JEditorPane) prints a Document contained within a JEDitorPane.
      public void print(JEditorPane jedPane) {
        setDocument(jedPane);
        printDialog();
    /*  print(PlainDocument) is called to set a PlainDocument for printing.
      public void print(PlainDocument plainDocument) {
        setDocument(plainDocument);
        printDialog();
    /*  A protected method, printDialog(), displays the print dialog and initiates
        printing in response to user input.
      protected void printDialog() {
        if (pJob.printDialog()) {
          pJob.setPrintable(this,pFormat);
          try {
            pJob.print();
          catch (PrinterException printerException) {
            pageStartY = 0;
            pageEndY = 0;
            currentPage = -1;
            System.out.println("Error Printing Document");
    /*  printView is a recursive method which iterates through the tree structure
        of the view sent to it. If the view sent to printView is a branch view,
        that is one with children, the method calls itself on each of these
        children. If the view is a leaf view, that is a view without children which
        represents an actual piece of text to be painted, printView attempts to
        render the view to the Graphics2D object.
        I.    When any view starts after the beginning of the current printable
              page, this means that there are pages to print and the method sets
              pageExists to true.
        II.   When a leaf view is taller than the printable area of a page, it
              cannot, of course, be broken down to fit a single page. Such a View
              will be printed whenever it intersects with the Graphics2D clip.
        III.  If a leaf view intersects the printable area of the graphics clip and
              fits vertically within the printable area, it will be rendered.
        IV.   If a leaf view does not exceed the printable area of a page but does
              not fit vertically within the Graphics2D clip of the current page, the
              method records that this page should end at the start of the view.
              This information is stored in pageEndY.
      protected boolean printView(Graphics2D graphics2D, Shape allocation,
      View view) {
        boolean pageExists = false;
        Rectangle clipRectangle = graphics2D.getClipBounds();
        Shape childAllocation;
        View childView;
        if (view.getViewCount() > 0 &&
              !view.getElement().getName().equalsIgnoreCase("td")) {
          for (int i = 0; i < view.getViewCount(); i++) {
            childAllocation = view.getChildAllocation(i,allocation);
            if (childAllocation != null) {
              childView = view.getView(i);
              if (printView(graphics2D,childAllocation,childView)) {
                pageExists = true;
        } else {
    //  I
          if (allocation.getBounds().getMaxY() >= clipRectangle.getY()) {
            pageExists = true;
    //  II
            if ((allocation.getBounds().getHeight() > clipRectangle.getHeight()) &&
            (allocation.intersects(clipRectangle))) {
              view.paint(graphics2D,allocation);
            } else {
    //  III
              if (allocation.getBounds().getY() >= clipRectangle.getY()) {
                if (allocation.getBounds().getMaxY() <= clipRectangle.getMaxY()) {
                  view.paint(graphics2D,allocation);
                } else {
    //  IV
                  if (allocation.getBounds().getY() < pageEndY) {
                    pageEndY = allocation.getBounds().getY();
        return pageExists;
    /*  Method to set the content type the JEditorPane.
      protected void setContentType(String type) {
        jeditorPane.setContentType(type);
    /*  Method to set an HTMLDocument as the Document to print.
      public void setDocument(HTMLDocument htmlDocument) {
        jeditorPane = new JEditorPane();
        setDocument("text/html",htmlDocument);
    /*  Method to set the Document to print as the one contained in a JEditorPane.
        This method is useful when Java does not provide direct access to a
        particular Document type, such as a Rich Text Format document. With this
        method such a document can be sent to the DocumentRenderer class enclosed
        in a JEditorPane.
      public void setDocument(JEditorPane jedPane) {
        jeditorPane = new JEditorPane();
        setDocument(jedPane.getContentType(),jedPane.getDocument());
    /*  Method to set a PlainDocument as the Document to print.
      public void setDocument(PlainDocument plainDocument) {
        jeditorPane = new JEditorPane();
        setDocument("text/plain",plainDocument);
    /*  Method to set the content type and document of the JEditorPane.
      protected void setDocument(String type, Document document) {
        setContentType(type);
        jeditorPane.setDocument(document);
    /*  Method to set the current choice of the width scaling option.
      public void setScaleWidthToFit(boolean scaleWidth) {
        scaleWidthToFit = scaleWidth;
    }The sample input file is "mark.html":::
    <html>
    <head>
    <style type="text/css">
    <!--
    ol { list-style-type: decimal; margin-top: 10; margin-left: 50; margin-bottom: 10 }
    u { text-decoration: underline }
    s { text-decoration: line-through }
    p { font-weight: normal; font-size: medium; margin-top: 15 }
    dd p { margin-top: 0; margin-left: 40; margin-bottom: 0 }
    ol li p { margin-top: 0; margin-bottom: 0 }
    address { color: blue; font-style: italic }
    i { font-style: italic }
    h6 { font-weight: bold; font-size: xx-small; margin-top: 10; margin-bottom: 10 }
    h5 { font-weight: bold; font-size: x-small; margin-top: 10; margin-bottom: 10 }
    h4 { font-weight: bold; font-size: small; margin-top: 10; margin-bottom: 10 }
    h3 { font-weight: bold; font-size: medium; margin-top: 10; margin-bottom: 10 }
    dir li p { margin-top: 0; margin-bottom: 0 }
    h2 { font-weight: bold; font-size: large; margin-top: 10; margin-bottom: 10 }
    b { font-weight: bold }
    h1 { font-weight: bold; font-size: x-large; margin-top: 10; margin-bottom: 10 }
    a { color: blue; text-decoration: underline }
    ul li ul li ul li { margin-right: 0; margin-top: 0; margin-left: 0; margin-bottom: 0 }
    menu { margin-top: 10; margin-left: 40; margin-bottom: 10 }
    menu li p { margin-top: 0; margin-bottom: 0 }
    table table { border-color: Gray; margin-right: 0; border-style: outset; margin-top: 0; margin-left: 0; margin-bottom: 0 }
    sup { vertical-align: sup }
    body { margin-right: 0; font-size: 14pt; font-family: SansSerif; color: black; margin-left: 0 }
    ul li ul li ul { list-style-type: square; margin-left: 25 }
    blockquote { margin-right: 35; margin-top: 5; margin-left: 35; margin-bottom: 5 }
    samp { font-size: small; font-family: Monospaced }
    cite { font-style: italic }
    sub { vertical-align: sub }
    em { font-style: italic }
    table table table { border-color: Gray; margin-right: 0; border-style: outset; margin-top: 0; margin-left: 0; margin-bottom: 0 }
    ul li p { margin-top: 0; margin-bottom: 0 }
    ul li ul li { margin-right: 0; margin-top: 0; margin-left: 0; margin-bottom: 0 }
    var { font-weight: bold; font-style: italic }
    table { border-color: Gray; margin-right: 7; border-style: outset; margin-top: 7; margin-left: 7; margin-bottom: 17 }
    dfn { font-style: italic }
    menu li { margin-right: 0; margin-top: 0; margin-left: 0; margin-bottom: 0 }
    strong { font-weight: bold }
    ul { list-style-type: disc; margin-top: 10; margin-left: 50; margin-bottom: 10 }
    center { text-align: center }
    ul li ul { list-style-type: circle; margin-left: 25 }
    kbd { font-size: small; font-family: Monospaced }
    dir li { margin-right: 0; margin-top: 0; margin-left: 0; margin-bottom: 0 }
    th p { font-weight: bold; padding-left: 2; padding-bottom: 3; padding-right: 2; margin-top: 0; padding-top: 3 }
    ul li menu { list-style-type: circle; margin-left: 25 }
    dt { margin-top: 0; margin-bottom: 0 }
    ol li { margin-right: 0; margin-top: 0; margin-left: 0; margin-bottom: 0 }
    li p { margin-top: 0; margin-bottom: 0 }
    strike { text-decoration: line-through }
    dl { margin-top: 10; margin-left: 10; margin-bottom: 10 }
    tt { font-family: Monospaced }
    ul li { margin-right: 0; margin-top: 0; margin-left: 0; margin-bottom: 0 }
    dir { margin-top: 10; margin-left: 40; margin-bottom: 10 }
    pre p { margin-top: 0 }
    th { border-color: Gray; border-style: solid; padding-left: 3; padding-bottom: 3; padding-right: 1; padding-top: 1 }
    pre { font-family: Monospaced; margin-top: 5; margin-bottom: 5 }
    td { border-color: Gray; border-style: inset; padding-left: 3; padding-bottom: 3; padding-right: 1; padding-top: 1 }
    td p { padding-left: 2; padding-bottom: 3; padding-right: 2; margin-top: 0; padding-top: 3 }
    code { font-size: small; font-family: Monospaced }
    small { font-size: x-small }
    big { font-size: x-large }
    -->
    </style>
    </head>
    <body>
    <p style="margin-top: 0">
    </p>
    <table width="500" cellspacing="20" border="1">
    <tr>
    <td height="330" valign="top">
    <table border="0">
    <tr>
    <td>
    <font size="2">This is to certify that [[Client Name]], born
    on [[Client Date of Birth]], of [[Client Residential
                    Address]], was the holder of motor vehicle driver
    licence number [[Client Licence Number]], first issued on
    [[First Issue Date of Holding]] and expired on [[Holding
                    Expiry Date]].<br></font>
    </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    <table width="500" border="2">
    <tr>
    <td>
    <table width="480" border="0">
    <tr>
    <td align="right">
    <font size="2"><br>
    <b>Fred Flintstone<br>Manager</b><br>Records Services Division<br>State
    Police<br>An authorised person for the purposes of the
    Road Act 1986</font>
    </td>
    </tr>
    <tr>
    <td align="left">
    <font size="2"><b>User ID: wzvqv7<br>Dated: 29 November 2006</b>
    </font>
    </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </body>
    </html>

    I have finally cracked it!!!!!!!!!!!!!!!!
    The issue is definitely with Java Sun. "Uneven character spacing when printing JTextComponent"
    It is raised on the http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6488219
    And currently in OPEN state, and raised on 31 Oct 2006 and mentions it was caused by fix 4352983.
    So where do we go from here. It's not good because I have tried all later version of the JVM and the issue is still there.
    Why? Because it hasn't been fixed yet. Read the bug report above, as it gives more insight -- and mentions the workaround is NOT good for existing code.
    So the way forward is to use an earlier version of the JVM 5.
    I download the JVM version 1.5.0 (starting version) and works Ok... I would probably think version prior to 4352983 would be Ok too.
    Please vote for this.... We have a workaround (use older version of the JVM).
    So I am very happy.

Maybe you are looking for

  • Why won't my G5 shut down after upgrading to OS 10.4?

    Hey guys. I have a problem with upgrading my OS to 10.4. I am running a Late 2004 Dual 2 GHz PowerPC G5 with two internal drives. About a month ago, I upgraded the OS to 10.4.3. It was great having spotlight, but the comptuer would refuse to shut its

  • REP:1401 'cf_cf_pb_si_accformula': Fatal PL/SQL error occurred.

    I got this error message , i check forumulla but it is ok nothing is wrong in there.My report builder version is 3.0.5.8.0, Please help me it is urgent.

  • Can't install on mac os 10.9.2

    Why can't I install the adobe creative suite 2 on my new mac os 10.9.2?

  • Distributing Forms in LiveCycle using Acrobat 9

    I have created a four page form with flowable subforms and calculated fields.  The form works fine in preview but for some reason I can't get it to distribute.  The final form is anywhere from 1 to 4 pages depending on the options the user selects/ne

  • Input objects and software monitoring

    Okay, my set up: Macbook intel 1 gig RAM Edirol FA-66 Lacie external drive for audio The issue: The edirol has a peak meter which is just a light that comes on when the signal is too high, however, Logic is still perfectly happy with it, which means