Results 1 to 2 of 2
  1. #1
    20deoctubre is offline Member
    Join Date
    Nov 2012
    Rep Power

    Default Novice question about JFrames

    Hello all
    This is my first post and I would like to state that I'm a completely novice on java.
    My question is related to JFrames, I would like to say too that I have already search information but I haven't been able to find an answer that suits to my question. (Java how to programa, Java 21 hrs and google).
    So here it is, Whats the correct way to program gui applications (I mean windows, buttons and those commponents)? What about the main function of my code and the JFrame, do they have to be mixed on the same package?
    This doubt is killing me and I haven't been able to found a way to do this, I have seen tutorials on youtube which say the way to make a VERY NICE JFrame, but how to mix the JFrame with the main class, or Is it that a JFrame application doesn't need a main class (that will be funny)?

    Well, I know that this could sound very simple, but is confusing me a lot, so any help is more than welcome

    I'm sorry if the information I'm asking is in the book, maybe I have been searching in a wrong way, but that's what I need, just a direction to take.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Rep Power

    Default Re: Novice question about JFrames

    There are several examples on the Swing tutorial.
    Essentially your main class looks something like:
    Java Code:
    public class MyApp {
        public static void main(String[] args) {
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
        private static void createAndShowGUI() {
            //Create and set up the window.
            JFrame frame = new JFrame("ComboBoxDemo");
            //Create and set up the content pane.
            JComponent newContentPane = ...some class that represents your base content pane...
            newContentPane.setOpaque(true); //content panes must be opaque
            //Display the window.
    Note, you shouldn't need to extend JFrame in a normal app.
    Most sample code where JFrame has been extended is not really correct.

    As for invokeLater, here's the tutorial for that part.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. multiple jframes question
    By dhazwa in forum New To Java
    Replies: 1
    Last Post: 09-08-2011, 09:28 AM
  2. Does UML's adequate for a novice ?
    By RealSilhouette in forum New To Java
    Replies: 2
    Last Post: 04-13-2011, 09:00 AM
  3. Question [Novice]
    By lovepo1314 in forum New To Java
    Replies: 5
    Last Post: 10-14-2010, 02:48 PM
  4. novice question about output
    By GarBage in forum New To Java
    Replies: 1
    Last Post: 02-05-2010, 01:08 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