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;

[Code] .....

View Replies


ADVERTISEMENT

Swing/AWT/SWT :: Give JTextArea Focus - Using It On A Panel And With JToolBar

Apr 21, 2014

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.)

View Replies View Related

JFrame Layout Appearance

Dec 4, 2014

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.

View Replies View Related

Swing/AWT/SWT :: How To Draw A Diamond Using Polygon

Mar 8, 2015

I'm currently trying to do a diamond using Polygon. I have done this so far. It is not drawing a diamond.

import java.applet.Applet;
import java.awt.Graphics;

public class Diamond extends Applet {

int[] a = {-30, 100 , 30, 100};
int[] b = {100, 40, 100, -40};

public void init()
{
}
public void paint(Graphics g)
{
g.drawPolygon(a, b, 4);
}

View Replies View Related

Swing/AWT/SWT :: Iterating Through Objects To Draw On Panel?

Apr 23, 2014

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.

View Replies View Related

Swing/AWT/SWT :: Draw String Inside A Shape

Mar 19, 2015

I have this piece of code, i want to insert a text inside my shape.

import javax.swing.SwingUtilities;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
import java.awt.Color;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Need To Draw JButton Such That It Displays On Top Of Two Different Panels

Mar 3, 2015

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.

View Replies View Related

Swing/AWT/SWT :: Draw A Line (Horizontal) Inside A Circle

Mar 12, 2015

I want to draw a line inside a circle, i what to have a horizontal line. Here is what i have done so far.

import javax.swing.SwingUtilities;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
import java.awt.Color;
import java.awt.Dimension;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Simple GUI Task - Draw Pie Chart With Different Colors

Jan 31, 2014

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.

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import java.awt.geom.Arc2D;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Color;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Method To Draw Triangle When Click On Specific Button

Mar 8, 2015

I'm trying to do a method which will draw a triangle and then the method will be called when we click on a specific button. How I must proceed.

View Replies View Related

Fractal Triangle - Recursion To Make Children Triangles

Oct 7, 2014

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.

View Replies View Related

Find Area Of Four Triangles Split By Two Intersecting Lines

May 4, 2014

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?

View Replies View Related

Read Positive Integer N And Plot 3 Triangles Of Size N

Oct 10, 2014

Write a Java program that reads positive integer n, 1 ≤ n ≤ 13, and plots 3 triangles of size n as shown below.

For n = 4, for instance, the program should plot: (works for n = 5 and n = 6 etc.)

triangle 1

1
2 3
4 5 6
7 8 9 10

triangle 2

_ _ _ 1
_ _ 3 2
_ 6 5 4
10 9 8 7

triangle 3

_ _ _ 1
_ _ 3 3 3
_ 5 5 5 5 5
7 7 7 7 7 7 7

import java.util.Scanner;
class Loops { 
void plotTriangle1(int n) {
int t = 1;
for (int i = 1; i <= n; i++) {
System.out.println(" ");
for (int j = 1; j <= i; j++) {
System.out.printf("%3d", t++);

[Code] ....

Currently compiles to this: Enter n(1-13):4
1
2 3
4 5 6
7 8 9 10

Format of the triangles, I couldn't get the spacing to work so I used underscores to replicate the blank space....

View Replies View Related

Swing/AWT/SWT :: Creating New Leaves In Tree

Aug 26, 2014

Having trouble adding leaves to my tree. Developing a stand alone Java app using mainly SWT and Eclipse JavaEE on Windows.The tree is like this:

root
------parentA
--------------childA1
--------------childA2
--------------childA3
------parentB
------parentC
--------------childC1
--------------childC2

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:

root
------parentA
--------------childA1
--------------childA2
----------------------grandchildA21
--------------childA3
------parentB
------parentC
--------------childC1
--------------childC2

Codewise I have:

import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;

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.

View Replies View Related

Swing/AWT/SWT :: Sorting In File Tree Node

May 12, 2014

I have requirement of sorting the files in tree structure with name and timestamp of creation, i am new to swings...

Here we are using FileTreeModel.

Root Folder:
folder1;
file1
file2
.
.

View Replies View Related

Swing/AWT/SWT :: Adding Button To Refresh Tree

Apr 6, 2015

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 ....

View Replies View Related

JavaFX 2.0 :: TreeView - Swing Tree Will Expand Listener?

Jun 3, 2014

Is there some equivalent of the Swing TreeWillExpand-listener for TreeView?
 
In my particular case I want to check whether some constrains are set to show some children before they will populated in the view.

View Replies View Related

Java Tree Structure - Build Tree Based On Traversal Results

Jun 17, 2014

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?

View Replies View Related

Swing/AWT/SWT :: JTree - Drag And Drop Inside One Tree - Java 1.6

Jul 16, 2008

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.

View Replies View Related

How To Give URL Connection To Code

May 11, 2014

how to give URL Connection to this?

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.net.*;
import java.io.*;
import javax.swing.*;
import javax.swing.event.*;
public class WebBrowser

[code]....

View Replies View Related

Way To Give A Color To The JFrame

Nov 23, 2014

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).

View Replies View Related

Can't Give Input A File By Console

Sep 28, 2014

this is my code...in my code i cant give input form my console...it takes input but it doesn't save in a target file..My code is :-

package filetester;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
 
[code]....

View Replies View Related

Why Array Initialization Does Not Give Error

Feb 18, 2014

int[][] array1 = {{1, 2, 3}, {}, {1, 2,3, 4, 5}};

it initializes 3 one dimentional array:

1 - {1, 2, 3}
2 - {}
3 - {1, 2,3, 4, 5}

but it only declares two dimensional arrays.

View Replies View Related

JSP :: How To Give Reference Of JavaScript And CSS File In Page

Aug 14, 2014

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.

View Replies View Related

How To Rotate Object And Give Colour Inside

Mar 13, 2014

package id.ac.ub.ptiik.computergraphics;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.*;
public class CG04_3DTransformation extends CGApplication {
protected boolean wireframe = true;

[Code] .....

View Replies View Related

How To Give Values To Array Objects Without Using Loop

Apr 3, 2014

The main method should creates a Student object with name as "Bill" and marks as {88,92,76,81,83} and print it.

Java Code:

class TestStudent {
public static void main(String args[]) {
Student1 st = new Student1();
st.name = "bill";
Student st1[] = new Student[6];
//This gives error
st1[].marks = {1, 5, 8, 9, 7, 6}; mh_sh_highlight_all('java');

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved