Jump to content

deleting objects

- - - - -

  • Please log in to reply
13 replies to this topic

#1
alix

alix

    Newbie

  • Members
  • PipPip
  • 28 posts
i'm wondering how i can delete an object
like i have this program that involves two frames
the initial design didn't involve logging off but now it does so i have to somehow implement it
its like this
i have class1 and class2
main starts by
class1 c1 = new c1();
when c1 is created it has a class2 c2 item inside it
when i click log in i have
c2 = new class2();
c1.setVisible(false)
c2.class1=this;
so basically i have a class1 pointing at class2 and a class2 pointing at class1 so i can manipulate them from inside the classes

now when i want to log out i call c2.class1.reset(); which contains

public void reset(){
        user.setText(null);
        pass.setText(null);
        class2 = null;
        System.gc(); 
    }
but the class2 frame is not deleted
anyone know how to remove that frame?

Edited by Alexander, 06 January 2011 - 02:24 PM.
( formatting )


#2
alix

alix

    Newbie

  • Members
  • PipPip
  • 28 posts
JFrame has a .dispose() that seams to be the best way to do that, i'm still open for other possibilities

#3
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
now when i want to log out i call c2.class1.reset(); which contains

Can't you, as you said, first dispose the frame and then call the reset method?

#4
alix

alix

    Newbie

  • Members
  • PipPip
  • 28 posts
i can't dispose without calling the reset function because when i dispose it it's gone forever (i assume)
i mean i don't have to set it to invisible it just dissapears when i dispose it so i'd better inform the old frame to do something otherwise it will remain invisible and nothing will be going on

the way i did it was

	public void logOutFunction(){

		linkToLogin.setLocationRelativeTo(this);

		linkToLogin.reset();

		linkToLogin.setVisible(true);

		this.removeAll();

		this.dispose();

	}
	public void reset(){

		user.setText(null);   //set user field to null

		pass.setText(null);   //set pass field to null

		transferAF = null;     //cut the refference to the old window

		transferMF = null;    //cut the refference to the old window

		loginErrors.setText("");  //clear the login errors

		remove(logInB);  //the focus is on this button when i set it to visible because when i logged in and set the frame to invisible this was the last thing in focus

		add(logInB);  

	}


#5
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
hm i don't see the problem immediately. But for the focus trick you do there, i would just do JFrame.requestFocus()

#6
alix

alix

    Newbie

  • Members
  • PipPip
  • 28 posts
well basically my problem has been solved, i needed to dispose the frame
as you may have noticed from my other threads when i have a problem i search for a while and if the answer isn't obvious i make a thread and keep on searching, if someone gives me the answer before i get it so much the better :)
by the way
about that matches regulated expression thing, do you know how i can get . to be accepted as an element? because . just as it is means any element and that kind of beats the purpose of having a regex
to split a string by the point i have to .split("\\.") but that wont work in .match

#7
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
This should work:


public static void main(String[] args){

    String regex = "[a-zA-Z0-9 \\.]*";

    String test = "dEf 4.ERr .dse";


    if(test.matches(regex)){

      System.out.println("true");

      System.out.println("------\n");

      for(String part : test.split("\\.")){

        System.out.println(part);

      }

    } else {

      System.out.println("false");

    }

  }



#8
alix

alix

    Newbie

  • Members
  • PipPip
  • 28 posts
yes, but unfortunately
String regex = "[a-zA-Z0-9 -\\.]*";
String test = "dEf 4.ERr-\" .dse";
if (test.matches(regex)) System.out.println("yep");
does return yep

#9
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
Dash is a metacharacter, you can escape it. [a-zA-Z0-9 \-\\.]*
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#10
alix

alix

    Newbie

  • Members
  • PipPip
  • 28 posts
Posted Image

#11
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
it's an escape character for the regex, not for java so you must do \\-

#12
alix

alix

    Newbie

  • Members
  • PipPip
  • 28 posts
works, but it's odd because "[a-zA-Z0-9 -]*" somehow worked




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users