CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Join Date
    Apr 1999
    Posts
    25

    Printing after an Event, from the Browser...

    Hi,

    I am developing an applet class that implements MouseMotionListener. On mouse over on top of a polygon, I display some text corresponding to that polygon. Once the text is displayed, it remains displayed until the User hits a “Clear” button.

    So, the text remains even if the mouse is not over the polygon any more. (That is, I have implemented the update method not to clear the screen)

    However, when I try to print it from the browser, I get the original view without the text. How could I get the text to be printed also?

    Please advise,
    Thanks,
    Uma.



  2. #2
    Guest

    Re: Printing after an Event, from the Browser...

    Hi Uma,

    For the first problem, your mouse has to listen every movement. If mouse position is not on the object, you have to repaint or update, the screen. I am working on the second problem. I will soon reply





  3. #3
    Guest

    Re: Printing after an Event, from the Browser...

    Hi again,

    There is no problem with the Mouse Events at all.

    The only problem I have is with the printing - i.e after the Event. I want the text that is generated after the Event to be printed also. I only get the original view of the Applet printed.

    Thanks for taking the time to reply to my question,
    Uma.



  4. #4
    Guest

    Re: Printing after an Event, from the Browser...

    Then i will reply soon after trying some thing

    Regards jagannadh


  5. #5
    Join Date
    Sep 1999
    Location
    Madurai , TamilNadu , INDIA
    Posts
    1,024

    Re: Printing after an Event, from the Browser...


    > I am developing an applet class that implements MouseMotionListener. On mouse over on top of a
    > polygon, I display some text corresponding to that polygon. Once the text is displayed, it
    > remains displayed

    You mean you are trying to show a tooltip like stuff for that polygon ? Which method are u
    using to display the text ? Graphics.drawString()... ?

    One simple solution( ? ) is create a TooltipLabel window and since you know the co-ordinates
    of the Polygon , in your mouseMotionListener , check for enter & Exit. If the cursor is
    inside the Poligon , set the position of the label window. If it exits then reset the label
    window. Try like this..



    JLabel toolTipWindow = new JLabel();
    // Somewhere inside applet init() method ..
    toolTipWindow.setBounds( 0 , 0, 0 ,0 );
    toolTipWindow.setText( "Polygon" );
    getContentPane().add( toolTipWindow );

    // Inside mouseMotionListener

    public void mouseMoved( MouseEvent e ){
    if( myPolygon.contains( e.getX() , e.getY() ) ){
    toolTipWindow.setBounds( e.getX() , e.getY() , 100 , 30 ); // set the width and height properly
    }else{
    toolTipWindow.setBounds( 0, 0 , 0 , 0 );
    }
    }





    If you like to set exact width and height of the label window .. Try this..


    public void showTooltip( String TooltipMessage , int xOffset , int yOffset ){
    FontMetrics fontMetrics = getFontMetrics( getFont());
    char [] message = new char[ TooltipMessage.length() ];
    TooltipMessage.getChars( 0 , TooltipMessage.length() , message , 0 );
    int width = fontMetrics.charsWidth( message , 0 , TooltipMessage.length() );
    int height = fontMetrics.getHeight();
    toolTipWindow.setText(TooltipMessage);
    toolTipWindow.setBounds( xOffset , yOffset , width , height );
    }





    Poochi..


  6. #6
    Join Date
    Apr 1999
    Posts
    25

    Re: Printing after an Event, from the Browser...

    As I had mentioned earlier, I am able to get the events to work correctly.
    I am using the drawString method to display the text by finding the coordinates, etc.

    It's only while printing that I do not get the text to be printed also.

    Will the use of ToolTip Label window allow me to print the text after the Event?

    Thanks,
    Uma.


  7. #7
    Join Date
    Sep 1999
    Location
    Madurai , TamilNadu , INDIA
    Posts
    1,024

    Re: Printing after an Event, from the Browser...


    > Will the use of ToolTip Label window allow me to print the text after the Event?

    I am sorry ... I could not able to get this.
    What do you mean by " Printing the text after the event ? "...
    As long as you are in the Polygon , you will get the text , after that the Label window will
    disappear.


    Poochi...


  8. #8
    Join Date
    Apr 1999
    Posts
    25

    Re: Printing after an Event, from the Browser...

    Hi,

    To give you more details, I have a chart with several polygons representing the points of Measurement. When the user places his Mouse Over a Polygon, the text corresponding to the Polygon is displayed. I have implemented the Update() method such that it calls paint() without Clearing the Screen. So, the text continues to be displayed. The user can compare the data for several points of Measurement.

    On printing from the browser, I get the original Chart with the Polygons but not the Text associated with each. Why???

    P.S: I have looked at some other Applets on the Web and I noticed that any changes after an Event, doesn't get printed.
    For Eg: http://www.javasoft.com/applets/jdk/...est/index.html
    (After you draw something, try to print. It won't show up. Why?)

    Thanks,
    Uma.



  9. #9
    Join Date
    Sep 1999
    Location
    Madurai , TamilNadu , INDIA
    Posts
    1,024

    Re: Printing after an Event, from the Browser...


    post the code..


  10. #10
    Join Date
    Apr 1999
    Posts
    25

    Re: Printing after an Event, from the Browser...

    Here is a snippet of my code:

    public class ChartAverageGap extends Applet implements MouseMotionListener, ActionListener
    {
    ....

    public void paint(Graphics g)
    {
    ….
    g.fillPolygon(p1[i]);
    if(isMouseOver)
    {
    //Display the Vehicle_Name
    g.drawString(vehicle_name[pointNum], xrep[pointNum] - 5, yrep[pointNum] - 5);
    }
    }


    //Implement the update method to avoid clearing the screen
    public void update(Graphics g)
    {
    paint(g);
    }


    public void mouseMoved( MouseEvent e )
    { displayName( e.getX(), e.getY() ); }


    public void displayName(int x, int y)
    {
    …………..
    if( p1[k].contains(mouseX, mouseY) )
    {
    isMouseOver = true;
    pointNum = k;
    repaint();
    }

    }




    Uma.



  11. #11
    Join Date
    Sep 1999
    Location
    Madurai , TamilNadu , INDIA
    Posts
    1,024

    Re: Printing after an Event, from the Browser...


    Hi Uma,

    I could not able to understand some of your code...
    What is P1 ? If it's polygon , then how do you do this ?



    >if( p1[k].contains(mouseX, mouseY) )






    Check whether the control flow goes inside the if condition and check isMouseOver becomes
    true. Check drawString method's X , Y values.

    I tried a simple program. It works just fine... Here it is...



    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;

    public class MyApplet extends JApplet{
    int[] x = { 10 , 50 , 88 };
    int[] y = { 100 , 130 , 30 };
    Polygon p;
    int X , Y;
    boolean isMouseOver;
    public void init(){
    p = new Polygon( x,y,3);
    this.getContentPane().addMouseMotionListener( new MouseMotionAdapter(){
    public void mouseMoved( MouseEvent e ){
    if( p.contains( e.getX() , e.getY() )){
    isMouseOver = true;
    X += 10 ;
    Y +=10;
    repaint();
    }
    }
    });
    }
    public void paint( Graphics g ){
    g.fillPolygon(p);
    if( isMouseOver ){
    g.drawString( "Poochi" ,X , Y );
    }

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








  12. #12
    Join Date
    Apr 1999
    Posts
    25

    Re: Printing after an Event, from the Browser...

    Hi,

    P1 is an array of Polygons.

    Anyway, I tried your code. I am working with jdk1.1.7 using Visual Cafe3.0. I cannot compile using javax.swing classes.

    But I tried the same thing using Applet instead of JApplet.
    Again the same problem. Cannot get the text to print from the browser.

    Can you please check if you can get the text to print when you use the JApplet class?

    Do the browsers support jdk1.2 and swing classes?

    Thanks,
    Uma.


  13. #13
    Join Date
    Sep 1999
    Location
    Madurai , TamilNadu , INDIA
    Posts
    1,024

    Re: Printing after an Event, from the Browser...


    > But I tried the same thing using Applet instead of JApplet.
    > Again the same problem. Cannot get the text to print from the browser.

    Did you try my code with Applet class ? I converted my applet from JApplet to Applet..



    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;

    public class MyApplet extends Applet{
    int[] x = { 10 , 50 , 88 };
    int[] y = { 100 , 130 , 30 };
    Polygon p;
    int X , Y;
    boolean isMouseOver;
    public void init(){
    p = new Polygon( x,y,3);
    this.addMouseMotionListener( new MouseMotionAdapter(){
    public void mouseMoved( MouseEvent e ){
    if( p.contains( e.getX() , e.getY() )){
    isMouseOver = true;
    X += 10 ;
    Y +=10;
    repaint();
    }
    }
    });
    }
    public void paint( Graphics g ){
    g.fillPolygon(p);
    if( isMouseOver ){
    g.drawString( "Poochi" ,X , Y );
    }

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





    it works as i expect. So , the problem might be in some other place. Did you debug the
    code ? Does it go inside the if( isMouseOver ) condition in the paint method ?


  14. #14
    Join Date
    Sep 1999
    Location
    Madurai , TamilNadu , INDIA
    Posts
    1,024

    Re: Printing after an Event, from the Browser...


    If you dont mind , can you send me your java source files to me to the following id..

    [email protected]


  15. #15
    Join Date
    Apr 1999
    Posts
    25

    Re: Printing after an Event, from the Browser...

    Hi again,

    Yes, I did compile your code after changing JApplet to Applet.

    Could you get the updated applet with the text "poochi" to be printed from the browser.

    Please try to PRINT using the printer and I don't know if you are mentioning - printing to the screen. The Applet is working correctly.

    Thanks,
    Uma.





Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured