Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- public class Main {
- public static void main(String... args){
- initComponents();
- }
- static void initComponents(){
- JFrame frame = new JFrame("Frame title in here duh");//frame object holds all the stuff
- JPanel panel = new JPanel();//jpanel is the basic component which u can put buttons, textfields in etc
- panel.setLayout(null);//layout null is absolute layout, you use X,Y for positioning
- JButton button = new JButton("text for button");// a simple button
- button.setBounds(100,100,200,50);//position x position y,width and height
- panel.add(button);//must add all components we have to the panel
- frame.add(panel);//after everything add the panel
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//in Java by default if u press the X button of the window
- //it would not stop your program but just minimize the gui and still run the thread in background
- //useful for minimizing, services etc, and this line sets it to close when you press X
- frame.setBounds(600,600,600,600);//spawning the frame at x,y with size something,something
- frame.setResizable(false);//cannot resize it :D
- frame.setVisible(true);//makes it visible
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement