Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

Have Programming Question? Ask it here!
 
 
 


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


How will you add panel to a frame?

Advertisement
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 Tutorials/Questions & Answers:
Advertisements
Advertisements
 

 

 

DMCA.com