Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7810971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:59:11+00:00 2026-06-02T03:59:11+00:00

i designed java desktop application in that application when i press a button another

  • 0

i designed java desktop application
in that application when i press a button
another Jframe is shown that draws a tree
but when i close the Jframe whole operation is close
but i only want to close that Jfarme what should i do?
here is the jframe codes:

public  class DrawTree extends JFrame{
 public int XDIM, YDIM;
public Graphics display;

@Override
public void paint(Graphics g) {} // override method

// constructor sets window dimensions
public DrawTree(int x, int y)
{
XDIM = x;  YDIM = y;
this.setBounds(0,0,XDIM,YDIM);
this.setVisible(false); 
    this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
display = this.getGraphics();
// draw static background as a black rectangle
display.setColor(Color.black);
display.fillRect(0,0,x,y);
    display.setColor(Color.red);
try{Thread.sleep(500);} catch(Exception e) {} // Synch with system
}  // drawingwindow


public static int depth(BinaryNode N)  // find max depth of tree
{
if (N==null) return 0;
    int l = depth(N.left);
    int r = depth(N.right);
    if (l>r) return l+1; else return r+1;
}

// internal vars used by drawtree routines:
private int bheight = 50; // branch height
private int yoff = 30;  // static y-offset

// l is level, lb,rb are the bounds (position of left and right child)
private void drawnode(BinaryNode N,int l, int lb, int rb)
{
if (N==null) return;
try{Thread.sleep(100);} catch(Exception e) {} // slow down
    display.setColor(Color.green);
display.fillOval(((lb+rb)/2)-10,yoff+(l*bheight),20,20);
display.setColor(Color.red);
display.drawString(N.element+"",((lb+rb)/2)-5,yoff+15+(l*bheight));
display.setColor(Color.blue); // draw branches
    if (N.left!=null)
    {
       display.drawLine((lb+rb)/2,yoff+10+(l*bheight),((3*lb+rb)/4),yoff+(l*bheight+bheight));
           drawnode(N.left,l+1,lb,(lb+rb)/2);
    }
    if (N.right!=null)
    {
           display.drawLine((lb+rb)/2,yoff+10+(l*bheight),((3*rb+lb)/4),yoff+(l*bheight+bheight));
           drawnode(N.right,l+1,(lb+rb)/2,rb);
    }
} // drawnode

public void drawtree(BinaryNode T)
{
    if (T==null) return;
int d = depth(T);
bheight = (YDIM/d);
display.setColor(Color.white);
display.fillRect(0,0,XDIM,YDIM);  // clear background
    drawnode(T,0,0,XDIM);
}}

and another question

when i new a object from my tree class,i want to access that object in all my button codes
so where i should define that or better to say , how i should define that object that can access in all my codes??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T03:59:14+00:00Added an answer on June 2, 2026 at 3:59 am

    You can simply hide the JFrame.

    this.hide();
    

    Edit: For the above: Youssef G’s answer is better.

    For the 2nd part of the question. Create your tree class and pass the object around in your program so it is the same tree object. Don’t create a new one.

    For example:

    Class A {
         B b;    //B object inside class A
         Tree t;  //Tree object inside class A
    }
    Class B {
         Tree t;    //Tree object inside class B
    }
    

    Now you have a tree object in both classes. You can create a new tree which is class b’s tree while code is running in Class A. Then say this.t = b.t;

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would I deploy a java desktop application that is designed to run on
Hi I have designed a desktop application in Java SE with netbeans and Mysql.I
Question I have an application written in Java. It is designed to run on
I have designed a GUI connect to DB button using Swing in java now
I have a Java client - server application. The client is designed to run
My application is written in Java (J2SE) and was originally designed for a Windows
I am trying to make a Java application thread-safe. Unfortunately, it was originally designed
I was wondering why Java has been designed without the friend directive that is
I am developing a Java Desktop Application which uses MySQL database. The DB has
I have a Java web application designed to be deployed on the internet. It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.