Solved

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

Posted on 2004-03-24
7
286 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
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do I remove an object from a 3 51
running on tomcat not jboss eap 7.0 3 28
Java Eclipse Loop 3 28
Find out all repos that a user is most active on Github 1 26
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This video teaches viewers about errors in exception handling.

679 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