StudyLover
  • Home
  • Study Zone
  • Features
    • Workout Interval Timer
    • Typing Tutor
  • Profiles
  • Contact us
  • Sign in
StudyLover The Basic Window (Swing)
Download
  1. Java
  2. Programs
The String Performance Lab : The Layout Organizer
Programs
Initiative: To transition from CLI to GUI by building a desktop frame with components.
import javax.swing.*; // Import Swing toolkit for window components
import java.awt.*; // Import AWT for layout and fonts

public class BasicWindow { // Define class for standard desktop window setup
    public static void main(String[] args) { // Program entry point
        // Run the GUI creation on the Event Dispatch Thread (standard practice)
        SwingUtilities.invokeLater(() -> { // Use a lambda to wrap the UI creation logic
            JFrame f = new JFrame("Java Dashboard v1.0"); // Instantiate the main window frame
            f.setSize(400, 300); // Set the dimensions of the window in pixels
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Stop app when window is closed
            f.setLayout(new FlowLayout()); // Set simple flow-based layout manager
            
            JLabel title = new JLabel("System Control Center"); // Create a text label
            title.setFont(new Font("Arial", Font.BOLD, 20)); // Set font style for the label
            f.add(title); // Add the label to the window frame
            
            JLabel prompt = new JLabel("Enter command below:"); // Create second label
            f.add(prompt); // Add the second label to the window frame
            
            JTextField field = new JTextField(20); // Create text input field with width 20
            f.add(field); // Add the input field to the window frame
            
            JButton btn = new JButton("Execute"); // Create a functional-looking button
            f.add(btn); // Add the button to the window frame
            
            f.setLocationRelativeTo(null); // Center the window on the computer screen
            f.setVisible(true); // Finally, make the window visible to the user
            
            System.out.println("GUI Thread started. Frame is now visible."); // Log thread status
        }); // End of invokeLater lambda
    } // End of main method
} // End of BasicWindow class
The String Performance Lab The Layout Organizer
Our Products & Services
  • Home
Connect with us
  • Contact us
  • info.studylover@gmail.com

StudyLover - About us

The Best knowledge for Best people.

Copyright © StudyLover
Powered by Odoo - Create a free website