Solved

how to create callout windows...like those used in comics?

Posted on 2004-03-24
7
296 Views
Last Modified: 2008-03-10
Hi!
I'd like to use callout window to guide the user through my program

                     |---------------------------|
                     |                                  |
                     |           hello!               |
                     |------      ----------------|
                            j     j
                           j   j
                         j  j
                        j j

Can someone tell me how...with code example....can it be done?...
Thanks for the help experts.
Cheers
0
Comment
Question by:Thunder_scream
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
7 Comments
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 10674245
0
 
LVL 13

Expert Comment

by:Webstorm
ID: 10675678
You need a transparent window
http://www.jniwrapper.com/winpack_features.jsp
0
 
LVL 2

Author Comment

by:Thunder_scream
ID: 10693035
Hi!

>Have a look on this link
>http://jeans.studentenweb.org/java/trayicon/trayicon.html
>and download  your requirements from http://jeans.studentenweb.org/java/trayicon/trayicon.html#download

All I wanted was how to create the callout box....this is not shown in this package...instead it calles internal windows commands to create what is already there in windows...anyway..I'm working on application which must be platform independent (linux,mac,windows), and this will not do the job. ..if I have misunderstood something please let me know...


>You need a transparent window
>http://www.jniwrapper.com/winpack_features.jsp
Webstorm , did not quite catch what you meant that I need a transparent window? do what with later...or how does it direct me to my goal...
the library you gave me link to seems to support multiplatform...but I have not yet been able to compile anything sucessfully with it....it seems to be big and complex...
isnt it just an easy way around..this?

thanks for the response  
Cheers
0
 
LVL 2

Accepted Solution

by:
Thunder_scream earned 0 total points
ID: 10693546
It seems that I found my own solution to the problem........have a look...hehe  ;)
webStorm> I take back what I said about transparent window..

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

/**
 * <p>Title: </p>
 * <p>Description: Provizuliser</p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: </p>
 * @author Thunder_scream & and someOther people
 * @version 1.0
 */

public class Callout {


  public static
      void main(String[] args) throws Exception {
    new Callout();
  }

  JScrollPane scroll;
  JPanel p = new JPanel(new BorderLayout());
  Robot robot = new Robot();
  public Callout() throws Exception {
    final JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(p);
    JButton b = new JButton("Callout Test");
    b.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        TransparentFrame frame1 = new TransparentFrame();
        int x = frame.getX() - 100;
        if (x < 0) {
          x = 0;
        }
        int y = frame.getY() - 100;
        if (y < 0) {
          y = 0;
        }
        frame1.setBounds(x, y, 100, 100);
        frame1.createCallout();
        frame1.setVisible(true);
      }
    });
    frame.getContentPane().add(b);
    frame.setBounds(200, 200, 120, 50);
    frame.show();
  }
}


  class MyPanel
    extends JPanel {
  BufferedImage underFrameImg;
  Area Callout;
  int paintX = 0;
  int paintY = 0;
  public MyPanel() {
    super();
    setOpaque(true);
  }

  public void paint(Graphics g) {
    super.paint(g);
  }

  protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.drawImage(underFrameImg, paintX, paintY, null);
    if (Callout != null) {
      g.setColor(Color.yellow);
      ( (Graphics2D) g).fill(Callout);
    }
    g.setColor(Color.red);
    g.drawString("wow!", 10, 20);
  }
}

class TransparentFrame
    extends JWindow {
  Robot robot;
  BufferedImage screenImg;
  Rectangle screenRect;
  MyPanel contentPanel = new MyPanel();
  boolean userActivate = false;
  Area Callout;
  public TransparentFrame() {
    super();
    createScreenImage();
    contentPanel.Callout = Callout;
    this.setContentPane(contentPanel);
    this.addComponentListener(new ComponentAdapter() {
      public void componentHidden(ComponentEvent e) {}

      public void componentMoved(ComponentEvent e) {
        resetUnderImg();
        repaint();
      }

      public void componentResized(ComponentEvent e) {
        resetUnderImg();
        repaint();
      }

      public void componentShown(ComponentEvent e) {}
    });
    this.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {}

      public void windowClosed(WindowEvent
                               e) {}

      public void windowOpened(WindowEvent e) {}

      public void windowIconified(WindowEvent e) {}

      public void windowDeiconified(WindowEvent e) {}

      public void windowActivated(WindowEvent e) {}

      public void windowDeactivated(WindowEvent e) {
        Callout = null;
      }
    });
  }
  protected void createScreenImage() {
   try {
     if (robot == null) {
       robot = new Robot();
     }
   }
   catch (AWTException ex) {
     ex.printStackTrace();
   }
   Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
   screenRect = new Rectangle(0, 0, screenSize.width, screenSize.height);
   screenImg = robot.createScreenCapture(screenRect);
 }

 public void createCallout() {
   Rectangle bounds = new Rectangle(0, 0, getWidth(), getHeight());
   Callout = new Area(new Rectangle(bounds));
   System.err.println(Callout.getBounds());
   RoundRectangle2D content = new RoundRectangle2D.Double(0, 0, getWidth(),
       getHeight() / 3, 20, 20);
   Polygon polygon = new Polygon(new int[] {20, getWidth() / 2, getWidth()}
                                 , new int[] {getHeight() / 3, getHeight() / 3,
                                 getHeight()}
                                 , 3);
   Area a = new Area(new Rectangle(bounds));
   a.subtract(new Area(content));
   a.subtract(new Area(polygon));
   Callout.subtract(a);
   contentPanel.Callout = Callout;
 }

 public void resetUnderImg() {
   if (robot != null && screenImg != null) {
     Rectangle frameRect = getBounds();
     int x = frameRect.x;
     contentPanel.paintX = 0;
     contentPanel.paintY = 0;
     if (x < 0) {
       contentPanel.paintX = -x;
       x = 0;
     }
     int y = frameRect.y;
     if (y < 0) {
       contentPanel.paintY = -y;
       y = 0;
     }
     int w = frameRect.width;
     if (x + w > screenImg.getWidth()) {
       w = screenImg.getWidth() - x;
     }
     int h = frameRect.height;
     if (y +
         h > screenImg.getHeight()) {
       h = screenImg.getHeight() - y;
     }
     contentPanel.underFrameImg = screenImg.getSubimage(x, y, w, h);
   }
 }
}
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 10729606
That  is good Work
I appreciate Thunder_scream and his team for their Work

Cheers
Sudhakar
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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question