Top-level Window JFrame
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TopLevelWindow {
public static void main(String[] args) {
MyFrame frame = new MyFrame();
}
}
class MyFrame extends JFrame {
...
}
Description and Objective
- This is a simple application which changes the background color of the app window everytime it gains focus.
Things to Do
- Use the above code as a template and implement the c'tor of MyFrame class as follows:
- set the size of the window
- set the position of the window
- set the title of the window to "Lab 5 - Part 1"
- create and add a FocusListener object which changes the background color of the JFrame. The background color should cycle between red, green, blue and cyan.
- make sure that when you close the window the application quits also (use setDefaultCloseOperation)
- set the window visible
- To test the behaviour of the application, open another window (e.g. windows explorer, any browser etc.) and switch back and forth by selecting the other window and the app window.