Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Frame for my window  RSS feed

 
Kajol Shroff
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody..
Well I have some problem in adding a frame to my panel..can anybody help me out in that...
I will explain u exaclty what I want..
See there is a user login... as soon as the user submits his login & password.. and if he is a valid user........after validation a frame must pop up...which will have 3 panels and cardlayout which are nothing but the different steps..what i have done is I have called all 3 functions from the init() which are nothing but 3 different panels.. all I need to do is to add the 3 panels in the frame so that whenevr the user logs in and after validation a pop up should come....which will look as if its an application....
Can i call a function from the frame...if yes how???
Can somebody please help me out in this as I have to implement it ...
Kajol
[This message has been edited by Kajol Shroff (edited March 10, 2001).]
[This message has been edited by Kajol Shroff (edited March 10, 2001).]
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

.....problem in adding a frame to my panel..
To the best of my knowledge, Frame (among others) is a top
level container and Panel is NOT.
You can add a Panel to a Frame, but not vice-versa.
Also, I din't follow your second half of the qstn. What are
you doing after init'ing the three Panels?
To add these three panels to the Frame you could do it using
the add() method.
regds.
- satya
 
Kajol Shroff
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Satya,
Thanks for ur reply..
The second half says..
See what I have done is I have used three panels and CardLayout.. what i do is that each panel is a Step so when I do next a new panel opens and so i can say precvious too so that the previous panel opens..
What I need to do is I need to add these 3 panels in the Frame so as it appears like a Pop up kind of window..
I have used add() only..
So please let me know ..if its still confusing you..
Kajol
 
Kajol Shroff
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Everybody...
I am not getting any replies ....have I asked something which is not answerable...
Kajol
 
Daniel Searson
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You said earlier that you are adding components from an init() method. Are you calling this method yourself (from a constructor) or are you expecting it to be automatically called as in an applet? You should add all components in the constructor, only use an init() method in an applet.
Hope that helps.
 
Kajol Shroff
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Daniel,
Yes i have called the methods in the init method ...see my program is like this ...
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class TestCard1 extends Applet implements ActionListener
{
Button btnLogin = null ;
Button btnExit = null ;
Button btnBack = null ;
Panel firstPanel = null ;
Panel secondPanel = null ;

public void init()
{
firstPanel = new Panel();
secondPanel = new Panel();
CardLayout cardLayout = new CardLayout();
this.setLayout ( cardLayout );
formFirstPanel( firstPanel );
formSecondPanel( secondPanel );
this.add( firstPanel , "Option");
this.add( secondPanel , "Login");
this.setSize(200,400);
cardLayout.show( this, "Option");
this.show(true);
}
void formFirstPanel( Panel firstPanel )
{
btnLogin = new Button ("Login");
btnExit = new Button ("Exit");
btnLogin.addActionListener( this );
btnExit.addActionListener( this );
firstPanel.add (btnLogin);
firstPanel.add (btnExit);
}

void formSecondPanel( Panel secondPanel )
{
TextField name = new TextField(25);
TextField password = new TextField(25);
btnBack = new Button("Back");
secondPanel.add (name);
secondPanel.add (password);
secondPanel.add (btnBack);
btnBack.addActionListener(this);
}

public void actionPerformed(ActionEvent e)
{
if ( e.getSource () == btnLogin )
{
CardLayout c1 = ( CardLayout ) this.getLayout();
c1.show( this , "Login" );
}
if ( e.getSource () == btnBack )
{
CardLayout c1 = ( CardLayout ) this.getLayout();
c1.show( this , "Option" );
}
if ( e.getSource () == btnExit )
{
System.exit (0);
}
}
/* public static void main( String[] str )
{
TestCard1 card = new TestCard1();
card.init();
}*/
}
Here i am calling two methds formFirstPanel( Panel firstPanel ) & formSecondPanel( Panel firstPanel )....right
So now what i want is I need to put this two metods in a frame i.e. it should appear as if a pop up window is opened
Please help me out...
Can a metod be added in a frame..
Kajol
[This message has been edited by Kajol Shroff (edited March 13, 2001).]
[This message has been edited by Kajol Shroff (edited March 13, 2001).]
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kajol,
Here is what you would do to make it open in a frame. I have commented all the lines I have added or changed so you can follow what I have done.

HTH,
-Nate
 
Kajol Shroff
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nathan,
Thanks a lot..
I got some hint out of it..
But tell me ... if i keep the first page in applet and may start with the second page in frame.. i mean if when i say login ( which will be i applet ) then when i press the submit button the frame should pop up ... hope u get me..
Cann u get backt to me on this..
Thnaks
Naveen
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kajol,
All you would have to do is create the frame and it's contents in the Applet's init() method, then in the ActionListener for your "Login" button do something like this :

HTH,
-Nate
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!