[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

Plug-in Problem.

I have a web-based java application(Applet based). Its quite big appliation containing lot of classes, the jar file is about 500K.  When i am running it without plug-in, its really running OK, though i am missing certain things on some of components made of Swing Classes.  But when i am using it through java plug-in(i tired all versions)i am getting missed things on those swing properties.  But system is getting hanged whenever it tried to refresh my application's screen which is made of Canvas.   Its happening everytime whenever i use repaint(),drawcell() kinda methods.  Its real-time quotes screen i need to update everytime.   The application is working fine on my Linux PC.  The problem is only on Windows?  

Why is like that? What could be the problem? Is it plug-in problem? or my Application? If its my application why its working fine without plug-in? and on Linux with plug-in? I need to report the problem and finalise the things. Can anyone help me in knowing whas going exactly?

0
vinaykn
Asked:
vinaykn
  • 6
  • 4
1 Solution
 
heyhey_Commented:
IMHO your application uses some bad technique for updating screen information.

your applet can be easily fixed, but I cannot help you if you post some snippet of your code - even better - small compilable example that reproduces the problem.
0
 
vinayknAuthor Commented:
Thanks heyhey.  Its a verybig source consists some 100 java files. I am also not permitted to send them all. If you feel OK, then i can send my refereshScreen method(), where always system getting hanged.  You may suggest some, if you find any bad technique.   Can you enlighten me what could be the problem on windows only???
0
 
heyhey_Commented:
> Can you enlighten me what could be the problem on windows only???

different Java VMs have their own bugs / features / implementation features.

post your code, I may find some problem.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
heyhey_Commented:
can you give me link to the working app ?
0
 
vinayknAuthor Commented:
This still in my local network, i think i cant give line. I am trying to send some code. Dont know whether its helpful in finding any problem. Its calling other classes, methods.

synchronized public void refreshScreen(){

{
        String s = " ";
        try{
            if (!shouldRefresh && col != BLANK ){
                if (row == 0 || row%2 == 0)
                    g.setColor(AppColor.displayBackground);
                else
                    g.setColor(AppColor.displayAlternateBackground);
               
                g.fillRect(colPosition[col]+1,
                           rowPosition[row]+1,
                           colPosition[col+1] - colPosition[col]-2,
                           rowPosition[1]-1);
            }

            if(stockInfo == null){
                return;
            }

            switch(col){
                case Quote.NEWS:
                    g.setColor(AppColor.getStockForeColor(stockInfo,col)); //AppData.getStockForeColor(stockInfo,col)); 29/12/1999
                    if(stockInfo.sNewsInd.compareTo("1") == 0){
                        s = "*";
                    }
                    break;
                case Quote.NAME:
                    if(showName){
                        g.setColor(AppColor.getStockBackColor(stockInfo, row)); //AppData.getStockBackColor(stockInfo, row)); 29/12/1999

                        g.fillRect(colPosition[col]+1,
                                   rowPosition[row]+1,
                                   colPosition[col+1]- colPosition[col]-2,
                                   rowPosition[1]-1);
                        g.setColor(AppColor.getStockForeColor(stockInfo,col)); //AppData.getStockForeColor(stockInfo,col)); 29/12/1999
                        s = stockInfo.sName;
                    }
                    else {
                        g.setColor(AppColor.getStockBackColor(stockInfo, row)); //AppData.getStockBackColor(stockInfo, row)); // 29/12/1999

                        g.fillRect(colPosition[col]+1,
                                   rowPosition[row]+1,
                                   colPosition[col+1]- colPosition[col]-2,
                                   rowPosition[1]-1);//Clearing off the display.
                        g.setColor(AppColor.getStockForeColor(stockInfo,Quote.CODE)); //AppData.getStockForeColor(stockInfo,Quote.CODE));//Setting the foreground color 29/12/1999
                        if(stockInfo.sType.length() > 0 &&
                           stockInfo.sType.charAt(0) != 'O' &&
                           stockInfo.sType.charAt(0) != 'F' &&
                           stockInfo.sType.charAt(0) != 'U'){
                            s = AppData.fillUpSpace(stockInfo.sCode,7)+stockInfo.sName;
                            if(s.length() > NAME_LEN){
                                s = s.substring(0,NAME_LEN);
                            }
                        }
                        else {
                            s = stockInfo.sCode;
                        }
                    }
                    break;

                case Quote.VOL:
              case Quote.PREV:
                    if(showPrev == 1){
                    g.setColor(AppColor.getStockForeColor(stockInfo,col));
                        s = AppData.justRight(stockInfo.sPrev,Quote.COL_SIZE[col+1]);
                    }
                    else if (showPrev == 0){
                        g.setColor(AppColor.getStockForeColor(stockInfo,col));
                        if (shouldRefresh == false && hLight == true) {
                            g.setColor(AppColor.displayUpdate);

                            g.fillRect(colPosition[col]+1,
                                       rowPosition[row]+1,
                                       colPosition[col+1] - colPosition[col]-2,
                                       rowPosition[1]-1);
                            hilite[3][row] = counter + 2;

                            g.setColor(AppColor.displayBackground);
                        }
                        else {
                            if (row == 0 || row%2 == 0)
                                g.setColor(AppColor.displayBackground);
                            else
                                g.setColor(AppColor.displayAlternateBackground);

                            g.fillRect(colPosition[col]+1,
                                       rowPosition[row]+1,
                                       colPosition[col+1] - colPosition[col]-2,
                                       rowPosition[1]-1);
                            hilite[3][row] = 0;
                            g.setColor(AppColor.displayForeground);
                        }
                        s = AppData.justRight(stockInfo.sVol, Quote.COL_SIZE[col+1]); // 17/8/1999 , show volume
                    }
                else {
                    g.setColor(AppColor.getStockForeColor(stockInfo,col)); //AppData.getStockForeColor(stockInfo,col)); 29/12/1999
                        s = AppData.justRight(AppData.getInter(StockInfo.CURRENCY_NAME_PREFIX+stockInfo.sCurrency),Quote.COL_SIZE[col+1]); // 28/10/1999
                }
                    break;
                case Quote.HIGH:
                    g.setColor(AppColor.getStockForeColor(stockInfo,col)); //AppData.getStockForeColor(stockInfo,col)); 29/12/1999
                    s = AppData.justRight(stockInfo.sHigh,Quote.COL_SIZE[col+1]);
                    break;
                case Quote.LOW:
                    g.setColor(AppColor.getStockForeColor(stockInfo,col)); //AppData.getStockForeColor(stockInfo,col)); 29/12/1999
                    s = AppData.justRight(stockInfo.sLow,Quote.COL_SIZE[col+1]);
                    break;
                case Quote.LAST:
                    g.setColor(AppColor.getStockForeColor(stockInfo,col)); //AppData.getStockForeColor(stockInfo,col)); 29/12/1999
                    s = AppData.justRight(stockInfo.sLast,Quote.COL_SIZE[col+1]);
                    break;
                case Quote.CHANGE:
                    if(showChange){
                        g.setColor(AppColor.getStockForeColor(stockInfo,col)); //AppData.getStockForeColor(stockInfo,col)); 29/12/1999
                        s = AppData.justRight(stockInfo.sChg,Quote.COL_SIZE[col+1]);
                    }
                    else {
                        g.setColor(AppColor.getFontColor(Float.valueOf(stockInfo.sChgPCent).floatValue(), Float.toString(0))); //AppData.getFontColor(Float.valueOf(stockInfo.sChgPCent).floatValue(), Float.toString(0))); 29/12/1999
                        s = AppData.justRight(stockInfo.sChgPCent+"%",Quote.COL_SIZE[col+1]);
                    }
                    break;
                case Quote.BUY:
                    g.setColor(AppColor.getStockForeColor(stockInfo,col));
                    if(stockInfo.sType.length() > 0 && stockInfo.sType.charAt(0) != 'I'){
                        s = AppData.justRight(stockInfo.sBuy,Quote.COL_SIZE[col+1]);
                    }
                    break;
                case Quote.SELL:
                    g.setColor(AppColor.getStockForeColor(stockInfo,col));
                    if(stockInfo.sType.length() > 0 && stockInfo.sType.charAt(0) != 'I'){
                       s = AppData.justRight(stockInfo.sSell,Quote.COL_SIZE[col+1]);
                    }
                    break;
                case Quote.BUYQTY:
                    g.setColor(AppColor.getStockForeColor(stockInfo,col));
                    if (shouldRefresh == false && hLight == true) {
                        g.setColor(AppColor.displayUpdate);

                        g.fillRect(colPosition[col]+1,
                                   rowPosition[row]+1,
                                   colPosition[col+1] - colPosition[col]-2,
                                   rowPosition[1]-1);
                        hilite[0][row] = counter + 2;
                        g.setColor(AppColor.displayBackground);
                      }
                    else {
                        if (row == 0 || row%2 == 0)
                            g.setColor(AppColor.displayBackground);
                        else
                            g.setColor(AppColor.displayAlternateBackground);
   
                        g.fillRect(colPosition[col]+1,
                                   rowPosition[row]+1,
                                   colPosition[col+1] - colPosition[col]-2,
                                   rowPosition[1]-1);
                        hilite[0][row] = 0;
                        g.setColor(AppColor.displayForeground);
                    }
                    if(stockInfo.sType.length() > 0 && stockInfo.sType.charAt(0) != 'I'){
                        s = AppData.justRight(stockInfo.sBuyQty,Quote.COL_SIZE[col+1]);
                    }
                    break;
                case Quote.SELLQTY:
                    g.setColor(AppColor.getStockForeColor(stockInfo,col));
                    if (shouldRefresh == false && hLight == true) {
                        g.setColor(AppColor.displayUpdate);

                        g.fillRect(colPosition[col]+1,
                                   rowPosition[row]+1,
                                   colPosition[col+1]-colPosition[col]-2,
                                   rowPosition[1]-1);
                        hilite[1][row] = counter + 2;
                        g.setColor(AppColor.displayBackground);
                    }
                    else {
                        if (row == 0 || row%2 == 0)
                            g.setColor(AppColor.displayBackground);
                        else
                            g.setColor(AppColor.displayAlternateBackground);
                       
                        g.fillRect(colPosition[col]+1,
                                   rowPosition[row]+1,
                                   colPosition[col+1]-colPosition[col]-2,
                                   rowPosition[1]-1);
                        hilite[1][row] = 0;
                        g.setColor(AppColor.displayForeground);
                    }
                    if(stockInfo.sType.length() > 0 && stockInfo.sType.charAt(0) != 'I'){
                        s = AppData.justRight(stockInfo.sSellQty,Quote.COL_SIZE[col+1]);
                    }
                    break;
                case Quote.VALUE:
                case Quote.LOTSIZE:
                    g.setColor(AppColor.getStockForeColor(stockInfo,col));
                    if(showVal){
                        if (shouldRefresh ==  false && hLight == true) {
                            g.setColor(AppColor.displayUpdate);

                            g.fillRect(colPosition[col]+1,
                                       rowPosition[row]+1,
                                       colPosition[col+1]-colPosition[col]-2,
                                       rowPosition[1]-1);
                            hilite[2][row] = counter + 2;
                            g.setColor(AppColor.displayBackground);
                        }
                        else {
                                                if (row == 0 || row%2 == 0)
                                g.setColor(AppColor.displayBackground);
                            else
                                g.setColor(AppColor.displayAlternateBackground);
                           

                            g.fillRect(colPosition[col]+1,
                                       rowPosition[row]+1,
                                       colPosition[col+1]-colPosition[col]-2,
                                       rowPosition[1]-1);
                            hilite[2][row] = 0;
                            if(showVal){ //show Value
                                g.setColor(AppColor.displayValue);
                            }
                            else {
                                g.setColor(AppColor.displayForeground);
                            }
                        }
                        s = AppData.justRight(stockInfo.sValue, Quote.COL_SIZE[col+1]);
                    }
                    else {
                        s = AppData.justRight(stockInfo.sLot,Quote.COL_SIZE[col+1]); // show lotSize
                    }
                    break;
                default:
                    return;
            }
            g.drawString(s,colPosition[col]+2,rowPosition[row+1]-5);//18/4/200 -3);
        }
        catch(Exception e){
            System.out.println("Quote.drawCell:"+e.toString()+" col = "+col+" row = "+row);
        }
    }
0
 
heyhey_Commented:
1. what is g ? Do you create this graphics object ?
2. why refreshScreen() is synchronized ?
3. who calls refreshScreen() ?
0
 
vinayknAuthor Commented:
I found these following two methods are calling refreshScreen(); But i didnt find anywhere "g" is globally declared(i am not getting any compiling error).  The applet is connected to back-end server which always pushes real-time data.  Depends on the data it received, it will process the data and repaint() will be called.  "Synchronized" is user for the reason--there is possibility of immediate updatation, before some data is being processed.


public void update(Graphics g) {
        refreshScreen();
    }

    public void paint(Graphics g) {
        refreshScreen();
    }
0
 
heyhey_Commented:
1. synchronizing paint() method is terrible idea. if some other worker Thread blocks inside some synchronized block, your whole UI will stop responding.

2. globally defined Graphics object is very bed idea too.
0
 
heyhey_Commented:
a very quick example on how to implement similar system

group all data needed for rendering into one object
class RendererData
{
   ....
}

in you main rendering class you following code

// contains all information needed for rendering packed in a single object
private RendererData currentData;

// called by the communication Thread when new data is available
public void setData(RendererData newData)
{
  currentData = newData;
  repaint();
}


public void update(Graphics g)
{
  paint(g);
}

public void paint(Graphics g)
{
  paintComponent(g, currentData);
}


private void paintComponent(Graphics g, RendererData theData)
{
   // renders data from 'theData' object on current Graphics object

   // ...  
   
   // you can pu all the code from refreshScreen method here
   // but try using only local varibales, i.e. only data form theData object
}
0
 
vinayknAuthor Commented:
Thanks for the help heyhey. I will implement your suggestions. I will try to improve the code.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now