Solved

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
The viewer will learn how to implement Singleton Design Pattern in Java.

825 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