i have make a jtree program in java and if the node is circle then the circle can be shown in frame and i have to resize it with slider . plz help me i have done the tree program bt how to get selected node means its circle of any thing else i can't get it ..
someone plz help me
i have attached my program with this -
import java.awt.*;
-
import java.awt.event.ActionEvent;
-
import java.awt.event.ActionListener;
-
import javax.swing.JButton;
-
import javax.swing.JFrame;
-
import javax.swing.JOptionPane;
-
import javax.swing.JPanel;
-
import javax.swing.JScrollBar;
-
import javax.swing.JScrollPane;
-
import javax.swing.JSlider;
-
import javax.swing.JTextField;
-
import javax.swing.JTree;
-
import javax.swing.event.*;
-
import javax.swing.tree.DefaultMutableTreeNode;
-
import javax.swing.tree.DefaultTreeModel;
-
import javax.swing.tree.MutableTreeNode;
-
import javax.swing.tree.TreeNode;
-
import javax.swing.tree.TreePath;
-
-
public class HirvaTree extends JFrame implements ActionListener {
-
-
-
private static final long serialVersionUID = 1L;
-
-
public static int WIDTH = 400;
-
-
public static int HEIGHT = 400;
-
-
public static String TITLE = "Trees";
-
-
Container frameContainer;
-
-
JTextField TF = new JTextField(20);
-
-
JScrollPane scrollPane = new JScrollPane();
-
-
JScrollBar scrollbar,scrollbar1 = new JScrollBar();
-
-
JSlider slider = new JSlider(JSlider.HORIZONTAL, 1, 100, 37);
-
-
JButton jb= new JButton();
-
-
JFrame frame= new JFrame("trees");
-
-
// Renderer renderer = new Renderer();
-
-
JTree mytree = new JTree();
-
-
JPanel panel = new JPanel();
-
-
public static DefaultTreeModel model;
-
-
public static TreePath path;
-
-
public static JTree tree;
-
-
public static DefaultMutableTreeNode nNode;
-
-
public static MutableTreeNode node;
-
-
TreeHandler treeHand = new TreeHandler();
-
-
-
-
//constructor
-
public HirvaTree()
-
{ DefaultMutableTreeNode treenode = getTree();
-
-
model = new DefaultTreeModel(treenode);
-
-
mytree = new JTree(model);
-
-
frame.setLayout(new FlowLayout(FlowLayout.CENTER));
-
-
// add button
-
jb = new JButton("Add");
-
jb.addActionListener(this);
-
frame.add(jb);
-
-
// Remove button
-
jb=new JButton("Remove");
-
jb.addActionListener(this);
-
frame.add(jb);
-
-
// delete all button
-
jb=new JButton("Delete All");
-
jb.addActionListener(this);
-
frame.add(jb);
-
-
//rename button
-
jb=new JButton("Rename Node");
-
jb.addActionListener(this);
-
frame.add(jb);
-
-
// add textfield
-
frame.add(TF);
-
-
// scrollbar
-
scrollbar = new JScrollBar(JScrollBar.HORIZONTAL,0,1,0,400);
-
-
scrollbar1 = new JScrollBar(JScrollBar.VERTICAL,0,1,0,400);
-
-
// frame size and visible
-
frame.setSize(WIDTH,HEIGHT);
-
-
frame.setVisible(true);
-
-
frame.add(panel);
-
-
panel.add(scrollbar);
-
-
panel.add(scrollbar1);
-
-
mytree.addTreeSelectionListener(treeHand);
-
-
panel.add(mytree);
-
-
frame.add(slider);
-
}
-
public void layoutComponents() {
-
-
frameContainer=getContentPane();
-
-
scrollPane.getViewport().add(mytree);
-
-
frameContainer.add("Left", scrollPane);
-
-
frameContainer.add("Center", TF);
-
-
}
-
-
public void actionPerformed(ActionEvent ae){
-
-
String str= ae.getActionCommand();
-
//add button logic
-
if (str.equals("Add"))
-
{
-
DefaultMutableTreeNode root = new DefaultMutableTreeNode(TF.getText());
-
DefaultMutableTreeNode a = (DefaultMutableTreeNode)treeHand.selectedNode;
-
a.add(root);
-
mytree.updateUI();
-
panel.add(mytree);
-
JOptionPane.showMessageDialog(null, "Node "+TF.getText()+" is add to the tree");
-
-
}
-
-
//remove button logic
-
if(str.equals("Remove"))
-
{
-
DefaultMutableTreeNode selectedNode = getSelectedNode();
-
if (selectedNode != null)
-
model.removeNodeFromParent(selectedNode);
-
mytree.updateUI();
-
panel.add(mytree);
-
JOptionPane.showMessageDialog(null, "Node "+selectedNode+" is deleted from tree");
-
-
}
-
-
-
//delete all button logic
-
if(str.equals("Delete All"))
-
{
-
DefaultMutableTreeNode a = (DefaultMutableTreeNode)treeHand.selectedNode;
-
a.removeAllChildren();
-
mytree.setRootVisible(false);
-
mytree.updateUI();
-
}
-
-
//remove buttion logic
-
if(str.equals("Rename Node"))
-
{
-
mytree.setEditable(true);
-
TreePath path = mytree.getSelectionPath();
-
mytree.startEditingAtPath(path);
-
}
-
-
-
}
-
-
//to show default tree on the screen
-
private DefaultMutableTreeNode getTree() {
-
DefaultMutableTreeNode nNode = new DefaultMutableTreeNode("Jtree");
-
-
DefaultMutableTreeNode colour = new DefaultMutableTreeNode("Colour");
-
nNode.add(colour);
-
-
DefaultMutableTreeNode pink = new DefaultMutableTreeNode("Pink");
-
colour.add(pink);
-
DefaultMutableTreeNode yellow = new DefaultMutableTreeNode("Yellow");
-
colour.add(yellow);
-
-
DefaultMutableTreeNode food = new DefaultMutableTreeNode("Food");
-
nNode.add(food);
-
-
return nNode;
-
}
-
-
public DefaultMutableTreeNode getSelectedNode() {
-
return (DefaultMutableTreeNode) mytree.getLastSelectedPathComponent();
-
}
-
-
-
//main class
-
public static void main(String[] args)
-
{
-
HirvaTree hi = new HirvaTree();
-
}
-
-
}
-
-
-
-
class TreeHandler implements TreeSelectionListener {
-
public TreeNode selectedNode;
-
-
public void valueChanged(TreeSelectionEvent e) {
-
TreePath e1 = e.getPath();
-
Object[] e2 = e1.getPath();
-
selectedNode =(TreeNode)e2[e1.getPathCount()-1]; // Node and convert
-
System.out.println("Current Selected Node :" + ((TreeNode)e2[e1.getPathCount()-1])); // For infomration printing selected node's name.
-
-
if(selectedNode.equals("circle"))
-
{
-
public void paint(Graphics a)
-
{
-
a.drawOval(60,60,40,50);
-
}
-
-
}
-
-
/*if(selectedNode.equals("rectangel"))
-
{
-
//drawrect();
-
public void paint(Graphics g)
-
{
-
g.drawoval(60,60,40,50);
-
}
-
System.out.println("node is Rectangle");
-
}*/
-
-
}
-
-
}
1 3673 JosAH 11,448
Recognized Expert MVP
It would be better if you'd post a short example, not a large listing that uses a lot of different Swing components that obfuscate what it's all about: a JPanel that is supposed to draw a circle with a radius that can be changed by a JSlider. Now the reader has to plough through JTrees, JScrollbars, JButtons, JFrames, JScrollPanes and almost the entire collection of available components ...
kind regards,
Jos
ps. don't forget to use the code tags when you have to post Java code.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Jason Charalambides |
last post by:
I need to assign a slider to determine a percentage value for a certain
variable in my program. I decided to use a slider so that the user will be
able to manually set a value between 0.000... to 1.000 for that variable.
The problem for me is how do I associate the slider to that variable? Do I
need to write something specific within that or do I just give the slider
control the name of the variable that it shall control?
Thank you
J.C.
|
by: Brian Henry |
last post by:
Ok I've never implemented a snap location before so I dont really know what
im doing wrong here... anyways, I am making a custom slider control that
takes dates as its values instead of integers... then taking that date range
and finding dates specifiec between them (in a list of dates) and putting
snap marks, so if you slide it near one of them it should snap to that tick,
but that part i cant figure out. the rest seems ok so far... here...
|
by: Israel |
last post by:
The problem:
I want to know, definitively when a slider loses focus after a user has
started sliding and hasn't released the mouse yet. It appears that
this is captured with the WM_ACTIVATEAPP message but this only goes to
the form and I want it in the user control that maybe very much removed
from the form's knowledge; i.e. the form may launch a 3rd party form
that, upon a call back, decides to launch other form that has my user
control...
|
by: murrayatuptowngallery |
last post by:
I have seen applets for mathematical functions with a mouse-operated
slide-bar to vary a parameter in lieu of direct numeric entry.
One waws online as Java I believe and the others were created by the
Maple math package. I believe it can export them to various languages.
Is such an entity possible and how difficult with PHP?
Thank you.
|
by: fatfatpopo |
last post by:
Anyone who understand the codes below, can you please kindly explain to me by adding comments.. thanks in advance
// <applet code="ImageSlider" width="400" height="400"></applet>
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
import javax.swing.*;
| |
by: Home Coder |
last post by:
Below is a link to a web page that loads a Java applet (sorry in
advance). In the applet, on the bottom there is a pink colored
slider. I would like to use/buy an a web version of this
slider. Do you know of any?
I'll try to describe what makes this slider special. It's a horizontal
slider, much like a scroll bar, but the end points are not fixed. You
don't click on them, you drag either of them to lenghten or shorten
the slider. This...
|
by: cmgmyr |
last post by:
Hello,
I'm trying to figure out how to disable a slider through the onChange
function. Here is what I have so far:
new Control.Slider('handle','slider',
{
axis:'horizontal',
sliderValue: 1,
range: $R(1, 100),
alignY:0,
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
| |
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |