Avatar of Chad_T
Chad_T
 asked on

Java GUI, cannot load image- I am very confused!

To whom this may concern:

For several weeks, I have been attempting to write a Java program that uses an image as the GUI, with 6 spots on the image going to different pieces of code.  4 of the spots are Java coded calculators, and 2 of them go to pdf manuals.

I started using a text editor, and had success with the calculator functionality.  The GUI was really difficult for me, so I moved to NetBeans to try to implement this.  

At this point, NetBeans "cannot find symbol" getCodeBase(), and I have imported about every library I can think of.  Point being, I have code everywhere, and am totally confused as to how to get the GUI working, and to get my different calculators and manuals to all "talk" to each other.

Should I go back to my text editor?  Should I continue working NetBeans?  I am completely confused, and my deadline is very, very soon.  

Can anybody offer advise, or possibly even what the base code would look like?  I thought that I knew how to program before I took this on, and boy have I been schooled!

Any help is very, very much appreciated.

Thank you,
Chad T
Java

Avatar of undefined
Last Comment
Javatm

8/22/2022 - Mon
suprapto45

Hi Chad T,

It is true that it is a little frustated learning Java GUI for the first time but when you are used to do that, you should have no problem anymore.

What you need to know regarding the GUI is that the positioning. Please search yahoo based on Layout. There are many Layout in Java such as FlowLayout which default your GUI from left to right, BorderLayout which divides your screen into NORTH, WEST, CENTER and etc. BoxLayou, GridLayout and etc.

You may also search yahoo or google on the Panel or JPanel if you use Swing. The panel can contain many components of your GUI such as JBUtton, JTextField and etc.

Then you need to know more about Listener. For the JButton, JTextField, they all have the listeners to configure what they need to execute if they are pressed or invoked.

By learning these three components, I believe that you should have some clear and obvious idea. Please search on JavaAlmanac.com and etc.

My suggestion...just stick to NetBeans or you may post your prob here.

Regards
Dave
Chad_T

ASKER
Hello Dave,
 
Thank you for your fast reply.  I actually have already schooled myself on the items that you mention above.  As for the Centering, North, South, JButton, and JTextFields, I have a pretty decent understanding.  Those are actually items that I am using in the calculators that I have already completed.  

I actually have a functional test GUI, where I am using the TabbedPanes.  My biggest point of confusion is how use an actual JPG image as my GUI, and to specify 4 sections of my JPG to execute my calculator code blocks, and to specify the other 2 sections to open a pdf file.

Does this help, in terms of specifics?  I can post what I have if it would help.  I figured my code was garbled to the point where it was pretty unhelpful, though.  Let me know....

Thank you,
Chad T
CEHJ

getCodeBase() is an applet method. Do you have an Applet  (or JApplet)? If not, you should probably do something like

Image img = new ImageIcon(getClass().getResource("/x.jpg")).getImage();
Your help has saved me hundreds of hours of internet surfing.
fblack61
CEHJ

>> If not,

and you can call that if it *is* too
Chad_T

ASKER
Hello CEHJ,
  You are correct, I am not doing an Applet.  This must be the issue.  I tried your line of code, and it does compile.... and works very well, I might add.  Now that I am able to read the image, how can I display it as my GUI?  I need to convert to a different type than TabbedPane I am pretty sure, but do not know what that would be.... below is the current "main" that I am using:

-----
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Calculators extends JFrame {
  private JLabel        statusBar;
  private JTabbedPane   tabbedPane;

  public static void main(String[] args) {
    Calculators that = new Calculators();
    that.setVisible(true);
  }

  public Calculators() {
    super("Money");
    setSize(700, 550);
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    statusBar = new JLabel(" ");
    getContentPane().add(statusBar, BorderLayout.SOUTH);

    tabbedPane = new JTabbedPane();

    populateTabbedPane();
    getContentPane().add(tabbedPane, BorderLayout.CENTER);
  }

  private void populateTabbedPane() {

    Image img = new ImageIcon(getClass().getResource("money.JPG")).getImage();
   
 }
----

Thank you very much,
Chad T
ASKER CERTIFIED SOLUTION
Javatm

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Chad_T

ASKER
By the way, not sure when it is appropriate to click "accept," and when to provide "feedback."  First time using the forum, so please let me know what is customary, so that I can make sure grading and points are allocated properly.

Thanks,
Chad T
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Javatm

Feed back : is if you want to say thank you for the things an expert did.
Accept : means the expert gets all the points.
Split Points : at the buttom of the page splits the points on all expert.
Javatm

You can use Feedback and Accept or Feedback and Split Just remember to do
Feedback 1st since if you pick Accept or Split you will not be able to do a Feedback :)
CEHJ

>>.  Now that I am able to read the image, how can I display it as my GUI?  

Since you're putting the image in a GUI, you may as well use the ImageIcon i mentioned as Javatm says
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Chad_T

ASKER
Javatm,
  Your code both solves the read and viewing problem that I am having!  Thank you, thank you, thank you, thank you!  Also, thank you to CEHJ for assisting, as well as Dave from the beginning of this thread.
  I do not want to push my luck here.... but now that I have my image as my GUI, is there some kind of mouse clicking procedure, or do I need to establish some coordinates so that a particular section of my image takes the user to a particular java calculator / pdf file?

Very warm regards,
Chad T
 
 
CEHJ

You can add a MouseListener to the ImageIcon
SOLUTION
CEHJ

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Javatm

Well you got to set your components 1st, align them in yout frame and add some listeners to your components.
http://java.sun.com/docs/books/tutorial/uiswing/events/

If you have another question that should be in another thread okey, I could use some feedback =) since I
only got one, haha. Thanks for your time dude.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Javatm

Here are the list of all the listeners to all components :
http://java.sun.com/docs/books/tutorial/uiswing/events/eventsandcomponents.html
SOLUTION
Javatm

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
CEHJ

8-)
Javatm

http://freewebs.com/cube-j

Always glad to help . . .
Friend : Javatm
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Javatm

Thanks for the feedback bro =)