Swing/AWT/SWT :: Draw 3 Triangles On Top Of Each Other To Give Appearance Of A Tree
Nov 22, 2014
I'm having trouble in 2 areas.
I'm trying to draw 3 triangles 'on top' of each other to give appearance of a tree. My code is below and struggling with how to set my x/y cords correctly.
Also I've drawn a rectangle under a new class and that should then be appearing in the south location of my border layout (south) - but it's not.
import javax.swing.*;
import java.awt.*;
public class Christmas1 extends JFrame {
JPanel titlePanel;
JLabel title;
I have a program with a main panel JPanel that implements KeyListener. I added a JTextArea to which I added as the KeyListener: this, meaning the main panel. I made the JTextArea fill the entire main panel because I want to catch a key press anywhere in the main panel.I catch the key presses and the program does what I want it to.
I added a JToolBar to the program; it is working just fine.Now that I have two components on the main panel - toolbar and panel with textarea -, the textarea must have the focus before it will send the KeyEvent and call keyPressed(). I don't want to expect the user to click on the main window to get the program to start or after each time they use the toolbar.
I have tried calling both requestFocus() and requestFocusInWindow() on the textarea; neither call worked. I put the toolbar at PAGE_END instead of PAGE_START; this worked to allow the program to start but I don't want to have the toolbar at the bottom and once I clicked on a toolbar button, the textarea lost the focus.
I need to be able to give the textarea the focus when the program starts and after the user uses a toolbar button. (I suspect that if I solve the problem when the program starts, I can use the same method after handling a button press.)
Below is my assignment and as you can see there is lots of empty space and it looks a bit ugly. Im currently using
content.setLayout(new GridLayout(5,1));
as follows:
Welcome Label and four buttons in the top JPanel, "Employee count" and JTextField in the second JPanel, "Employees in System: ", and empty JList in the third JPanel, Delete employee and Edit Employee buttons in the fourth JPanel Exit button in last JPanel.
When I set the size any smaller, the buttons sort of shrink into each other so Im looking for a way to have the panels take up less space? At the moment it seems like each of the panels are set to the same size for some reason, regardless of the content.how can I give the frame less vertical height without ruining the content.
I currently have the code set up to iterate through objects and keep track of them but how do I do the same and draw the objects on the panel window? I'm confused on what to do and how to start it.
Here's the code I have so far, the 'Car' which I want to draw extends to another class which extends to GameObject. I currently have a 'draw()' method under the 'Car' class but nothing in the 'draw()' method yet. From what I understand i'm suppose to have a 'draw()' method under 'GameObjects' class also?
public class MapView extends JPanel implements IObserver, ActionListener{ JPanel myPanel; private Timer timer = new Timer(5, this); int x = 0; int moveX = 2; public MapView(){ super.setBorder(BorderFactory.createTitledBorder("Map:"));
[code]....
Mostly I don't understand how to go through the iterator again to paint the objects. Wouldn't I need to put another iterator under 'paintComponent()' or can it be done under 'update()' ?
how to get some shapes from the GameObjects onto my panel.
one of the java swing challenge I am facing. Problem statement: there are two JPanels panel 1 and panel 2 placed on a JFrame one below the other as panel 2 below panel 1. Now, I need to put a JButton in any one of the panels such that this JButton displays half in panel 1 and half in panel 2.
Simple gui task. it meant to draw pie chart with different colors. i can't seem to find a mistake in it. It works if i put in g2g.draw(arc) i know arcs overlaps a bit due int conversion, but that's ok.
I have a FractalGUI and a FractalTriangle class. The FractalTriangle class is what does a lot of the work, it uses ATriangle(s) to make a triangle, and it uses recursion to draw three children triangles along each parent triangle. Fractal Triangle has a method "makeTriangle" private ATriangle makeTriangle( Point p0, Point p1 ) which takes the ATriangles and sets them the right size and everything, but for some reason I can only get one level of children triangles, and they are also already their upon running which they shouldn't be, they should appear when the depth is 2. When the depth is three it should add three triangles each onto the three added at depth two. At depth 4 it should add three each onto the three previously made triangles, and so on until depth reaches 6, the max depth. Here is some code of my FractalTriangle.
The Atriangle class given to us ("starter code") does not extend or implement anything, and has basic methods (setLocation, setSize, setThickness, setColor, etc. )
//---------------- class variables ------------------------------ //---- recursive generation parameters public static double sizeRatio = 0.5; // integer represent % public static double offset = 0.5; // offset/100 = parametric value // child positioning offset public static double p2projection = 0.5; // parametric value of projection of // vertex p2 onto the base; can be < 0 public static boolean outside = true;
[code]....
the way it looks without the recursion looks much more right, but I am supposed to have recursion in that constructor but I can't figure out how to get it right with the recursion. It's so weird how with the recursion the big red triangle ( base triangle ) disappears, and you can see the children are really really small.
Im doing a problem where i have to find the area of four triangles split by two intersecting lines, All i have are the points for x1, y1, x2, y2, x3, y3, x4, y4. My question is how do i find where these two lines intersect?
My requirement: when a child is selected/clicked I want to create a grandchild (there could be from zero to say 12 grandchildren). Thus if user clicks/selects childA2:
Question one: do I need any further tree related imports to get this to work?
final Tree tree = new Tree(shell, SWT.VIRTUAL | SWT.BORDER | SWT.CHECK | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE ); tree.setHeaderVisible(true); tree.setBounds(975, 00, 375, 600);
[code]...
And it is here I've tried lots of options but it's like bleak mid winter - no new leaves What seems odd is that I can see the selected/clicked child text item.getText() but if I look at the index it is always -1. And I thought the index would let me create the leaf.
I want to add a button who refresh the tree the problem that i have not "DefaultTreeModel" in my class to do this ((DefaultTreeModel) jTree1.getModel()).reload(); and i try this jtree.updateUI(); but not work ....
How to do draw the original binary tree based on traversal results?
A binary tree has this pre-order traversal result: A,B,D,H,I,E,F,C,G,K,J (TreeNodes) And the same tree gives the following in-order traversal: B,H,I,D,A,C,F,E,K,G,J. Can you draw the tree structure?
I am trying to drag and drop tree nodes within the same JTree. I have a code which uses Java 1.2 java.awt.dnd.I would like to use TransferHandler and newer implementation.I have found a code which works when JTree is drop target but there is no code where Jtree is drag source and drop target.
i've worked with java for 1 month, i'm designing some practices at Netbeans IDE. my problem is i tried to make a single colorful interface using panels, adding colors and i want to know if i exist a way to give a color to the JFrame (i tried to use the background color option but this didn't work).
I have just started to work on Java EE and I am not able to put the refrence of css and javascript in jsp page.
My senario is below: I have created script file inside myJavaScript Folder like Web Container-> myJavaScript ->Home.js. Similarlly for css:Web Container-> myCss ->Home.css.
My Jsp page palced inside Like: Web Container-> Home ->Home.jsp.
How to give the reference of js and css file in my Home.jsp page.