Lesson 2

Post Reply
admin
Site Admin
Posts: 3118
Joined: Wed Dec 11, 2019 8:31 am
Has thanked: 4 times

Lesson 2

Post by admin »

Create the project MyFrame.
admin
Site Admin
Posts: 3118
Joined: Wed Dec 11, 2019 8:31 am
Has thanked: 4 times

Re: Lesson 2

Post by admin »

  1. package myframe;
  2. //Import the library:
  3. import javax.swing.*;
  4. //Extend JFrame:
  5. class JustAFrame extends JFrame{
  6. //Class constructor:
  7. public JustAFrame(int a,int b){
  8. //The window caption:
  9. super("Simple window");
  10. //The window size:
  11. setSize(a,b);
  12. //The action when you close the window:
  13. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  14. //Show the window:
  15. setVisible(true);}
  16. }
  17. class MyFrame{
  18. public static void main(String args[]){
  19. //Create the window:
  20. JustAFrame frame=new JustAFrame(300,200);
  21. }}
admin
Site Admin
Posts: 3118
Joined: Wed Dec 11, 2019 8:31 am
Has thanked: 4 times

Re: Lesson 2

Post by admin »

Code: Select all

package myframe;
//Import the library:
import javax.swing.*;
//Extend JFrame:
class JustAFrame extends JFrame{
//Class constructor:
public JustAFrame(int a,int b){
    //The window caption:
    super("Simple window");
    //The window size:
    setSize(a,b);
    //The action when you close the window:
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //Show the window:
    setVisible(true);}
}
class MyFrame{
public static void main(String args[]){
    //Create the window:
    JustAFrame frame=new JustAFrame(300,200);
}}
admin
Site Admin
Posts: 3118
Joined: Wed Dec 11, 2019 8:31 am
Has thanked: 4 times

Re: Lesson 2

Post by admin »

In this thread we created Simple window. Frame is a window which doesn't contain any other windows. We had to extend class Frame for it.
Post Reply