Lesson 2
Re: Lesson 2
- 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);
- }}
Re: Lesson 2
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);
}}
Re: Lesson 2
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.