
how to creat a frame in java

Hi Friend,
Try the following code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class RetrieveDataFromTextFields{
public static void main(String[] args){
JFrame f=new JFrame();
JLabel label1=new JLabel("Name: ");
JLabel label2=new JLabel("Address: ");
final JTextField text1=new JTextField(20);
final JTextField text2=new JTextField(20);
JButton b=new JButton("Submit");
JPanel p=new JPanel(new GridLayout(3,2));
p.add(label1);
p.add(text1);
p.add(label2);
p.add(text2);
p.add(b);
f.add(p);
f.setVisible(true);
f.pack();
}
}
Thanks
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.