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

Thread: JFrame properties for an Applet to be embedded in website?

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

    Default JFrame properties for an Applet to be embedded in website?

    I've been trying to find a way to gain access to all the JFRAME functionality
    like buttons etc in an applet which is being doublebuffered. Is there any
    way to have these buttons etc and chat style panes in an applet?

    EXAMPLE:

    Say I'm making a small game. In this game I am using something like:
        // The paint function handles all the paint requests to draw things to the
    screen
        public void paint(Graphics g){
     
            bg.clearRect(0, 0, appWidth, appHeight);    // Refresh the background first    
     
     
            // GUI PLACEMENT
     
            bg.setColor(Color.orange);
            bg.fillRect(640, 685, 260, 70);        // PROGRESS QUICKVIEW
     
            bg.setColor(Color.red);
            bg.fillRect(740, 655, 80, 30);        // SERVER TIME
     
    //////// MORE CODE HERE /////////
     
            // Finally output the prepared screen
            g.drawImage(buffer,0,0,this);
        }

    BUT ..... I want to be able to use the JFrame things like buttons to choose
    items in the game, and I want to be able to implement a little chat client in
    the game as well ......

    What would you recommend I do to accomplish this?

    I was thinking about writing it all from scratch, boundary boxes and parsing
    text to fit inside for the chatbox etc ... and then for the buttons / hotkeys
    in the game but JFrame buttons in there to do all the actions but I'm
    starting to think that I'm tackling this in the wrong way entirely.

    Any help please? Or would using JFrame properties inside my applet work?

    VERY IMPORTANT: This is to be embedded into a website so it cannot have
    standard windows style borders etc, I just want to utilise the JFrame assets
    like buttons etc ...

    Anyway any help you can offer me would be appreciated.

    Regards
    gam35guru


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: JFrame properties for an Applet to be embedded in website?

    It appears you wish to add Swing components...see the following tutorial page: Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)

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

    Default Re: JFrame properties for an Applet to be embedded in website?

    The one thing I dont want is the java frame as it's to be embedded in a website ... would the swing buttons etc still work without a content pane?

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: JFrame properties for an Applet to be embedded in website?

    Give it a try and see There are lots of code examples in the following link:
    How to Make Applets (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)

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

    Default Re: JFrame properties for an Applet to be embedded in website?

    @Copeg

    Thanks so much for the advice you've given so far and I've been frantically trying to make buttons work, AND THEY DO ..... but not how I want them to work.

    I can run a standard JFrame and have the content pane display and do something with the button but that's not what I want to do.

    I am building a game and I have an applet that extends Applet and I manage my own resources in there like loading images, sounds and have created GUI placement tools and working on a network component and sql database interaction but I just cannot grasp how to use swing buttons without having a standard FRAME generated.

    I want to be able to use the components from swing but without them opening their own window/application. So use the button functionality without having to make an application for them to run inside. Is there an easy way to do this?

    Could you perhaps give me an example of how to make a button if I inboxed you my code? I think seeing it come to life INSIDE my code would be the best way for you describe it for me, from there onwards I can tackle it all myself.

    Thanks so much for your time.

    My code: http://pastebin.com/zKKYDiAC

    Regards
    gam35guru
    Last edited by gam35guru; October 21st, 2011 at 08:29 AM.

  6. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: JFrame properties for an Applet to be embedded in website?

    Add the components (JButton, etc...) to a JPanel, then add this JPanel to a JApplet. Like I mentioned, there are many code examples online, and if you want specific help with your code you are better off posting it directly in the forums (see my signature on how to make an SSCCE)

Similar Threads

  1. how to convert applet to a JPanel or JFrame
    By flipsyde02 in forum Java Theory & Questions
    Replies: 2
    Last Post: August 29th, 2011, 07:40 AM
  2. [SOLVED] Java DB embedded
    By potatostar in forum JDBC & Databases
    Replies: 5
    Last Post: July 20th, 2011, 11:17 AM
  3. [SOLVED] Java Noob, Jframe in Applet.
    By rLLZORS in forum AWT / Java Swing
    Replies: 2
    Last Post: May 5th, 2011, 10:42 AM
  4. Managing an embedded database
    By jstn455 in forum JDBC & Databases
    Replies: 1
    Last Post: April 24th, 2011, 10:06 AM
  5. Help with JavaDB embedded
    By jstn455 in forum JDBC & Databases
    Replies: 2
    Last Post: March 17th, 2011, 03:27 PM