It does not print message to screen


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: It does not print message to screen

  1. #1
    eejay Guest

    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



  2. #2
    Ako Guest

    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
    >
    >



  3. #3
    Ako Guest

    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
    >>
    >>

    >



  4. #4
    John Guest

    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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center