Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Protect jar file - windows app 2 39
Impossible to extract MSI from new JAVA releases 2 48
object oriented programming comparison 5 55
expectj telnet failing 5 26
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now