I have created the following JPanel and I want to display that JPanel within a JFrame form.
JPanel
import javax.swing.*;
public class JPanelFormInJFrameForm extends JPanel{
public JPanelFormInJFrameForm(){
setLayout(null);
JLabel lStudNo = new JLabel("Student No:");
JLabel lStudName = new JLabel("Student Name:");
JLabel lMaths = new JLabel("Maths:");
JLabel lScience = new JLabel("Science:");
JLabel lEnglish = new JLabel("English:");
JTextField tStudNo = new JTextField();
JTextField tStudName = new JTextField();
JTextField tMaths = new JTextField();
JTextField tScience = new JTextField();
JTextField tEnglish = new JTextField();
lStudNo.setBounds(50, 40, 80, 25);
lStudName.setBounds(50, 80, 110, 25);
lMaths.setBounds(50, 120, 80, 25);
lScience.setBounds(50, 160, 80, 25);
lEnglish.setBounds(50, 200, 80, 25);
tStudNo.setBounds(145, 40, 110, 30);
tStudName.setBounds(145, 80, 110, 30);
tMaths.setBounds(145, 120, 110, 30);
tScience.setBounds(145, 160, 110,30);
tEnglish.setBounds(145, 200, 110, 30);
add(lStudNo);
add(lStudName);
add(lMaths);
add(lScience);
add(lEnglish);
add(tStudNo);
add(tStudName);
add(tMaths);
add(tScience);
add(tEnglish);
}
public static void main(String[] args) {
JFrame Frame = new JFrame();
Frame.getContentPane().add(new JPanelFormInJFrameForm());
Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Frame.setSize(300, 300);
}
}
At the main() I have tried that but it didn't worked.
I cannot figure out the problem so that if you could someone please help me.
Thank You!
Chiranthaka