|
March 1, 2005, 11:38 PM
|
|
Moderator
|
|
Join Date: February 15, 2004
Location: Michigan
Favorite Player: Mashrafee Mortaza
Posts: 8,361
|
|
Java Help
Just switching to java, and still dont know many staff. here is small problem, if someone can give me a solution. their must be an easier way to do it, but dont know how.
i've two frame, frame1 is the main frame, frame2 will come up when a button in frame1 is pressed. while frame2 is on, the button on frame1 will not generate frame2 again. and closing frame2 will go back to frame1. this actions can be repeated. the problem i'm having is, as many times i keep pressing the generating button, a new frame2 keeps coming up.
thanks in advance.
here is the code i've:
public void JButton1_actionPerformed(ActionEvent e){
Frame2 f = new Frame2();
f.validate();
f.show();
}
the "new" is causing the trouble. and Frame2.show() gives syntax error.
many not be needed, still, i'm using Borland JBuilder 2005 Enterprise Edition.
Edited on, March 2, 2005, 4:44 AM GMT, by AgentSmith.
|
March 1, 2005, 11:40 PM
|
|
Super Moderator BC Editorial Team
|
|
Join Date: February 12, 2004
Location: Canada
Favorite Player: Ice Man, Chatter Box
Posts: 27,678
|
|
ektu matha ghuracche. can u re-explain? or post the code? let me see what i can do.
|
March 1, 2005, 11:40 PM
|
|
Super Moderator BC Editorial Team
|
|
Join Date: February 12, 2004
Location: Canada
Favorite Player: Ice Man, Chatter Box
Posts: 27,678
|
|
ok i think i got what you said. sorry about that. posting the code will be helpful nevertheless. and yes, it probably doesnt matter which IDE you're using here.
Edited on, March 2, 2005, 4:41 AM GMT, by AsifTheManRahman.
|
March 1, 2005, 11:48 PM
|
|
Moderator
|
|
Join Date: February 15, 2004
Location: Michigan
Favorite Player: Mashrafee Mortaza
Posts: 8,361
|
|
code posted, atmh. thanks.
|
March 2, 2005, 02:00 PM
|
|
Super Moderator BC Editorial Team
|
|
Join Date: February 12, 2004
Location: Canada
Favorite Player: Ice Man, Chatter Box
Posts: 27,678
|
|
hmm. looks like you're opening frame2, but not preventing it from opening when one version of frame2 is already open. f.show() should display frame2, but where does it say in the code that it should not be displayed once there's already a frame2 open?
btw - can you post the exact errors you're getting, and the code for the method call?
|
March 2, 2005, 02:07 PM
|
|
Super Moderator BC Editorial Team
|
|
Join Date: February 12, 2004
Location: Canada
Favorite Player: Ice Man, Chatter Box
Posts: 27,678
|
|
btw - i'm not very familiar with frames and windows (or anything visual for that matter, unless you're talking about web development tools) so i'm not sure how much i may be able to help you.
|
March 3, 2005, 12:03 AM
|
|
Administrator BanglaCricket Development
|
|
Join Date: October 4, 2002
Location: USA
Favorite Player: Mashrafe Mortaza
Posts: 9,094
|
|
Before you create new Frame2(), have a global flag variable verification. If flag is unset create new Frame2() then set the flag. After frame2() is closed/destroyed unset that variable again.
Something like this:
if (flag == 0) {
Frame2 f = new Frame2();
flag=1;
f.validate();
f.show();
}
and then in the close/destroy method the last operation should be: flag=0;
That will ensure that your frame2 isn't recreated if its already active. I don't know if its the best way (not a java expert) but it is one way.
By the way, I think NetBeans is much better IDE for Java (and its free ).
Edited on, March 3, 2005, 5:06 AM GMT, by nasif.
|
March 3, 2005, 12:33 AM
|
|
Moderator
|
|
Join Date: February 15, 2004
Location: Michigan
Favorite Player: Mashrafee Mortaza
Posts: 8,361
|
|
nasif vai, thanks for the help, i tried that, but the problem here is, i can't unset the flag. i mean, when frame two is closed it should make the flag =0 again. what is the way to do that?
one thing i found is:
setDefaultCloseOperation(flag=0);
the problem is, if i do that, the frame does not close anymore. and i can't use it twice so:
setDefaultCloseOperation(flag=0);
setDefaultCloseOperation(frame2.HIDE_ON_CLOSE);
only executes the first line, doesnot matter which one i put first. so, it will either make the flag zero or close, don't know how to do both.
btw, jbuilder is free too and its more fun to use a professional compiler free than to use a free one.
|
March 3, 2005, 12:36 AM
|
|
Moderator
|
|
Join Date: February 15, 2004
Location: Michigan
Favorite Player: Mashrafee Mortaza
Posts: 8,361
|
|
i found it!!!!
just declear the frame outside the stub of the jButton, right at the beginning of
public class Frame1 extends JFrame{......
that way, when i press the jbutton, it will not create a new frame, but will reshow the same frame already created.
|
March 3, 2005, 09:48 AM
|
|
Super Moderator BC Editorial Team
|
|
Join Date: February 12, 2004
Location: Canada
Favorite Player: Ice Man, Chatter Box
Posts: 27,678
|
|
hahaha....basic mistake that all java beginners make! nothing to worry about!
|
March 13, 2005, 03:43 PM
|
|
Cricket Guru
|
|
Join Date: February 8, 2005
Location: Deleting Evidence
Favorite Player: Dubya
Posts: 10,102
|
|
use Jcreator its the best
|
March 21, 2005, 08:48 PM
|
|
Moderator
|
|
Join Date: February 15, 2004
Location: Michigan
Favorite Player: Mashrafee Mortaza
Posts: 8,361
|
|
once again, i'm stuck: this time a bit more complicated. see if anyone can give some tips.
overveiw: i'm writting a software to operate a device (an RFID). it operates in bitwise command. i need to send a packet of binary (=hex) number through rs232 serial port.
problem: the packet has to be in the grup of 8 bits (1 byte). i did it in C, they have this "unsigned char" that has 8 bit. problem with java is, its char is 16 bits(2 bytes). i tryed to use "byte" type variable in java, but i can't. because i can't assign something like
byte var1=0xFF; i'm not able to change the Most sig bit to 1.
and if i'm using a bigger variable say char or int, my device will not take it since they are padded with a huge line of zeros. what can i do? any idea?
in short, i need 8 bit of space where i can use all eight.
|
March 21, 2005, 08:56 PM
|
Administrator
|
|
Join Date: January 22, 2004
Posts: 22,100
|
|
|
March 21, 2005, 09:21 PM
|
|
Moderator
|
|
Join Date: February 15, 2004
Location: Michigan
Favorite Player: Mashrafee Mortaza
Posts: 8,361
|
|
thanks doc.
how did u find it so quick? i spent some time looking for something like this but did not find any. have u had it read before? in this case, one more question for u (this is just out of curisity, i can use that method anyway). why bother doing all this, is not it be same if we do this?
int a=0x000000FF;
b=(byte)a;
if not, why?
Edited on, March 22, 2005, 2:43 AM GMT, by AgentSmith.
|
March 22, 2005, 01:10 AM
|
|
Administrator BanglaCricket Development
|
|
Join Date: October 4, 2002
Location: USA
Favorite Player: Mashrafe Mortaza
Posts: 9,094
|
|
Won't work because the moment you change it into byte type most sig bit can't be modified. You will always need higher type to store lower type ( word to store byte, long to store word etc). Thats why all operations need that byte mask (0xFF).
Not a java guru, but looking at the problem that seems to be the reason. I think C/C++ is the best programming for hardware interface
|
March 22, 2005, 02:13 AM
|
|
Moderator
|
|
Join Date: February 15, 2004
Location: Michigan
Favorite Player: Mashrafee Mortaza
Posts: 8,361
|
|
yes, the thing i'm trying to do has done in C several times. but when we choose the language for our project, we wanted GUI+database+hardware interface. fast two are harder in C. VB was not an option because we needed it platform free. i'll give it a try, if does not work, i'll have to find a way to run an internal program written in C and get the data from text files or something like that.
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is On
|
|
|
All times are GMT -5. The time now is 08:07 PM.
|
|