Home Answers Viewqa Java-Interview-Questions How will you add panel to a frame?

 
 


ANJAN KUMAR DHIR
How will you add panel to a frame?
2 Answer(s)      2 years and 9 months ago
Posted in : Java Interview Questions

How will you add panel to a frame?
View Answers

August 18, 2010 at 2:36 AM


you can simply use add method to add panel to a frame
i.e panelA.add(frameA)

August 18, 2010 at 4:26 PM


Hi Friend,

Using add() method of JFrame.

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

class FormDemo extends JFrame {
JButton ADD;
JPanel panel;
JFrame f;

FormDemo(){
JLabel label1,label2;
final JTextField text1,text2;
label1 = new JLabel();
label1.setText("Name:");
text1 = new JTextField(20);

label2 = new JLabel();
label2.setText("Address:");
text2 = new JTextField(20);

f=new JFrame();
panel=new JPanel(new GridLayout(2,2));
panel.add(label1);
panel.add(text1);
panel.add(label2);
panel.add(text2);
f.add(panel,BorderLayout.CENTER);
f.setTitle("FORM");
f.setVisible(true);
f.pack();
}
public static void main(String[]args){
FormDemo ff=new FormDemo();
}
}

Thanks









Related Pages:
add
add

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.