
how to create frame in swings

Simple Example
import javax.swing.*;
public class FrameExample{
public static void main(String[] args){
JFrame frame = new JFrame("Frame in Java Swing");
frame.setSize(400, 400);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Another Example
import java.awt.*;
import javax.swing.*;
class FrameExample
{
public static void main(String[] args)
{
JFrame f=new JFrame();
f.setLayout(null);
JLabel lab1=new JLabel("Name");
JLabel lab2=new JLabel("Age");
JTextField text1=new JTextField(20);
JTextField text2=new JTextField(20);
lab1.setBounds(10,10,100,20);
text1.setBounds(120,10,100,20);
lab2.setBounds(10,40,100,20);
text2.setBounds(120,40,100,20);
f.add(lab1);
f.add(text1);
f.add(lab2);
f.add(text2);
f.setVisible(true);
f.setSize(300,150);
}
}
For more information, visit the following link:
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.