Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Title screen Glitch (Cant Bust ERROR)

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Title screen Glitch (Cant Bust ERROR)

    Ok, I'm normally able to bust lots of errors. But this time it just wont bust!!
    I'm trying to make a button show up.
    Excuse the Start Image. I was just gonna make it so the button disappears and the picture fades. That's why I need the button code to fit in here. I tried every button script. Just wont fit in the code. Making it another class file wont work cause I need to make a main which is gonna be where Gameplay data is stored. So I need it all in 1 class for now. Unless you can show a way to make it another class for now. I've been to tired to program so I probably would've seen this by now. I'm gonna take a Nap know. I'll look for the answer soon
    BTW Code is here
    import java.applet.Applet;
    import java.awt.Color;
    import java.awt.Font;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.MediaTracker;
     
    public class Main extends Applet
    {
        /**
             *
             */
            private static final long serialVersionUID = 1L;
            private Image Logo = null;
            private Image Start = null;
     
        public void init()
        {
            try
            {
                MediaTracker imageWait = new MediaTracker(this);
                Logo = this.getImage(getClass().getResource("images/Logo.png"));
                Start = this.getImage(getClass().getResource("images/Start.png"));
                imageWait.addImage(Logo, 1);
                imageWait.addImage(Start, 1);
                // Wait for the image to load
                imageWait.waitForAll();
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
     
            // TODO: Initialization things here.
        }
     
        /**
         * This is where things will get drawn to the screen within your applet.
         */
        public void paint(Graphics g)
        {
            // Draw our hello world
            Font myFont = new Font("Ariel", Font.BOLD, 17);
     
            g.setColor(new Color(236, 236, 236));
            g.fillRect(2, 6, 640, 480);
            g.setColor(Color.RED);
            g.setFont(myFont);
            g.drawString("In a world of Oranges and Grapes, A hero must rise and save Questia", 25, 25);
            g.drawImage(Logo, -9, 50, null);
            g.drawImage(Start, -9, 50, null);
            setSize(624, 500);
            g.drawString("Live, Build, Explore!!!!", 200, 290);
            g.drawString("E10", 590, 470);
        }
    }
    Yes, It looks like I didn't even try but I did. This is the Pastebin File *Yawn*.


  2. #2
    Junior Member
    Join Date
    Apr 2012
    Location
    Missouri, United States
    Posts
    17
    Thanks
    4
    Thanked 2 Times in 2 Posts

    Default Re: Title screen Glitch (Cant Bust ERROR)

    Are you trying to add a JButton? IIRC, those have to be placed on a JFrame, JPanel, or some other such component.

    Or are you instead trying to have a custom image appear that represents a "button" and have your class receive mouse input to check if the "button" is clicked?

  3. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Title screen Glitch (Cant Bust ERROR)

    Yes, I've tried that. My other code just makes an applet of its own.
    I need to make a main class with gameplay soon. Without that the project wont run

  4. #4
    Junior Member
    Join Date
    Oct 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Title screen Glitch (Cant Bust ERROR)

    im not going to give you the code but im just going to tell you how i did it for my project

    first you want to get the game screens width and height preferebly in a mouse listener class so that you can calculate the position of the mouse on the game screen(sounds hard but easy to do) then using if statements make an invisile box but using screen coordinates to do it and make sure it workes by using print line thing when you mouse over the box then in repaint or paint or update set an image to the exact spot of the box make sure the image is the same size as box and use booleans to tell when you hovered over box and set them to true if you did so that you can change the image to preferebly a highlighted button image and set a boolean to true if its on the highlighted image so that you use both booleans in an if statement in mouse listener and if the user clicks on highlighted image set another boolean to true (and only if ALL "3" booleans are true do you) use an if statement to execute the required code

    this is pretty much just a button that will be executed if the user is hovering over it and clickes it

    if the user puts mouse out of detecter box then set the (first 2 booleans to false) when the code is executed after button pressed (set the third boolean to false)

    on more thing I used a fourth boolean that goes to true if (ALL) the above conditions are ment and at same time sets third boolean to false and if this boolean is on then the code can execute

    so when code is done turn boolean off to get ready for next button press




    and thats how i did it
    its realy not complicated even though it may seem complicated and this is not spoon feeding since i didn't give out any source code
    also do not ask me to structure this story better ecause I won't
    if there are any spelling errors tell me

    if you are not good at english then (too bad) because i explained this the best i can and am not changing it

    you should be happy im telling you how this can be done because i spent months of my time trying to figure out how to do this for my game since im not using any j objects in it so be happy and don't troll

    but anyway this is how I did it which doesn't mean its the best way because I am not a pro at javascript but it worked well for me so it might work well for you and now my rant is over
    Last edited by jack13580; May 3rd, 2012 at 12:15 AM.

  5. #5
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Title screen Glitch (Cant Bust ERROR)

    Are you trying to add a JButton? IIRC, those have to be placed on a JFrame, JPanel, or some other such component.
    Alternatively, you can extend JApplet (instead of Applet) and call the getContentPane().add(JButton...) method.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

Similar Threads

  1. Netbeams having a mysterious glitch about a work directory not existing.
    By javapenguin in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 14th, 2012, 02:59 PM
  2. Hello World! [Bet that's a belated Intro title]
    By Atypically Engineered in forum Member Introductions
    Replies: 0
    Last Post: April 6th, 2012, 04:40 PM
  3. Replies: 9
    Last Post: December 31st, 2011, 01:22 AM
  4. Freezing on bust (BlackJack)
    By DaffyPWNS in forum What's Wrong With My Code?
    Replies: 9
    Last Post: June 16th, 2011, 09:40 PM
  5. About Title border in jscrollpane
    By subhvi in forum AWT / Java Swing
    Replies: 2
    Last Post: December 15th, 2009, 12:45 AM