Start by reading the Swing tutorial on
Layout Managers. Download some of the demo code to learn how to better structure your code. For example:
1. All GUI code should be executed on the Event Dispatch
Thread (EDT). That is why SwingUtilities.invokeLater(...) is used in all the examples.
2.
You should not extend JFrame.
3. Don't use setSize() or setBounds(). Instead you just use frame.pack() AFTER all components have been added to the panel.
Why the image did not placed in the right hand side of text ?
The panel is using a GridLayout and the layout manager will determine the size and location of each component based on the order the component is added to the frame. See point 3 from above.
The code should be: