Solved

GUI-elements with funcionalities

Posted on 1998-04-11
4
149 Views
Last Modified: 2010-04-16
I'm searching for classes that can represent classes (in the form of a rectangle with text in it that can be
moved with the mouse and that can invoke an action when doubleclicked upon) and relations (in the form
of lines and arrows that can be manipulated with the mouse). Can anyone tell me where I might find such
classes or which classes I might use to implement such classes?
0
Comment
Question by:Jeppe041198
  • 2
  • 2
4 Comments
 

Author Comment

by:Jeppe041198
ID: 1234040
Edited text of question
0
 
LVL 1

Accepted Solution

by:
dufort earned 50 total points
ID: 1234041
This is a "classic" exemple of object-oriented programming. You will need to build a DrawCanvas class derivated from Component that owns a Vector of rectangular regions, each region represented with a DrawElement, a class derivated from Rectangle. Any drawable object (Oval, Line, Box, ...) inherits from DrawElement. When the user clicks anywhere on the DrawCanvas you must find if the click is inside() any of the DrawElements, and select (draw a rectangle on bounds()) the first matching object. Of course, you will need methods for changing the priority (or layers) of your drawn objects. Don't forget that low-layer objects are drawn first, but high-layer objects are selected first.

Add a TextField outside your work area for specifying the text tag for the selected DrawElement. Any such element can have a tag, even the arrows and lines. This is simpler like that.

Adding an object traced by the user at the end of your vector should not be difficult. Deleting the selected object is trivial.

May I suggest you taking a look into Microsoft Word's drawing tools. This should give you some hints on how to implement yours.

Let me know if you need more advices. I will have more time after 1998/04/24 to work on this.

0
 

Author Comment

by:Jeppe041198
ID: 1234042
The suggestion that you give is more or less the way I eventually did it, but now I have an other problem. I have several Panels in a Frame. Four of these Panels implement a KeyListener. My problem is  that when the DELETE-key is pressed after selecting a rectangle (more or less like your "DrawElement") this event is "caught" in the wrong panel...
0
 
LVL 1

Expert Comment

by:dufort
ID: 1234043
Are you sure you gave the focus to the Panel where the Rectangle was selected? The component with focus recieves the key events. For some components, the focus is not given automatically and you must "force" it.

Try requestFocus() and if you're not sure check if your component hasFocus(). (I assume here  you're using Swing components, but it should work with standard AWT's as well).

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
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.

747 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

12 Experts available now in Live!

Get 1:1 Help Now