Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

GUI-elements with funcionalities

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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

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…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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 about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

916 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