+ 2
How to use gui in java
4 Answers
+ 6
https://www.sololearn.com/discuss/339620/?ref=app
https://www.sololearn.com/discuss/536025/?ref=app
https://www.sololearn.com/discuss/371857/?ref=app
https://www.sololearn.com/discuss/727583/?ref=app
https://www.sololearn.com/discuss/364928/?ref=app
https://www.sololearn.com/discuss/976551/?ref=app
https://www.sololearn.com/discuss/548289/?ref=app
https://www.sololearn.com/discuss/1504989/?ref=app
https://www.sololearn.com/discuss/855936/?ref=app
+ 5
import javax.swing.*;
public class FirstGUI {
public static void main(String args[]){
JFrame f = new JFrame("My First GUI");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(300,300);
JButton button1 = new JButton("Press");
f.getContentPane().add(button1);
f.setVisible(true);
}
}
+ 2
// There are 2 ways to create a frame
// 1 By creating the object of frame class
// 2 By extending frame class ( public class MyFrame extends JFrame )
// Dont forget to import
import javax.swing.JFrame;
// This is a example by creating the object of frame class:
public class MyFrame {
public static void main(String[] args){
// Creating instance of JFrame
JFrame frame = new JFrame();
// Now use the instance variable (frame) to call some methods
frame.setSize(400,400); // Set the window size
frame.setLocationRelativeTo(null); // This center your window
frame.setVisible(true); // This makes your window visible
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // So you can close your window
}
}
// You cant create gui with sololearns playground..
0
Thank you for advice....can i know how to use gui in sololearn i am not having pc