(1) I am NEWBY to java. The following code works FINE, and
creates a "window" on the desktop, but
my attempt to make TWO windows, with a second program, by adding a section (a second "instantion"?) to this same
code (I thought) did NOT succeed: see the second sample of
code below this one.
1 // -----------------------------------------------
2 // java source program: "try_make_window_v2.java"
3 // page-
4 // java lesson by self-study student - ernie brown
5 // Using textbook: "Beginning JAVA 2", by Ivor Horton
6 // Page-783
7 // ------------------------------------------------
8 // "Test bed" script for this trial is:
9 //
10 // ./exec_java_program.ksh try_make_window_2 <enter>
11 //
12 // (Note: DON'T use the ".java" file-extension
13 // on the command-line. Enter (correctly) AS SHOWN)
14 // ---------------------------------------------------------
15 // java source program: "try_make_window_v2.java"
16 // (DON'T use the ".java" part on the command.line
17 // - when compiling with "javac")
18 // ---------------------------------------------------------
19
20 import javax.swing.JFrame;
21 import java.awt.Point;
22 import java.awt.GraphicsEnvironment;
23
24
25 public class try_make_window_v2
26 {
27 // the window object
28
29 static JFrame aWindow = new JFrame("This is ernies CENTERED - title");
30
31 public static void main(String[] args)
32 {
33
34 Point center =
35 GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
36 int windowWidth = 400;
37 int windowHeight = 150;
38
39 // set position and size
40
41 aWindow.setBounds(center.x-windowWidth/2, center.y-windowHeight/2,
42 windowWidth, windowHeight);
43
44
===========================================================
(2) My atttempt to create TWO 'windows" - which
does NOT succeed:
1 // -----------------------------------------------
2 // java source program: try_make_two_windows_v2.java"
3 // java lesson by self-study student - ernie brown
4 // Using textbook: "Beginning JAVA 2", by Ivor Horton
5 // ------------------------------------------------
6 // ./exec_java_program.ksh try_make_two_windows_v2 <enter>
7 // (Note: DON'T use the ".java" file-extension
8 // on the command-line.)
9 // -------------------------------------------------------
10
11 import javax.swing.JFrame;
12 import java.awt;
13
14 class sam {
15
16 public static void main(String[] args)
17 {
18
19 // --------------------------------------------------------------------------------------- 20 // instantiate the FIRST window object
21
22 static JFrame aWindow = new JFrame("This is ernies FIRST Window Title");
23 {
24
25 int windowWidth = 400;
26 int windowHeight = 150;
27 aWindow.setBounds(50, 100,
28 windowWidth, windowHeight);
29 aWindow.setVisible(true);
30 aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
31
32
33 } //End_of_1st_window_instantiation
34 //----------------------------------------------------------------------------------------
35 // --------------------------------------------------------------------------------------- -
36 // instantiate the SECOND window object
37
38 static JFrame anotherWindow = new JFrame("This is ernies SECOND Window Title");
39 {
40
41 int windowWidth = 500;
42 int windowHeight = 250;
"try_make_two_windows_v2.java" 58L, 216
=========================================================
(3) I think I have some FUNDAMENTAL lack of
understanding about "instatiation", since all my
variations to create a code MYSELF, based on a
code which works (ONE window) "from a book", but
extended by me to give (I thought) one more
instantioation than the original (successful) program
did NOT work.
What am I mis-understanding, here? I DO think I am
having some trouble (at least) understanding some of
these java concepts.
(4) Thanx in advance for any help you can give me with this.
Please refer to my line-numbers, so I can follow your
explanatioon better.
End-of-memo: Best to you..from ernieah.
I don't sell books, or work for any
publisher or computer company.
creates a "window" on the desktop, but
my attempt to make TWO windows, with a second program, by adding a section (a second "instantion"?) to this same
code (I thought) did NOT succeed: see the second sample of
code below this one.
1 // -----------------------------------------------
2 // java source program: "try_make_window_v2.java"
3 // page-
4 // java lesson by self-study student - ernie brown
5 // Using textbook: "Beginning JAVA 2", by Ivor Horton
6 // Page-783
7 // ------------------------------------------------
8 // "Test bed" script for this trial is:
9 //
10 // ./exec_java_program.ksh try_make_window_2 <enter>
11 //
12 // (Note: DON'T use the ".java" file-extension
13 // on the command-line. Enter (correctly) AS SHOWN)
14 // ---------------------------------------------------------
15 // java source program: "try_make_window_v2.java"
16 // (DON'T use the ".java" part on the command.line
17 // - when compiling with "javac")
18 // ---------------------------------------------------------
19
20 import javax.swing.JFrame;
21 import java.awt.Point;
22 import java.awt.GraphicsEnvironment;
23
24
25 public class try_make_window_v2
26 {
27 // the window object
28
29 static JFrame aWindow = new JFrame("This is ernies CENTERED - title");
30
31 public static void main(String[] args)
32 {
33
34 Point center =
35 GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
36 int windowWidth = 400;
37 int windowHeight = 150;
38
39 // set position and size
40
41 aWindow.setBounds(center.x-windowWidth/2, center.y-windowHeight/2,
42 windowWidth, windowHeight);
43
44
===========================================================
(2) My atttempt to create TWO 'windows" - which
does NOT succeed:
1 // -----------------------------------------------
2 // java source program: try_make_two_windows_v2.java"
3 // java lesson by self-study student - ernie brown
4 // Using textbook: "Beginning JAVA 2", by Ivor Horton
5 // ------------------------------------------------
6 // ./exec_java_program.ksh try_make_two_windows_v2 <enter>
7 // (Note: DON'T use the ".java" file-extension
8 // on the command-line.)
9 // -------------------------------------------------------
10
11 import javax.swing.JFrame;
12 import java.awt;
13
14 class sam {
15
16 public static void main(String[] args)
17 {
18
19 // --------------------------------------------------------------------------------------- 20 // instantiate the FIRST window object
21
22 static JFrame aWindow = new JFrame("This is ernies FIRST Window Title");
23 {
24
25 int windowWidth = 400;
26 int windowHeight = 150;
27 aWindow.setBounds(50, 100,
28 windowWidth, windowHeight);
29 aWindow.setVisible(true);
30 aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
31
32
33 } //End_of_1st_window_instantiation
34 //----------------------------------------------------------------------------------------
35 // --------------------------------------------------------------------------------------- -
36 // instantiate the SECOND window object
37
38 static JFrame anotherWindow = new JFrame("This is ernies SECOND Window Title");
39 {
40
41 int windowWidth = 500;
42 int windowHeight = 250;
"try_make_two_windows_v2.java" 58L, 216
=========================================================
(3) I think I have some FUNDAMENTAL lack of
understanding about "instatiation", since all my
variations to create a code MYSELF, based on a
code which works (ONE window) "from a book", but
extended by me to give (I thought) one more
instantioation than the original (successful) program
did NOT work.
What am I mis-understanding, here? I DO think I am
having some trouble (at least) understanding some of
these java concepts.
(4) Thanx in advance for any help you can give me with this.
Please refer to my line-numbers, so I can follow your
explanatioon better.
End-of-memo: Best to you..from ernieah.
I don't sell books, or work for any
publisher or computer company.