//We can also write all the codes of creating JFrame, JButton and method call inside the java constructor.
import javax.swing.*;
public class SwingInsideConstructor {
JFrame f;
SwingInsideConstructor(){
f=new JFrame("Music Book");//creating instance of JFrame
JButton b=new JButton("Open");//creating instance of JButton
b.setBounds(130,100,100, 40);
f.add(b);//adding button in JFrame
f.setSize(400,500);//400 width and 500 height
f.setLayout(null);//using no layout managers
f.setVisible(true);//making the frame visible
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new SwingInsideConstructor();
}
}
Thanks
Happy programming!
import javax.swing.*;
public class SwingInsideConstructor {
JFrame f;
SwingInsideConstructor(){
f=new JFrame("Music Book");//creating instance of JFrame
JButton b=new JButton("Open");//creating instance of JButton
b.setBounds(130,100,100, 40);
f.add(b);//adding button in JFrame
f.setSize(400,500);//400 width and 500 height
f.setLayout(null);//using no layout managers
f.setVisible(true);//making the frame visible
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new SwingInsideConstructor();
}
}
Thanks
Happy programming!
No comments:
Post a Comment