Good day. I am a beginner, only now I started learning Java. Recently, I found an example of initializing a GUI form using Java code. Here is how it is given:
import javax.swing.*; public class AbsoluteBoundsTest extends JFrame { public AbsoluteBoundsTest(){ super("Absolute bounds test"); JPanel content = new JPanel(); content.setLayout(null); JLabel lblFirstName = new JLabel("First name"); lblFirstName.setBounds(5,5,95,21); JLabel lblLastName = new JLabel("Last name"); lblLastName.setBounds(5,30,95,21); JTextField tfFirstName = new JTextField(20); tfFirstName.setBounds(100,5,120,21); JTextField tfLastName = new JTextField(20); tfLastName.setBounds(100,30,120,21); JButton btnOk = new JButton("Ok"); btnOk.setBounds(65,60,75,21); JButton btnCancel = new JButton("Cancel"); btnCancel.setBounds(145,60,75,21); content.add(lblFirstName); content.add(lblLastName); content.add(tfFirstName); content.add(tfLastName); content.add(btnOk); content.add(btnCancel); setSize(230,130); setLocationRelativeTo(null); setDefaultCloseOperation(EXIT_ON_CLOSE); setContentPane(content); } public static void main(String[] args) { try { UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } catch (Throwable thrown) { thrown.printStackTrace(); } AbsoluteBoundsTest abt = new AbsoluteBoundsTest(); abt.setVisible(true); } }
If I want to create one more form according to this principle, do I need to create it with another class? Or can be done in one class?