Results 1 to 11 of 11
  1. #1
    clueless is offline Member
    Join Date
    Apr 2017
    Posts
    5
    Rep Power
    0

    Default Help With Program

    I'm new to the forum here and not very proficient in java but I'm required to write a program that:
    Displays a menu with three different choices, the choices go to three different images that will have numbered parts and the user will have to match the part to the number. Each of the three wont have more that 9 selections. I've tried starting with a Jpanel and JFrame to create the menu, and then use buttons to navigate but that failed, and I have no idea how to implement images, any help would be greatly appreciated.

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,342
    Rep Power
    12

    Default Re: Help With Program

    There are many many ways to do this. I've seen https://docs.oracle.com/javase/7/doc...ImageIcon.html used before, but in all my java graphics stuff, I do all my work on a Panel subclass with overridden paintComponent methods and BufferedImages - that might be more than you want to bite off and chew right now. Java GUI stuff is a pain, I recommend you try to keep it simple (not pretty) and use one of the swing layout managers: https://docs.oracle.com/javase/tutor...ut/visual.html

  3. #3
    clueless is offline Member
    Join Date
    Apr 2017
    Posts
    5
    Rep Power
    0

    Default Re: Help With Program

    Thanks quad64bit, and I wish I didn't have to but my professor isn't giving a choice. I tried those two links before and I didn't get how they worked. Any more help would be appreciated

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Help With Program

    Can you post the code you are having problems with so we can see it?
    Add some comments explaining what you are trying to do.
    Be sure to wrap any posted code in code tags.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    clueless is offline Member
    Join Date
    Apr 2017
    Posts
    5
    Rep Power
    0

    Default Re: Help With Program

    import java.awt.*;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import javax.swing.JPanel;


    public class main extends JPanel
    implements KeyListener
    {
    public void mouseExited(java.awt.event.MouseEvent p1) { }
    public void keyReleased(java.awt.event.KeyEvent p1){ }
    public void keyPressed(java.awt.event.KeyEvent p1)
    {
    if (p1.getKeyCode()==p1.VK_1)
    {

    }
    if (p1.getKeyCode()==p1.VK_2)
    {

    }
    if (p1.getKeyCode()==p1.VK_3)
    {

    }

    }
    public void keyTyped(java.awt.event.KeyEvent p1) { }


    }

    Like I said I'm pretty clueless, my professor didn't teach much and expects a lot. For my program I have to display a home menu with three different options, to those three options there will be an image of a car from the side view, underneath, and under the hood. There will be parts numbered and the user can hit the number and the program will display a small bit of information about the particular numbered part. I know this is way beyond my programming abilities so you don't have to insult me on it, any help will be greatly appreciated. I'm not asking for the project to be done through for me either, I'd like to learn so I can understand more. Thank you to any that reply with helpful info.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Help With Program

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.

    I'd work on the project one step at a time. Start with this:
    display a home menu with three different options,
    Build a GUI with a menu with 3 options. When that works, move to the next feature in the list
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    clueless is offline Member
    Join Date
    Apr 2017
    Posts
    5
    Rep Power
    0

    Default Re: Help With Program

    Java Code:
    import java.awt.*;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import javax.swing.JPanel;
    
    
    public class main extends JPanel 
    implements KeyListener
    {
    public void mouseExited(java.awt.event.MouseEvent p1) { }
    public void keyReleased(java.awt.event.KeyEvent p1){ }
    public void keyPressed(java.awt.event.KeyEvent p1)
    {
    if (p1.getKeyCode()==p1.VK_1)
    {
    
    }
    if (p1.getKeyCode()==p1.VK_2)
    {
    
    }
    if (p1.getKeyCode()==p1.VK_3)
    {
    
    }
    
    }
    public void keyTyped(java.awt.event.KeyEvent p1) { }
    
    
    }
    Is this what you meant on how to post @Norm? And how would I start with a GUI, I'm sorry for so many questions, my professor only taught us the first two chapters from the textbook with little explanation.

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Help With Program

    That is a start. However the code has lost all its indentation that show nested logic.

    how would I start with a GUI,
    That is a big topic. Start by looking at the tutorial: Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    clueless is offline Member
    Join Date
    Apr 2017
    Posts
    5
    Rep Power
    0

    Default Re: Help With Program

    Norm, I've tried to make a GUI and errors keep happening. The Java Tutorials are using a different program than Eclipse.

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Help With Program

    If you ignore the one section that deals with Netbeans (the second part of the tutorial), the rest of them are all valid for any IDE.
    So long as you are not using a GUI builder.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  11. #11
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Help With Program

    If you are typing in the Java code by hand (which includes ensuring the import statements are present), then the programs should
    work whether you're using Eclipse, NetBeans, or a text editor.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Replies: 19
    Last Post: 07-17-2015, 03:40 PM
  2. Replies: 6
    Last Post: 12-15-2013, 06:40 AM
  3. Replies: 4
    Last Post: 11-21-2012, 01:19 PM
  4. Replies: 2
    Last Post: 04-02-2011, 12:57 PM
  5. Replies: 0
    Last Post: 10-04-2007, 09:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •