Results 1 to 5 of 5
  1. #1
    Andreas is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Post Using JFrame interfaces

    Hi,

    I'm new to Java, and I'm trying to make a basic app.

    I need to do the following.

    I have SendMessage.java and View.java.

    A button in View.java hides View.java, and now im trying to put a piece of code that shows a new JFrame i made called Confirm.java.

    Here is what my files look like (not all code just the essential):

    SendMessage.java
    Java Code:
    public class SendMessage {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            View showView = new View();
            showView.setVisible(true);
            
            Confirm showConfirm = new Confirm();
            showConfirm.setVisible(false);
        }
    }
    View.java
    Java Code:
    public class View extends javax.swing.JFrame {
    
        /**
         * Creates new form View
         */
        public View() {
            initComponents();
        }
        
    
        @SuppressWarnings("unchecked")
     
    
        private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            setVisible(false);
            // I guess I need to put something here! <---------------------------------------------
            System.out.println(jTextField1.getText());
            System.out.println();
            System.out.println(jTextField2.getText());
            System.out.println();
            System.out.println(jTextArea2.getText());
        }
    Confirm.java doesn't have anything yet.

    I'm sure its an easy one.

    Thanks for all your help!

    Andreas
    Last edited by Andreas; 02-03-2012 at 09:50 PM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

  3. #3
    doWhile is online now Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    6

    Default Re: [EASY] Playing with JFrame interfaces


  4. #4
    Andreas is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Question Re: [EASY] Playing with JFrame interfaces

    Quote Originally Posted by Fubarable View Post
    um,... what is your question exactly?
    Well, if you look at my View.java file line 15 i hide the first view. Now i want to show the view called Confirm.java in line 16.

    I tired putting showConfirm.setVisible(true); but that doesnt work.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: [EASY] Playing with JFrame interfaces

    If you need to have one object have access to another, then the first object needs a reference to the second. You have one of two options here:
    1. Create the Confirm object inside of View so the reference is readily available, or
    2. Pass a reference to the Confirm object into View from the main method by either passing the confirm object's reference into View's constructor or in a separate setConfirm(Confirm confirm) method.


    Having said this, it's a very ugly program design to have windows popping into and out of view. Most will either show a dialog on top of a main window or swap views on a stable main window. For my money for a confirm dialog, I'd use a dialog such as a JOptionPane or a JDialog and keep the main window in view.

    Also, please read the link that doWhile provides to you in your cross-post. It's not fair to us for you to cross-post without notifying us.

Similar Threads

  1. Playing a WAV or MP3
    By meesterpickles in forum New To Java
    Replies: 7
    Last Post: 12-19-2011, 02:59 AM
  2. Playing . MP3 in JAVA
    By UJJAL DHAR in forum Advanced Java
    Replies: 1
    Last Post: 12-12-2011, 03:54 PM
  3. sound playing
    By nikkka in forum Threads and Synchronization
    Replies: 1
    Last Post: 04-10-2011, 05:38 PM
  4. Wav player not playing
    By RightGoodEnt in forum CLDC and MIDP
    Replies: 0
    Last Post: 02-13-2011, 04:23 PM
  5. playing audio in J-App??
    By ashton in forum New To Java
    Replies: 3
    Last Post: 01-30-2009, 08:50 AM

Tags for this Thread

Posting Permissions

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