lab10
This commit is contained in:
17
lab/lab10/Question1/MyFrame.java
Normal file
17
lab/lab10/Question1/MyFrame.java
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Author: CHEN Yongyuan (Walter) from OOP(1007)
|
||||
* Date: 2022-05-01
|
||||
* Description: This is the Main Frame class.
|
||||
*/
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
public class MyFrame extends JFrame {
|
||||
public MyFrame() {
|
||||
setSize(400, 300);
|
||||
setTitle("MyFrame");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setLocationRelativeTo(null);
|
||||
setVisible(true);
|
||||
}
|
||||
}
|
||||
47
lab/lab10/Question1/Start.java
Normal file
47
lab/lab10/Question1/Start.java
Normal file
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Answer to question.
|
||||
*
|
||||
* - Q: In the constructor of the MyFrame class, comment out the call to the
|
||||
* setTitle method. Run the program. What happens? Then undo the commenting out.
|
||||
*
|
||||
* - A: The title will become empty.
|
||||
*
|
||||
* - Q: Comment out the call to the setSize method. Run the program. What
|
||||
* happens? Then undo the commenting out
|
||||
*
|
||||
* - A: Yes the program is still running. Because the "close windows" event is
|
||||
* not linked to the program ended event. So the program won't known the windows
|
||||
* is closed and will continue running.
|
||||
*
|
||||
* - Q: Comment out the call to the setVisible method. Run the program. What
|
||||
* happens?
|
||||
*
|
||||
* - A: Frame will not show and program will end.
|
||||
*
|
||||
* - Q: In a line before the call to the setVisible method, add a call to the
|
||||
* setLocationRelativeTo method of the frame and give it an argument of null.
|
||||
* Run the program. What happens?
|
||||
*
|
||||
* - A: The frame will show in the center of the screen. But did not work as
|
||||
* expected while using mutiple screen and x11-wayland or wayland platform.
|
||||
*
|
||||
* - Q: In the run method of the anonymous class inside the Start class, add a
|
||||
* second MyFrame object. Run the program. What happens? (Use the mouse to move
|
||||
* the frame to check what happens!) What happens when you close one of the
|
||||
* two frames? Then undo the change in the run method.
|
||||
*
|
||||
* - A: Two frame will show in the screen. If one of the frame is closed, the
|
||||
* both frame will be closed. Because they are connnect to the same event.
|
||||
*
|
||||
*/
|
||||
public class Start {
|
||||
public static void main(String[] args) {
|
||||
// Dispather
|
||||
javax.swing.SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
new MyFrame();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user