Need help with paint() within applet

Hi,
I am having some problems in using the paint() method within an applet.
I need to use drawString() in the paint() method.
However, I discovered that when i used drawString() in paint() method.
It clears the background which has other GUI components wipe out.
Pls help, thanx
Sample code:
public class watever extends javax.swing.JApplet {
//initialize some components and variables
public void init() {
//adding of components to contentPane
public void paint(Graphics g) {
g.drawString("The variable is " + sum, 80, 80);
}

super.paint(g) the paint method draws the components to, so if you override it and then never tell it to draw the components they don't get drawn.

Similar Messages

  • I need help with the Quote applet.

    Hey all,
    I need help with the Quote applet. I downloaded it and encoded it in the following html code:
    <html>
    <head>
    <title>Part 2</title>
    </head>
    <body>
    <applet      codebase="/demo/quote/classes" code="/demo/quote/JavaQuote.class"
    width="300" height="125" >
    <param      name="bgcolor"      value="ffffff">
    <param      name="bheight"      value="10">
    <param      name="bwidth"      value="10">
    <param      name="delay"      value="1000">
    <param      name="fontname"      value="TimesRoman">
    <param      name="fontsize"      value="14">
    <param      name="link"      value="http://java.sun.com/events/jibe/index.html">
    <param      name="number"      value="3">
    <param      name="quote0"      value="Living next to you is in some ways like sleeping with an elephant. No matter how friendly and even-tempered is the beast, one is affected by every twitch and grunt.|- Pierre Elliot Trudeau|000000|ffffff|7">
    <param      name="quote1"      value="Simplicity is key. Our customers need no special technology to enjoy our services. Because of Java, just about the entire world can come to PlayStar.|- PlayStar Corporation|000000|ffffff|7">
    <param      name="quote2"      value="The ubiquity of the Internet is virtually wasted without a platform which allows applications to utilize the reach of Internet to write ubiquitous applications! That's where Java comes into the picture for us.|- NetAccent|000000|ffffff|7">
    <param      name="space"      value="20">
    </applet>
    </body>
    </html>When I previewed it in Netscape Navigator, a box with a red X appeared, and this appeared in the console when I opened it:
    load: class /demo/quote/JavaQuote.class not found.
    java.lang.ClassNotFoundException: .demo.quote.JavaQuote.class
         at sun.applet.AppletClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadCode(Unknown Source)
         at sun.applet.AppletPanel.createApplet(Unknown Source)
         at sun.plugin.AppletViewer.createApplet(Unknown Source)
         at sun.applet.AppletPanel.runLoader(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    Caused by: java.io.FileNotFoundException: \demo\quote\JavaQuote\class.class (The system cannot find the path specified)
         at java.io.FileInputStream.open(Native Method)
         at java.io.FileInputStream.<init>(Unknown Source)
         at java.io.FileInputStream.<init>(Unknown Source)
         at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
         at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
         at sun.applet.AppletClassLoader.getBytes(Unknown Source)
         at sun.applet.AppletClassLoader.access$100(Unknown Source)
         at sun.applet.AppletClassLoader$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         ... 10 more
    Exception in thread "Thread-4" java.lang.NullPointerException
         at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
         at sun.plugin.AppletViewer.showAppletException(Unknown Source)
         at sun.applet.AppletPanel.runLoader(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    java.lang.NullPointerException
         at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
         at sun.plugin.AppletViewer.showAppletStatus(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)What went wrong? and how can I make it run correct?
    Thanks,
    Nathan Pinno

    JavaQuote.class is not where your HTML says it is. That is at the relative URL "/demo/quote/".

  • Need HELP with Stick Figure Applet

    I need help with this java program for college....we need to make a applet which displays a stick figure or some type of person using appleviewer..please can someone help me......
    email: [email protected]

    import java.awt.*;
    import java.applet.*;
    public class StickMan extends Applet {
         public void init() {
         public void paint(Graphics g) {
              g.drawOval(....);
              g.drawLine(....);
              g.drawLine(....);
              g.drawLine(....);
              g.drawLine(....);

  • Need help with navigation within a spark list...

    hey guys, so in my application when you click on a list item, it opens up an image, and along with the image a few buttons are created dynamically...
    the image and the url/labels for the dynamic buttons is provided through an xml/xmlListCollection.
    what i need help with is the url or more specifically when you click on one of these dynamic buttons it needs to navigate me to another part of an list or display a certain set of images that is not in my spark list...
    please let me know if this makes no sence
    the code i have is
    <code>
        [Bindable] private var menuXml:XML;
        [Bindable] private var imgList:XMLListCollection = new XMLListCollection();
        [Bindable] private var navControl:XMLListCollection = new XMLListCollection();
        [Bindable] private var fullList:XMLListCollection = new XMLListCollection();
        private var returnedXml:XMLListCollection = new XMLListCollection();
        private var myXmlSource:XML = new XML();
        //[Bindable] private var xmlReturn:Object;
        private var currImage:int = 0;
        //public var userOpProv:XMLListCollection = new XMLListCollection();
        //private var troubleShootProvider:XMLListCollection = new XMLListCollection();
        private function myXml_resultHandeler(event:ResultEvent):void{
            userOptionProvider.source = event.result.apx32.userOptions.children();
            troubleShootProvider.source = event.result.apx32.troubleShooting.children();
            fullList.source = event.result.apx32.children();
            returnedXml.source = event.result[0].children();
            myXmlSource = event.result[0];
        private function myXml_faultHandler(event:FaultEvent):void{
            Alert.show("Error loading XML");
            Alert.show(event.fault.message);
        private function app_creationComplete(event:FlexEvent):void{
            userOptions.scroller.setStyle("horizontalScrollPolicy", ScrollPolicy.OFF);
            myXml.send();
            //trouble.scroller.setStyle("horizontalScrollPolicy", ScrollPolicy.OFF);
            myXml = new HTTPService();
            myXml.url = "modules/apx32/apx32TroubleshootingXml.xml";
            myXml.resultFormat = "e4x";
            myXml.addEventListener(ResultEvent.RESULT, myXml_resultHandeler);
            myXml.addEventListener(FaultEvent.FAULT, myXml_faultHandler);
            myXml.send();
        private function troubleShootChange(event:IndexChangeEvent):void{
            dynamicButtons.removeAllElements();
            navControl.source = troubleShootProvider[event.newIndex].children();
            currImage = 0;
            imgList.source = troubleShootProvider[event.newIndex].images.children();
            definition.source = imgList[currImage].@url;
            if(imgList[currImage].@details == "true"){
                if(imgList[currImage].buttons.@hasButtons == "true"){
                    for each(var item:XML in imgList[currImage].buttons.children()){
                        var newButton:LinkButton = new LinkButton();
                        newButton.label = item.@name;
                        newButton.x = item.@posX;
                        newButton.y = item.@posY;
                        newButton.setStyle("skin", null);
                        newButton.styleName = "dynamicButtonStyle";
                        dynamicButtons.addElement(newButton);
            //var isMultiPage:String = navControl[2]["multiPages"];
            //trace(isMultiPage);
            //        if(isMultiPage){
            if(currImage >= imgList.length - 1){
                next.visible = false;
                back.visible = false;
            else{
                back.visible = false;
                next.visible = true;
        private function customButtonPressed(event:Event):void{
            if(imgList[currImage].button.@changeTo != ""){
        private function userOptionsChange(event:IndexChangeEvent):void{
            dynamicButtons.removeAllElements();
            navControl.source = userOptionProvider[event.newIndex].children();
            currImage = 0;
            imgList.source = userOptionProvider[event.newIndex].images.children();
            definition.source = imgList[currImage].@url;
            if(imgList[currImage].@details == "true"){
                if(imgList[currImage].buttons.@hasButtons == "true"){
                    for each(var item:XML in imgList[currImage].buttons.children()){
                        var newButton:LinkButton = new LinkButton();
                        newButton.label = item.@name;
                        newButton.x = item.@posX;
                        newButton.y = item.@posY;
                        newButton.setStyle("skin", null);
                        newButton.styleName = "dynamicButtonStyle";
                        newButton.addEventListener(MouseEvent.MOUSE_DOWN, customButtonPressed);
                        dynamicButtons.addElement(newButton);
            var isMultiPage:String = navControl[2]["multiPages"];
            if(isMultiPage == "true"){
                if(navControl[2]["next"] == "NEXT STEP"){
                    navContainer.x = 630;
                else{
                    navContainer.x = 640;
                next.label = navControl[2]["next"];
                back.label = navControl[2]["back"];
            if(currImage >= imgList.length - 1){
                next.visible = false;
                back.visible = false;
            else{
                back.visible = false;
                next.visible = true;
        private function nextClickHandler(event:MouseEvent):void{
            currImage += 1;
            dynamicButtons.removeAllElements();
            if(currImage >= imgList.length-1){
                currImage = imgList.length - 1;
                //next.visible = false;
                next.label = "YOU'RE DONE";
            else
                next.label = navControl[2]["next"];
            back.visible = true;
            if(imgList[currImage].@details == "true"){
                if(imgList[currImage].buttons.@hasButtons == "true"){
                    for each(var item:XML in imgList[currImage].buttons.children()){
                        var newButton:LinkButton = new LinkButton();
                        newButton.label = item.@name;
                        newButton.x = item.@posX;
                        newButton.y = item.@posY;
                        newButton.setStyle("skin", null);
                        newButton.styleName = "dynamicButtonStyle";
                        dynamicButtons.addElement(newButton);
            definition.source = imgList[currImage].@url;
        private function backClickHandler(event:MouseEvent):void{
            currImage -= 1;
            dynamicButtons.removeAllElements();
            if(currImage == 0){
                back.visible = false;
            next.visible = true;
            next.label = navControl[2]["next"];
            if(imgList[currImage].@details == "true"){
                if(imgList[currImage].buttons.@hasButtons == "true"){
                    for each(var item:XML in imgList[currImage].buttons.children()){
                        var newButton:LinkButton = new LinkButton();
                        newButton.label = item.@name;
                        newButton.x = item.@posX;
                        newButton.y = item.@posY;
                        newButton.setStyle("skin", null);
                        newButton.styleName = "dynamicButtonStyle";
                        dynamicButtons.addElement(newButton);
            definition.source = imgList[currImage].@url;
    </code>
    i have attached a copy of the xml that i have right now to this post for reference...
    any help will be greatly appretiated!!! i've been stuck on this problem for the last week and my project is due soon
    again thank you in advance...

    hey david... just nevermind my previous post... I was able to subclass a link button, so i now have two variables that get assigned to a link button,
    one is "tabId" <-- contains the information on which tab to swtich to, and the second is, "changeTo"... this contans the label name which it needs to switch to
    I'm just stuck on how to change my selected item in my tabNavigator/list
    the code i have right now is
        private function customButtonPressed(event:Event):void{
            if(event.currentTarget.tabId == "troubleShooting"){
                for each(var item:Object in troubleShootProvider){
                    if(item.@label == event.currentTarget.changeTo){
        private function userOptionsChange(event:IndexChangeEvent):void{
            dynamicButtons.removeAllElements();
            navControl.source = userOptionProvider[event.newIndex].children();
            currImage = 0;
            imgList.source = userOptionProvider[event.newIndex].images.children();
            definition.source = imgList[currImage].@url;
            if(imgList[currImage].@details == "true"){
                if(imgList[currImage].buttons.@hasButtons == "true"){
                    for each(var item:XML in imgList[currImage].buttons.children()){
                        var newButton:customLinkButton = new customLinkButton();
                        newButton.label = item.@name;
                        newButton.tabId = item.@tab;
                        newButton.changeTo = item.@changeTo;
                        newButton.x = item.@posX;
                        newButton.y = item.@posY;
                        newButton.setStyle("skin", null);
                        newButton.styleName = "dynamicButtonStyle";
                        newButton.addEventListener(MouseEvent.MOUSE_DOWN, customButtonPressed);
                        dynamicButtons.addElement(newButton);
            var isMultiPage:String = navControl[2]["multiPages"];
            var videoPresent:String = navControl[1]["videoPresent"];
            if(videoPresent == "true"){
                if(isMultiPage != "true"){
                    navContainer.x = 825;
            if(isMultiPage == "true"){
                if(navControl[2]["next"] == "NEXT STEP"){
                    navContainer.x = 630;
                else{
                    navContainer.x = 640;
                next.label = navControl[2]["next"];
                back.label = navControl[2]["back"];
            if(currImage >= imgList.length - 1){
                next.visible = false;
                back.visible = false;
            else{
                back.visible = false;
                next.visible = true;
    as you know, my xml gets divided into two saperate xmllistcollections one is the userOptionProvider, and the troubleshootingProvider
    as is in the following xml
    <mx:TabNavigator id="tabNav" width="275" tabStyleName="tabStyle" fontWeight="bold" height="400" paddingTop="0"
                             tabWidth="137.5" creationPolicy="all" borderVisible="false">
                <mx:VBox label="USER OPTIONS" width="100%" height="100%" horizontalScrollPolicy="off" verticalScrollPolicy="off">
                    <s:List id="userOptions" width="100%" height="100%" itemRenderer="modules.apx32.myComponents.listRenderer"
                            borderVisible="false" contentBackgroundColor="#e9e9e9"
                            change="userOptionsChange(event)">
                        <s:dataProvider>
                            <s:XMLListCollection id="userOptionProvider" />
                        </s:dataProvider>
                    </s:List>
                </mx:VBox>
                <mx:VBox label="TROUBLESHOOTING">
                    <s:List id="trouble" width="100%" height="100%" itemRenderer="modules.apx32.myComponents.listRenderer"
                            borderAlpha="0" borderVisible="false" contentBackgroundColor="#e9e9e9"
                            change="troubleShootChange(event)">
                        <s:dataProvider>
                            <s:XMLListCollection id="troubleShootProvider" />
                        </s:dataProvider>
                    </s:List>
                </mx:VBox>
            </mx:TabNavigator>
    Im having some trouble updating my list... basically change to the troubleshooting tab, and then select the one that i need...
    hopefully that makes sence...

  • Need help with paint (here my code)

    hi, i have problem with my paint method, if i put super.paint(g); all work perfectly but when you draw the program refresh all time, and does like flash effect taht i dotn want (test the code you'll see what im talking about) , and if i dont put super.paint(g) my component didnt paint... please help me, i know taht is a little bug, but i didnt have any kind of problem with swing before..
    thx
    //Debut imports
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.net.*;
    import javax.swing.border.*;
    import javax.swing.event.*;
    //Fin imports
    //  Class: soudure
    public class soudure extends JApplet implements MouseListener, MouseMotionListener, ChangeListener
        //Debut Declarations
        boolean dessinConfig = false; //Savoir quand on utilise paint pour config
        Image img; //Image a dessiner
        int x = -1; //Sert pour savoir le point x de la souris
        int y = -1; //Sert pour savoir le point y de la souris
        int ovalHeight = 10; //Set la hauteur de l'oval
        int ovalWidth = 10; //Set la largeur de l'oval
        JLabel xCoord, //Coordonner de la souris X
               yCoord, //Coordonner de la souris Y
               lVoltage, //Identifie le voltage
               lAmperage; //Indeitifie l'amperage
        JPanel config, //Panel de configuration
               dessin, //Panel de dessin
               info; //Panel d'info
        JSlider voltage, //Set le voltage
                amperage; //Set l'amperage
        Vector sauvOvalXY; //Sauvegarde les points x et y des ovals
        Vector sauvOvalWH;  //Sauvegarde les largeur et hauteur des ovals
        //Fin Declarations
        //  Fonction: init()
        public void init()
            //Debut Initialisations
            config = new JPanel();   
            dessin = new JPanel();
            info = new JPanel();
            xCoord = new JLabel("X Coord.: ");
            yCoord = new JLabel("Y Coord.: ");
            voltage = new JSlider(JSlider.VERTICAL, 15,30,15);
            lVoltage = new JLabel("Voltage  15 :");
            amperage = new JSlider(JSlider.VERTICAL, 100,400,100);
            lAmperage = new JLabel("Amperage  100 :");
    //      img = new Image();
          sauvOvalXY = new Vector();
          sauvOvalWH = new Vector();
            //Fin Initialisations
            //Debut set Background
            config.setBackground(Color.lightGray);       
            dessin.setBackground(Color.white);
            //Fin set Background
            //Debut set layout
            dessin.setLayout(null);
            //Fin Set Layout
            //Add les listener
            dessin.addMouseListener(this);
            dessin.addMouseMotionListener(this);
            voltage.addChangeListener(this);
            amperage.addChangeListener(this);       
            //Fin Add listener
            //Divers settings
            dessin.setBorder(new MatteBorder(1,1,1,1,Color.black));
            config.setBorder(new MatteBorder(1,1,1,1,Color.black));
            info.setBorder(new MatteBorder(1,1,1,1,Color.black));
            voltage.setSize(20,10);
            amperage.setSize(20,10);
            //Set Size
            getContentPane().setSize(500,500);
            config.setBounds(0,0,500,100);
            dessin.setBounds(0,100,500,300);
            info.setBounds(0,400,500,100);       
            //Fin set Size
            //Debut ajout Panel
            info.add(xCoord);
            info.add(yCoord);
            config.add(lVoltage);
            config.add(voltage);
            config.add(lAmperage);
            config.add(amperage);
            getContentPane().add(config,"North");
            getContentPane().add(dessin,"Center");
            getContentPane().add(info,"South");       
            //Fin ajout Panel       
        //Fin Fonction init()
        //  Fonction: mouseClicked(MouseEvent)
        public void mouseClicked(MouseEvent e)
        //Fin Fonction mouseClicked(MouseEvent)
        //  Fonction: mouseDragged(MouseEvent)
        public void mouseDragged(MouseEvent e)
            //Prend l'objet sur lequel l'event est fait
            Object obj = e.getSource();
            x = e.getX();
            y = e.getY();
            //JPanel Dessin
            if(obj == dessin)
                repaint();
                positionSouris(e);
            //Fin JPanel dessin
        //Fin Fonction mouseDragged(MouseEvent)
        //  Fonction: mouseEntered(MouseEvent)
        public void mouseEntered(MouseEvent e)
            //positionSouris(e);
        //Fin Fonction mouseEntered(MouseEvent)
        //  Fonction: mouseExited(MouseEvent)
        public void mouseExited(MouseEvent e)
            //Met les coords de la souris a 0
            xCoord.setText("X Coord.: 0");
            yCoord.setText("Y Coord.: 0");
        //Fin Fonction mouseExited(MouseEvent)
        //  Fonction: mouseMoved(MouseEvent)
        public void mouseMoved(MouseEvent e)
            positionSouris(e);
        //Fin Fonction mouseMoved(MouseEvent)
        //  Fonction: mousePressed(MouseEvent)
        public void mousePressed(MouseEvent e)
        //Fin Fonction mousePressed(MouseEvent)
        //  Fonction: mouseReleased(MouseEvent)
        public void mouseReleased(MouseEvent e)
        //Fin Fonction mouseReleased(MouseEvent)
        //  Fonction: paint(Graphics)
        public void paint(Graphics g)
            super.paint(g);
            g = dessin.getGraphics();
            //Verifie si rien n'a encore ete dragger
            if(x != -1)
                //Sauvegarde les infos
                sauvOvalXY.add(new Point(x,y));
                sauvOvalWH.add(new Point(ovalWidth,ovalHeight));
                //Dessine les sauvegarde
                int size = sauvOvalXY.size();
                for(int i=0;i<size;i++)
                    Point tmpXY = (Point)sauvOvalXY.get(i);
                    Point tmpWH = (Point)sauvOvalWH.get(i);
                    g.fillOval(tmpXY.x,tmpXY.y,tmpWH.x,tmpWH.y);
                g.fillOval(x,y,this.ovalWidth,this.ovalHeight);
    /*        //Si dessine pour panel config
            if(dessinConfig)
                g = config.getGraphics();
                g.drawImage(img,0,0,100,100,this);
               // dessinConfig = false;
        //Fin Fonction paint(Graphics)
        //  Fonction: positionSouris(MouseEvent)
        public void positionSouris(MouseEvent e)
            int tmpX = e.getX();
            int tmpY = e.getY();
            xCoord.setText("X Coord.: " + Integer.toString(tmpX));
            yCoord.setText("Y Coord.: " + Integer.toString(tmpY));
        //Fin Fonction positionSouris(MouseEvent)
        //  Fonction: stateChanged(ChangeEvent)
        public void stateChanged(ChangeEvent e)
            //Verifie lobject actuel
            Object obj = e.getSource();
            //Voltage
            if(obj == voltage)
                int tmpVoltage = voltage.getValue();
                lVoltage.setText("Voltage  " + Integer.toString(tmpVoltage) + " :");
            //Fin voltage
            else
                //Voltage
                if(obj == amperage)
                    int tmpAmperage = amperage.getValue();
                    lAmperage.setText("Amperage  " + Integer.toString(tmpAmperage) + " :");
                //Fin voltage       
        //Fin Fonction stateChanged(ChangeEvent)
    }

    Hi,
    For Swing components you need to override the paintComponent method instead of paint. In your case you can't do that with the approach you have taken. Here is how you can do it:
    1. Remove your paint method
    2. Change your creation of the dessin JPanel and override its' paintComponent method using an anonymous class.
        dessin = new JPanel()
                    public void paintComponent( Graphics g )   
                      super.paintComponent(g);      
                      //Verifie si rien n'a encore ete dragger 
                      if(x != -1)       
                        //Sauvegarde les infos
                        sauvOvalXY.add(new Point(x,y));
                        sauvOvalWH.add(new Point(ovalWidth,ovalHeight));
                        //Dessine les sauvegarde          
                        int size = sauvOvalXY.size(); 
                        for(int i=0;i<size;i++)         
                          Point tmpXY = (Point)sauvOvalXY.get(i);
                          Point tmpWH = (Point)sauvOvalWH.get(i);
                          g.fillOval(tmpXY.x,tmpXY.y,tmpWH.x,tmpWH.y);
                        g.fillOval(x,y,ovalWidth,ovalHeight);
                 };This will allow you to override the correct method and still use all of your applet class variables. Notice that I have removed the line getting the graphics of dessin because it is now being passed into the paintComponent method.
    The two steps above should remove any flashing that you may have had.
    Regards,
    Manfred.

  • Need help with division within a query

    Hello all~
    I am trying to divide these two columns to get a % of case numbers involving an accident. Im pretty sure you need to use decode to avoid the divide by 0 error but not sure how to implement this within my query. When i run this query below, it gives me the result of "1", which is not correct. Can someone help me please?
    Oracle Version 10g
    ACCIDENT is a datatype VARCHAR
    CASE_NUMBER is a datatype VARCHAR
    select to_char(count(ACCIDENT),'999,999,999') as "ACCIDENT",
    to_char(COUNT(CASE_NUMBER),'999,999,999')as "CASE NUMBER",
    round(ratio_to_report(count(accident))
    OVER()*100,2)as "%"
    from      "PURSUIT"
    WHERE ACCIDENT = 'Y'
    AND
    (:P1_BEG_DATE IS NULL AND :P1_END_DATE IS NULL
    OR
    pursuit_date BETWEEN to_date(:p1_beg_date,'MM/DD/YYYY') and to_date
    (:p1_end_date,'MM/DD/YYYY'))
    AND(:P1_TROOP=pursuit.officer_troop OR :p1_troop IS NULL) 
    AND(:P1_RADIO=pursuit.officer_radio OR :p1_radio IS NULL)
    group by case_numberThanks
    Deanna

    Are you sure that the ANDs and ORs in your WHERE clause will take precedence properly?
    Also, if you always select only cases where there has been an accident, what percentage would you like to display? Surely in this case the percentage of cases involving in accident in cases where there was an accident.. is 100%?
    as a simpler example
    SELECT
      accident,
      ROUND(RATIO_TO_REPORT(count(*)) OVER() * 100)
    FROM
      pursuit
    GROUP BY
      accidentHere's a trick to neaten up those IS NULLs:
    SELECT
      accident,
      ROUND(RATIO_TO_REPORT(count(*)) OVER() * 100)
    FROM
      pursuit
    WHERE
      pursuit_date >= COALESCE(:p1_beg_date, pursuit_date) AND
      pursuit_date <= COALESCE(:p1_end_date, pursuit_date) AND
      officer_troop LIKE :p1_troop AND
      offcier_radio LIKE :p1_radio
    GROUP BY
      accidentTo wildcard a date, simply pass NULL in; the coalesce will replace the null with the pursuit_date from the record (thus the >= and <= becomes true)
    To wildcard the troop or the radio, simply pass a '%' symbol as the value of the parameter. If the front end code is already set up to pass nulls, use the COALESCE trick above

  • Need help with select within select - daterange

    I use Crystal Reports v12.3.0.601 - I am a beginner.
    Problem:
    TABLE: ACCOUNTBILLFEE
    Columns are   
    FOLDERRSN
    STAMPDATE
    BILLNUMBER
    PAYMENTAMOUNT
    There are over 500,000 rows/ records...
    And I need to report the FOLDERRSN which has at least one {ACCOUNTBILLFEE.STAMPDATE} in DateTime
    (2014, 05, 01, 00, 00, 01) to DateTime (2014, 05, 31, 23, 59, 59)
    Out-put required is:
    FOLDERSN | STAMPDATE | BILLNUMBER   | PAYMENTAMOUNT
    Group by FOLDERRSN
    1010234               May01,2014                 1111                      25000
                                  May25, 2014                1112                       5000
                                  Jan 05, 2013                  998                          500
    1034567                May5, 2014                11325                       5000
    1033999                May15, 2014               6752                       15000
                                  Dec5 , 2011                1132                       25000
    Please help -
    The critical part for me, is to display  payments not within the date range in 'select expert' statement.
    Currenlty my report reflects only payments for FOLDERRSN, where {ACCOUNTBILLFEE.STAMPDATE} in DateTime
    (2014, 05, 01, 00, 00, 01) to DateTime (2014, 05, 31, 23, 59, 59) and not other payments outside the date range specified.
    Thank you for your time.

    Hi Abilash,
    This worked !!!
    My brother helped me with it here....ofcourse you have intiated the intial idea.
    It worked when i used the following SQL at 'Add Command'
    Select * from DATABASE_NAME.ACCOUNTBILLFEE A
    Where A.FOLDERSN = any ( select B.FOLDERSN from DATABASE_NAME.ACCOUNTBILLFEE B
    where B.STAMPDATE >= TO_DATE('20140501', 'YYYYMMDD')
    AND  B.STAMPDATE <= TO_DATE('20140531', 'YYYYMMDD'))
    Excellent support - Thank you so much for your immediate attention and response.
    I know, how hard it is to understand someones requirement and suggest solutions.
    You are the best and most helpful I have ever come across in my life.
    Thank you for your kind heart and extending help to me.
    Regs,
    Sridhar Lam

  • Need help with buttons in applet

    stupid question maybe but i'm a beginner, and hey..there are no stupid questions, right? well, i may prove that wrong...anyway...
    I can't relocate a button, or any other component for that matter. When I try to make a simple applet with just one button showing, then it works perfect...but when I make the applet a little bigger with some graphcis and text, the setLocation() and setSize() methods don't work. the wierd part is that I don't get an error message, the compiler just ignores those lines...so it seems anyway.
    If anyone can help me I'd be very greatful
    thanx a lot

    Do you know there are 5 layout managers in java. It is probably worth looking through each one and the commands they use.
    The layout is determined by two things:
    1.position Components are added
    2.Layout manager used
    Ive never had to use setLocation() and setSize() as the layouts do it for you:
    1.Flowlayout: which is the default pane. e.g.
    setLayout(new Flowlayout()).
    2.GridLayout: postions panels into rows and columns
    b.GridBagLayout
    3.Borderlayout(NORTH,SOUTH,EAST,WEST and CENTER) postions in applet.
    4.CardLayout(a bit like a slideshow)
    5.Insets() which is used to determine top,bottom,left and right.
    Don't bother about 4 or 5 yet. But definitly have a look at the other 3.
    e.g. setLayout(new BorderLayout());
    add("North", new Button("ok"));
    add("CENTER", new Button("Exit");
    etc..

  • Need help with classes in Applets and drawing buildings.

    I'm trying to create an Applet that draws a starfield (I got that right) and then searches for any parameters in the Applet tag. The Applet then draws as many buldings as there are parameters in the Applet tag, and uses the number in the parameter as the height. I have it working OK, but it won't draw the buildings. Here is me code:
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.geom.*;
    import java.util.*;
    import javax.swing.*;
    public class Skyline extends Applet {
    public void init() {
    setBackground(Color.black);
    public void paint(Graphics g) {
    Graphics2D pen = (Graphics2D) g;
    Random generator = new Random();
    Stars starField = new Stars();
    starField.drawStars(pen, getWidth(), getHeight());
    int n = 1;
    String param = null;
    while((param = getParameter("param" + n)) != null) {
    n++;
    int startX = 0;
    int startY = getHeight();
    int height = 0;
    int width = getWidth() / (n + 2);
    Building structure = new Building();
    structure.drawBuilding(pen, height, width, startX, startY, n);
    class Stars {
    public void drawStars(Graphics2D pen, int Width, int Height) {
    Random generator = new Random();
    int runs = 1;
    while (runs <= 1000) {
    int Xcord = generator.nextInt(Width - 3);
    int Ycord = generator.nextInt(Height - 3);
    Ellipse2D.Double star
    = new Ellipse2D.Double(Xcord, Ycord, 3, 3);
    pen.setColor(Color.white);
    pen.fill(star);
    runs++;
    class Building {
    public void drawBuilding(Graphics2D pen, int height, int width, int startX, int startY, int n) {
    Random generator = new Random();
    int n2 = 1;
    int runs = 1;
    String input = "";
    int red = generator.nextInt(100),
    green = generator.nextInt(100),
    blue = generator.nextInt(100);
    pen.setColor(new Color(red, green, blue));
    while (runs <= n) {
    input = getParameter("building" + n2);
    height = Integer.parseInt(input);
    height = startY - height;
    Rectangle building = new Rectangle(startX, startY, height, width);
    pen.fill(building);
    startY = startY + width;
    n2++;
    runs++;
    Can anyone help me?

    That didn't work, so I looked at the code again and found some errors. I decided to rewrite it, here is the updated code...
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.geom.*;
    import java.util.*;
    import javax.swing.*;
    public class Skyline extends Applet {
    public void init() {
    setBackground(Color.black);
    public void paint(Graphics g) {
    Graphics2D pen = (Graphics2D) g;
    Random generator = new Random();
    Stars starField = new Stars();
    starField.drawStars(pen, getWidth(), getHeight());
    Building structure = new Building();
    structure.drawBuilding(pen);
    class Stars {
    public void drawStars(Graphics2D pen, int Width, int Height) {
    Random generator = new Random();
    int runs = 1;
    while (runs <= 1000) {
    int Xcord = generator.nextInt(Width - 3);
    int Ycord = generator.nextInt(Height - 3);
    Ellipse2D.Double star
    = new Ellipse2D.Double(Xcord, Ycord, 3, 3);
    pen.setColor(Color.white);
    pen.fill(star);
    runs++;
    class Building {
    public void drawBuilding(Graphics2D pen) {
    Random generator = new Random();
    int n = 1;
    int n2 = 1;
    int runs = 1;
    String input = "";
    String param = "";
    while ((param = getParameter("building" + n)) != null) {
    n++;
    int height = getHeight();
    int width = getWidth();
    int startX = 0;
    int startY = height;
    int red = generator.nextInt(100),
    green = generator.nextInt(100),
    blue = generator.nextInt(100);
    pen.setColor(new Color(red, green, blue));
    while (runs <= n) {
    height = getHeight();
    input = getParameter("building" + n2);
    height = Integer.parseInt(input);
    height = startY - height;
    Rectangle building = new Rectangle(startY, startX, height, width);
    pen.fill(building);
    startX = startX + width;
    n2++;
    runs++;
    I can get it to draw one large black building, but that's it.

  • Help with images within applets

    I created a card game applet which calls images placed within the same directory. In appletviewer the game runs fine,not in browsers. I downloaded the browser plugin since i use swing classes. If I remove the image the applet loads up without the grafix. Here is the IO error generated. I thought applets can read files within the same directory and sub directories? Would creating a jar file solve this problem? Anyhelp would be appreciated.
    java.security.AccessControlException: access denied (java.io.FilePermission main2.gif read)

    When running in a browser, your applet must be signed in order to be able to access local resources. Check out the "Signed Applets" forum for many discussions about this, as well as methods for signing applets.

  • Need help with a Java applet

    newGame.setActionCommand("newgame:1");
    newGame2.setActionCommand("newgame:2");
    //other lines of code in a previous method, rest of code not shown
    public void actionPerformed(ActionEvent evnt)
    int i;
    int j;
    String sp = new String(":");
    String[] cmd = evnt.getActionCommand().split(sp);
    // rest of code not shown
    // **When I get to that lastline, it tells me that the split() method could not be found in class String.  If you would like to see the rest of my code in order to help me, I will post anything to figure out what this problem is.*//

    "because(sic)" was supposed to be "became" ... anyway, in the API doco, when it says that something is "since 1.4", for example, it means from that point onward. So 1.5.x is good - but I wanted to warn you off v.1.3.x in case that was where you were running this.

  • Need Help with 2 Player Applet Game w Server

    Hi , I am quite rush for a game project which is about batt|e ship .
    The game judge is the ServerModel
    Firstly
    1) Player 1 , Player 2 press connect to establish connection.
    2) Connection sucessful prompt for choosing of coordinate
    3) Player 1 select a Map coor via mouse click and so do player 2
    4) Game will start once both choosed the coor
    5) The Game will run till Winner is determine
    => Winner is determine by <=
    Player 1's Turn select a Map Coor and it HITS player 2 Ship spot = win.
    viceversa for player 2.
    => My program problem , it is in version e, i been fixing it but cant find a way to fix my game to LOOP till Winner is determine.
    The program will stop displaying MyTurn on the JLabel status and mouse event seem no longer work after ROUND 1 pass , which is player 1 click on player 2 and player 2 click back on player 1.
    can help me check my code?
    Special Jar used is
    ClientModel.jar =>
    method of readFromServer ( Return String)
    and
    sendToServer(Java.Lang.String)

    baoky, you've been told before to use code tags when posting code:
    http://forum.java.sun.com/thread.jspa?threadID=5197453&messageID=9780961#9780961
    If you continue to refuse to do so, I (and many others here) will refuse to look at your code. Did you even bother to read responses in your previous thread??

  • Need help with advanced applet

    I need help with designing an applet as follows. Can someone give me a basic layout of code and material so i can fill in the rest or at leats give me some hints so i can get started since i am like no good at applets.
    Design and implement an applet that graphically displays the processing
    of a selection sort. Use bars of various heights to represent
    the values being sorted. Display the set of bars after each swap. Put
    a delay in the processing of the sort to give the human observer a
    chance to see how the order of the values changes.
    heres a website that does something similar
    http://www.cs.ubc.ca/spider/harrison/Java/sorting-demo.html

    elasolova wrote:
    i will not help you this time. but if you buy me a candy maybe i can reconsider the issue. :PI suggest an all-day sucker.

  • Need help with applet servlet communication .. not able to get OutputStream

    i am facing problem with applet and servlet communication. i need to send few image files from my applet to the servlet to save those images in DB.
    i need help with sending image data to my servlet.
    below is my sample program which i am trying.
    java source code which i am using in my applet ..
    public class Test {
        public static void main(String argv[]) {
            try {
                    URL serverURL = new URL("http://localhost:8084/uploadApp/TestServlet");
                    URLConnection connection = serverURL.openConnection();
                    Intermediate value=new Intermediate();
                    value.setUserId("user123");
                    connection.setDoInput(true);
                    connection.setDoOutput(true);
                    connection.setUseCaches(false);
                    connection.setDefaultUseCaches(false);
                    // Specify the content type that we will send binary data
                    connection.setRequestProperty ("Content-Type", "application/octet-stream");
                    ObjectOutputStream outputStream = new ObjectOutputStream(connection.getOutputStream());
                    outputStream.writeObject(value);
                    outputStream.flush();
                    outputStream.close();
                } catch (MalformedURLException ex) {
                    System.out.println(ex.getMessage());
                }  catch (IOException ex) {
                        System.out.println(ex.getMessage());
    }servlet code here ..
    public class TestServlet extends HttpServlet {
         * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
         * @param request servlet request
         * @param response servlet response
         * @throws ServletException if a servlet-specific error occurs
         * @throws IOException if an I/O error occurs
        protected void processRequest(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
             System.out.println(" in servlet -----------");
            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out = response.getWriter();
            ObjectInputStream inputFromApplet = null;
            Intermediate aStudent = null;
            BufferedReader inTest = null;
            try {         
                // get an input stream from the applet
                inputFromApplet = new ObjectInputStream(request.getInputStream());
                // read the serialized object data from applet
                data = (Intermediate) inputFromApplet.readObject();
                System.out.println("userid in servlet -----------"+ data.getUserId());
                inputFromApplet.close();
            } catch (Exception e) {
                e.printStackTrace();
                System.err.println("WARNING! filename.path JNDI not found");
            } finally {
                out.close();
        @Override
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            System.out.println(" in foGet -----------");
            processRequest(request, response);
         * Handles the HTTP <code>POST</code> method.
         * @param request servlet request
         * @param response servlet response
         * @throws ServletException if a servlet-specific error occurs
         * @throws IOException if an I/O error occurs
        @Override
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            System.out.println(" in doPost -----------");
            processRequest(request, response);
         * Returns a short description of the servlet.
         * @return a String containing servlet description
        @Override
        public String getServletInfo() {
            return "Short description";
        }// </editor-fold>
    }the Intermediate class ..
    import java.io.Serializable;
    public class Intermediate implements Serializable{
    String userId;
        public String getUserId() {
            return userId;
        public void setUserId(String userId) {
            this.userId = userId;
    }

    Hi,
    well i am not able to get any value from connection.getOutputStream() and i doubt my applet is not able to hit the servlet. could you review my code and tell me if it has some bug somewhere. and more over i want to know how to send multiple file data from applet to servlet . i want some sample or example if possible.
    do share if you have any experience of this sort..
    Thanks.

  • Help with Paint program.

    Hello. I am somewhat new to Java and I was recently assigned to do a simple paint program. I have had no trouble up until my class started getting into the graphical functions of Java. I need help with my program. I am supposed to start off with a program that draws lines and changes a minimum of 5 colors. I have the line function done but my color change boxes do not work and I am able to draw inside the box that is supposed to be reserved for color buttons. Here is my code so far:
    // Lab13110.java
    // The Lab13 program assignment is open ended.
    // There is no provided student version for starting, nor are there
    // any files with solutions for the different point versions.
    // Check the Lab assignment document for additional details.
    import java.applet.Applet;
    import java.awt.*;
    public class Lab13110 extends Applet
         int[] startX,startY,endX,endY;
         int currentStartX,currentStartY,currentEndX,currentEndY;
         int lineCount;
         Rectangle red, green, blue, yellow, black;
         int numColor;
         Image virtualMem;
         Graphics gBuffer;
         int rectheight,rectwidth;
         public void init()
              startX = new int[100];
              startY = new int[100];
              endX = new int[100];
              endY = new int[100];
              lineCount = 0;
              red = new Rectangle(50,100,25,25);
              green = new Rectangle(50,125,25,25);
              blue = new Rectangle(50,150,25,25);
              yellow = new Rectangle(25,112,25,25);
              black = new Rectangle(25,137,25,25);
              numColor = 0;
              virtualMem = createImage(100,600);
              gBuffer = virtualMem.getGraphics();
              gBuffer.drawRect(0,0,100,600);
         public void paint(Graphics g)
              for (int k = 0; k < lineCount; k++)
                   g.drawLine(startX[k],startY[k],endX[k],endY[k]);
              g.drawLine(currentStartX,currentStartY,currentEndX,currentEndY);
              g.setColor(Color.red);
              g.fillRect(50,100,25,25);
              g.setColor(Color.green);
              g.fillRect(50,125,25,25);
              g.setColor(Color.blue);
              g.fillRect(50,150,25,25);
              g.setColor(Color.yellow);
              g.fillRect(25,112,25,25);
              g.setColor(Color.black);
              g.fillRect(25,137,25,25);
              switch (numColor)
                   case 1:
                        g.setColor(Color.red);
                        break;
                   case 2:
                        g.setColor(Color.green);
                        break;
                   case 3:
                        g.setColor(Color.blue);
                        break;
                   case 4:
                        g.setColor(Color.yellow);
                        break;
                   case 5:
                        g.setColor(Color.black);
                        break;
                   case 6:
                        g.setColor(Color.black);
                        break;
              g.setColor(Color.black);
              g.drawRect(0,0,100,575);
         public boolean mouseDown(Event e, int x, int y)
              currentStartX = x;
              currentStartY = y;
              if(red.inside(x,y))
                   numColor = 1;
              else if(green.inside(x,y))
                   numColor = 2;
              else if(blue.inside(x,y))
                   numColor = 3;
              else if(yellow.inside(x,y))
                   numColor = 4;
              else if(black.inside(x,y))
                   numColor = 5;
              else
                   numColor = 6;
              repaint();
              return true;
         public boolean mouseDrag(Event e, int x, int y)
              int Rectheight = 500;
              int Rectwidth = 900;
              currentEndX = x;
              currentEndY = y;
              Rectangle window = new Rectangle(0,0,900,500);
              //if (window.inside(Rectheight,Rectwidth))
                   repaint();
              return true;
         public boolean mouseUp(Event e, int x, int y)
              int Rectheight = 500;
              int Rectwidth = 900;
              startX[lineCount] = currentStartX;
              startY[lineCount] = currentStartY;
              endX[lineCount] = x;
              endY[lineCount] = y;
              lineCount++;
              Rectangle window = new Rectangle(0,0,900,500);
              if (window.inside(Rectheight,Rectwidth))
                   repaint();
              return true;
         public void Rectangle(Graphics g, int x, int y)
              g.setColor(Color.white);
              Rectangle screen = new Rectangle(100,0,900,600);
    }If anyone could point me in the right direction of how to go about getting my buttons to work and fixing the button box, I would be greatly appreciative. I just need to get a little bit of advice and I think I should be good after I get this going.
    Thanks.

    This isn't in any way a complete solution, but I'm posting code for a mouse drag outliner. This may be preferable to how you are doing rectangles right now
    you are welcome to use and modify this code but please do not change the package and make sure that you tell your teacher where you got it from
    MouseDragOutliner.java
    package tjacobs.ui;
    import java.awt.BasicStroke;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Container;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Point;
    import java.awt.Stroke;
    import java.awt.event.*;
    import java.util.ArrayList;
    import java.util.Iterator;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.SwingUtilities;
    * See the public static method addAMouseDragOutliner
    public class MouseDragOutliner extends MouseAdapter implements MouseMotionListener {
         public static final BasicStroke DASH_STROKE = new BasicStroke(1.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL, 10.0f, new float[] {8, 8}, 0);
         private boolean mUseMove = false;
         private Point mStart;
         private Point mEnd;
         private Component mComponent;
         private MyRunnable mRunner= new MyRunnable();
         private ArrayList mListeners = new ArrayList(1);
         public MouseDragOutliner() {
              super();
         public MouseDragOutliner(boolean useMove) {
              this();
              mUseMove = useMove;
         public void mouseDragged(MouseEvent me) {
              doMouseDragged(me);
         public void mousePressed(MouseEvent me) {
              mStart = me.getPoint();
         public void mouseEntered(MouseEvent me) {
              mStart = me.getPoint();
         public void mouseReleased(MouseEvent me) {
              Iterator i = mListeners.iterator();
              Point end = me.getPoint();
              while (i.hasNext()) {
                   ((OutlineListener)i.next()).mouseDragEnded(mStart, end);
              //mStart = null;
         public void mouseMoved(MouseEvent me) {
              if (mUseMove) {
                   doMouseDragged(me);
         public     void addOutlineListener(OutlineListener ol) {
              mListeners.add(ol);
         public void removeOutlineListener(OutlineListener ol) {
              mListeners.remove(ol);
         private class MyRunnable implements Runnable {
              public void run() {
                   Graphics g = mComponent.getGraphics();
                   if (g == null) {
                        return;
                   Graphics2D g2 = (Graphics2D) g;
                   Stroke s = g2.getStroke();
                   g2.setStroke(DASH_STROKE);
                   int x = Math.min(mStart.x, mEnd.x);
                   int y = Math.min(mStart.y, mEnd.y);
                   int w = Math.abs(mEnd.x - mStart.x);
                   int h = Math.abs(mEnd.y - mStart.y);
                   g2.setXORMode(Color.WHITE);
                   g2.drawRect(x, y, w, h);
                   g2.setStroke(s);
         public void doMouseDragged(MouseEvent me) {
              mEnd = me.getPoint();
              if (mStart != null) {
                   mComponent = me.getComponent();
                   mComponent.repaint();
                   SwingUtilities.invokeLater(mRunner);
         public static MouseDragOutliner addAMouseDragOutliner(Component c) {
              MouseDragOutliner mdo = new MouseDragOutliner();
              c.addMouseListener(mdo);
              c.addMouseMotionListener(mdo);
              return mdo;
         public static interface OutlineListener {
              public void mouseDragEnded(Point start, Point finish);
         public static void main(String[] args) {
              JFrame f = new JFrame("MouseDragOutliner Test");
              Container c = f.getContentPane();
              JPanel p = new JPanel();
              //p.setBackground(Color.BLACK);
              c.add(p);
              addAMouseDragOutliner(p);
              f.setBounds(200, 200, 400, 400);
              f.addWindowListener(new WindowClosingActions.Exit());
              f.setVisible(true);
    }

Maybe you are looking for