Solved

GUI-elements with funcionalities

Posted on 1998-04-11
4
155 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
[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
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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…
The viewer will learn how to implement Singleton Design Pattern in Java.
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.

630 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