Created
May 31, 2025 02:43
-
-
Save MahraibFatima/cbbe679aaab4cae2774382876e374b6f to your computer and use it in GitHub Desktop.
basic with swing and java visual programming
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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