-
It does not print message to screen
Hey Developers,
Today is my first day trying to write a Java Application. I have a book that
somewhat walks me through the initial process. However, after I typed in
the code that was listed in the book it does not print the, "HelloJava" message
to the screen. They have a screen shots in the book showing the small app
should look like. My app looks exactly like it expect for the fact that it
doesn't print the message. The code is as follows:
public class HelloJava1 extends javax.swing.JComponent {
public static void main(String[] args) {
javax.swing.JFrame f = new javax.swing.JFrame("HelloJava1");
f.setSize(300, 300);
f.getContentPane().add(new HelloJava1( ));
f.setVisible(true);
}
public void paintComponent(java.awt.Graphics g) {
g.drawString("Hello, Java!", 125, 95);
}
}
Thanks in advance for your responses,
eejay
-
Re: It does not print message to screen
emmm it really should work if you have set up your environment correctly and
it compiles with not problem. That is a really poor example and perhaps you
should look for another book, you dont want to start learning the wrong way.
While the way your example creates a frame is not a very popular way of doing
it, it also doesnt add a WindowListener to the frame so you cant close the
opened frame the right way.
Good Luck,
Ako
"eejay" <enickols@midsouth.rr.com> wrote:
>
>Hey Developers,
>
>Today is my first day trying to write a Java Application. I have a book
that
>somewhat walks me through the initial process. However, after I typed in
>the code that was listed in the book it does not print the, "HelloJava"
message
>to the screen. They have a screen shots in the book showing the small app
>should look like. My app looks exactly like it expect for the fact that
it
>doesn't print the message. The code is as follows:
>
>public class HelloJava1 extends javax.swing.JComponent {
>
> public static void main(String[] args) {
> javax.swing.JFrame f = new javax.swing.JFrame("HelloJava1");
> f.setSize(300, 300);
> f.getContentPane().add(new HelloJava1( ));
> f.setVisible(true);
> }
>
> public void paintComponent(java.awt.Graphics g) {
> g.drawString("Hello, Java!", 125, 95);
> }
>}
>
>Thanks in advance for your responses,
>eejay
>
>
-
Re: It does not print message to screen
Just a correction of what i said, by saying the way your example creates a
frame is not a very popular way of so i mean you dont need to have a class
that extends JComponent there are easier ways of achieving the same result
but the line where the JFrame is created is fine.
Ako
>it,"Ako" <ays73@hotmail.com> wrote:
>
>emmm it really should work if you have set up your environment correctly
and
>it compiles with not problem. That is a really poor example and perhaps
you
>should look for another book, you dont want to start learning the wrong
way.
>While the way your example creates a frame is not a very popular way of
doing
>it, it also doesnt add a WindowListener to the frame so you cant close the
>opened frame the right way.
>
>Good Luck,
>Ako
>
>"eejay" <enickols@midsouth.rr.com> wrote:
>>
>>Hey Developers,
>>
>>Today is my first day trying to write a Java Application. I have a book
>that
>>somewhat walks me through the initial process. However, after I typed in
>>the code that was listed in the book it does not print the, "HelloJava"
>message
>>to the screen. They have a screen shots in the book showing the small app
>>should look like. My app looks exactly like it expect for the fact that
>it
>>doesn't print the message. The code is as follows:
>>
>>public class HelloJava1 extends javax.swing.JComponent {
>>
>> public static void main(String[] args) {
>> javax.swing.JFrame f = new javax.swing.JFrame("HelloJava1");
>> f.setSize(300, 300);
>> f.getContentPane().add(new HelloJava1( ));
>> f.setVisible(true);
>> }
>>
>> public void paintComponent(java.awt.Graphics g) {
>> g.drawString("Hello, Java!", 125, 95);
>> }
>>}
>>
>>Thanks in advance for your responses,
>>eejay
>>
>>
>
-
Re: It does not print message to screen
"Ako" <ays73@hotmail.com> wrote:
>
>Just a correction of what i said, by saying the way your example creates
a
>frame is not a very popular way of so i mean you dont need to have a class
>that extends JComponent there are easier ways of achieving the same result
>but the line where the JFrame is created is fine.
>
>Ako
>
>
>
>>it,"Ako" <ays73@hotmail.com> wrote:
>>
>>emmm it really should work if you have set up your environment correctly
>and
>>it compiles with not problem. That is a really poor example and perhaps
>you
>>should look for another book, you dont want to start learning the wrong
>way.
>>While the way your example creates a frame is not a very popular way of
>doing
>>it, it also doesnt add a WindowListener to the frame so you cant close
the
>>opened frame the right way.
>>
>>Good Luck,
>>Ako
>>
>>"eejay" <enickols@midsouth.rr.com> wrote:
>>>
>>>Hey Developers,
>>>
>>>Today is my first day trying to write a Java Application. I have a book
>>that
>>>somewhat walks me through the initial process. However, after I typed
in
>>>the code that was listed in the book it does not print the, "HelloJava"
>>message
>>>to the screen. They have a screen shots in the book showing the small
app
>>>should look like. My app looks exactly like it expect for the fact that
>>it
>>>doesn't print the message. The code is as follows:
>>>
>>>public class HelloJava1 extends javax.swing.JComponent {
>>>
>>> public static void main(String[] args) {
>>> javax.swing.JFrame f = new javax.swing.JFrame("HelloJava1");
>>> f.setSize(300, 300);
>>> f.getContentPane().add(new HelloJava1( ));
>>> f.setVisible(true);
>>> }
>>>
>>> public void paintComponent(java.awt.Graphics g) {
>>> g.drawString("Hello, Java!", 125, 95);
>>> }
>>>}
>>>
>>>Thanks in advance for your responses,
>>>eejay
>>>
>>>
>>
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks