Solved

GUI-elements with funcionalities

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Desingning Refactoring existing code 2 31
java imports not found 4 49
Bot application - advice 3 61
Eclipse with various Java releases 7 48
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.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to implement Singleton Design Pattern in Java.

749 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