Skip to content

Instantly share code, notes, and snippets.

@MahraibFatima
Created May 31, 2025 02:43
Show Gist options
  • Save MahraibFatima/cbbe679aaab4cae2774382876e374b6f to your computer and use it in GitHub Desktop.
Save MahraibFatima/cbbe679aaab4cae2774382876e374b6f to your computer and use it in GitHub Desktop.
basic with swing and java visual programming
//Step 1: import lib
import javax.swing.*;
import java.awt.*;
public class Main {
public static void main(String[] args) {
//step 2: Top level Frame / window
JFrame frame= new JFrame();
//step 3: container to frame
Container container= frame.getContentPane();
//step 4: container layout
container.setLayout(new FlowLayout());
//step 5: UI component to container
JButton btn= new JButton("hello");
btn.setBackground(Color.PINK);
container.add(btn);
//Step 6: set visibility of frame
frame.setVisible(true);
frame.setSize(200,400);
frame.setTitle("title");
frame.setBackground(Color.BLUE);
//step 7: sed default on close
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment