Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

GUI-elements with funcionalities

Posted on 1998-04-11
4
Medium Priority
?
156 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 200 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

670 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