Close JFrame

hi all,
i have a JFrame. on that frame i put a JTabbedPane. on this pane i add a JPanel. and on this panel there is a JButton "exit". when this button is clicked, a JDialog opens that asks the user if he really wants to quit. when the user clicks "yes", i would like the frame to close, without using the System.exit() command (since the frame is opened from another JFrame, and that one isn't supposed to shut down).
does any of you know how to do that? thanks a lot people!

thanks woodi,
i know that i could use these methods, but the problem is i cannot tell the program which frame to close; since i'm using:
JFrame --> JTabbedPane --> JPanel --> JButton --> JDialog
how to tell the JDialog that i want to distroy the JFrame?

Similar Messages

  • Close JFrame by press JButton

    i wonder how to close JFrame...
    i know that DeafultCloseOperation... to this for me by pressing X...
    but how can i close the JFrame by pressing JButton...
    what do i have to do?
    to create new Event to do this or what?
    thx
    cya

    You can just call dispose();
                 btnClose.addActionListener(
                            new ActionListener()
                                   // pass query to tthe frame
                                 public void actionPerformed( ActionEvent event )
                                     dispose();
                                 } // end actionPerformed
                             }  // end ActionListener inner class         
                          ); // end call to addActionListener 

  • Question on not to close JFrame when close button is clicked

    Hi All,
    Good Morning
    I have frame created like:
    JFrame frame=new JFrame();When we give
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);The above statement closes the frame but i want the same frame to be hidden in the statusbar.So can any one help me in providing any built in method if there or else how to do it??
    Thanks in advance.
    regards,
    Viswanadh

    but i want the same frame to be hidden in the statusbar.Thats what the "minimize" button is for. Don't mix the functionality of the two buttons.

  • To close JFrame over a JDialog

    Hi,
    I am facing a slight problem. Say I have a code like under
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class abc extends JDialog implements ActionListener
         JPanel jp1 = new JPanel();
         JButton ok1 = new JButton("OK");
         public abc()
              this.getContentPane().setLayout(new BorderLayout());
              this.getContentPane().add(jp1,BorderLayout.CENTER);
              jp1.add(ok1);
              ok1.addActionListener(this);
              ok1.setActionCommand("ok1");
         public void actionPerformed(ActionEvent e)
              if (e.getActionCommand().equals("ok"))
                   System.out.println("Inside action performed method");
              else if (e.getActionCommand().equals("ok1"))
              JFrame j1 = new JFrame();
              JPanel jp2 = new JPanel();
              JButton btn1 = new JButton("OK");
              j1.getContentPane().add(jp2);
              jp2.add(btn1);     
              btn1.addActionListener(this);
              btn1.setActionCommand("ok");
              j1.show();
              j1.pack();
              j1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    public static void main(String args[])
              abc ABC = new abc();
              ABC.show();
              ABC.pack();
    Now here in this code the line
    j1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    closes the application itself. What I want is only the JFrame closes while the main Dialog stills stays in context.
    Can someone help with me how I can achieve the same.
    Regards.
    Anand

    There is a dialog it has a OK button. When I click the OK button a frame opens with another OK1 button in it.
    Now if I click the "x" sign of the frame it should be disposed without doing anything. frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE)But if I click the OK1 button then also the frame should be disposed but
    after doing something other processing corresponding to the OK1 button.
    OK1.addActionListener( new ActionListener() {
        public void actionPerformed(ActionEvent e) {
              // do processing
             frame.setVisible(false);
             // add this if you want to remove the frame from memory and recreate it when it needs to be opened
             frame.dispose();
    })>
    And within all this the parent(JDialog) and the child(JFrame) should be modal.A JFrame unfortunately cannot be modal, so you shd use a JDialog instead.
    ICE

  • Close JFrame in Netbeans

    Hello,
    I have a java application in NetBeans. I have been using Netbean absolut layout. I didn´t create JFrame class variable at all, instead using:Ok is a button
    ok.setFont(new java.awt.Font("Arial", 0, 10));
    ok.setToolTipText("ok");
    ok.setLabel("ok");
    ok.setMargin(new java.awt.Insets(2, 2, 2, 2));
    getContentPane().add(ok, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 150, 60, 20));
    ok.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    okPerformed(evt);
    I don´t want to use System.exit(0); because it will shut down whole system. In order to use dispose method, I created a JFrame class variable in beginning of the class, but it doesn´t work.
    JFrame frame = new JFrame();
    public void okPerformed (java.awt.event.ActionEvent evt){
    this.frame.dispose();
    Can anyone help me?
    Thanks

    hello,
    Thanks for replying my message so fast.
    I tried, but it still doesn´t work. I am using netbeans absolute Layout. It doesn´t really have frame. Here is my code
    public class tt extends JFrame{
    JFrame frame = new JFrame();
    JTextField text1= new JTextField(20);
    JButton ok = new JButton();
    public tt throws Exception
    setSize(400,300);
    setTitle("tt");
    getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
    text1.setFont(new java.awt.Font("Arial",0,12));
    text1.setBounds(5, 8, 5, 5);
    text1.setEditable(true);
    getContentPane().add(text1, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 30, 100, 20));
    ok.setFont(new java.awt.Font("Arial", 0, 10));
    ok.setToolTipText("ok");
    ok.setLabel("ok");
    ok.setMargin(new java.awt.Insets(2, 2, 2, 2));
    getContentPane().add(ok, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 150, 60, 20));
    ok.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    okPerformed(evt);
    setVisible(true);
    public void okPerformed (java.awt.event.ActionEvent evt){
    setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
    Thanks

  • Algo and close JFrame question

    Just a question. Basically, this is just my main method:
        public static void main(String[] args) {
            //Launch window ==============================================
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    game.launchFrame();
            //============================================================
        }It launches the frame of my game, which is a domino game. There's a bunch of code there (done), and at the end of a game, it asks whether the user wants to play another game, or quit the program. Quitting the program means just using System.exit(0).
    But what about if the user wants to play another game? I was thinking to just close the frame and launch another one. So I put "isEnd = true" if the user wants another game, and modified the main method:
            while (isEnd == false){
            //Launch window ==============================================
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    game.launchFrame();
            //============================================================
            }But it's totally flawed. It repeatedly tries to launch the same frame, so it's messy as hell.
    What do you guys suggest so the program can start a new game?

    so...
    we have the frame -> "DominoFrame.java"
    we have the GUI builder -> "MyDominoGUIBuilder.java"
    we have the class for storing domino -> "DominoStorage.java"
    and the Domino classes -> "DominoSet.java" , "Domino.java", etc...
    when you launch the app in DominoFrame, MyDominoGUIBuilder uses a new DominoStorage
    to initialize and manage the Domino game...
    when you wanna start a new game, you can "destroy" the DominoStorage and creating
    a new one and call the MyDominoGUIBuilder to create a new game, etc...

  • Questions about close a JFrame

    1) Creat a new JFrame frm1 to show a login page
    2) when user entered username & password, and clicked "OK" button, the program will check it's authority. when passed, I want to open a new JFrame and close the login frame.
    but I couldn't close the login page, and i found nothing on close JFrame on JFrame's API, except
    frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    maybe the usage about JFrame totally wrong. please give me some help. thank you!

    Hy
    On clicking the Login Button, u should validate the authorization.
    Eg:- If authorisation success then 1 , else 0.
    so if 1 means.
    this.dispose();
    newFrame.setVisible(true);
    if authorization 0 means,
    show some message using JOptionPane.showMessageDialog(...);
    and let the cursor be in the first field.

  • JFrame opening multiple times - strange bug

    Hi there
    I'm having this problem whereby a window (a JFrame) is opened multiple times - it works as follows:
    - I've got one JFrame which is opened via a button in my main JFrame (I'll call it JFrame 1)
    - A second one is opened from within the first in a similar way (JFrame 2)
    - The first time one opens JFrame 1 one can open and close JFrame 2 fine as many times as one wants
    - But when one closes JFrame 1 (this with JFrame 2 closed) and then reopens it (JFrame 1) and then clicks the button to open JFrame 2, JFrame 2 then opens twice - except one of them contains no components while the other contains everything it is meant to
    - The same thing happens as many times as I close JFrame 1 - except that when it is closed again JFrame 2 opens 3 times, then 4 and so on
    This is what I have for JFrame 1 (the actionlistener in the main window just calls showDebateRound(int roundID):
    public void showDebateRound(int roundID) {
            JFrame roundWindow=new JFrame("Round Draw");
            roundWindow.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            showRoundTitle.setFont(new java.awt.Font("Dialog", 1, 18));
            showRoundText.setColumns(20);
            showRoundText.setEditable(false);
            showRoundText.setRows(5);
            showRoundScroller.setViewportView(showRoundText);
            //showRoundPrint.setEnabled(false);
            //work out the title
            showRoundTitle.setText("Round: "+getRoundTitle(roundID));
            //work out the draw output
            showRoundTexts = "Motion: "+round[roundID].getMotion()+"\n\n";
            for (int i=0;i<debateCount;i++) {
                if (debate.getRoundID()==roundID) {
    showRoundTexts=showRoundTexts+"Prop: "+team[debate[i].getTeamOneID()].getTeamName()+"\nOpp: "+team[debate[i].getTeamTwoID()].getTeamName()+"\n\n";
    showRoundText.setText(showRoundTexts);
    //layout
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(roundWindow.getContentPane());
    roundWindow.getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addContainerGap()
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addComponent(showRoundScroller, javax.swing.GroupLayout.DEFAULT_SIZE, 410, Short.MAX_VALUE)
    .addGroup(layout.createSequentialGroup()
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addComponent(showRoundTitle)
    .addComponent(showRoundDrawLabel))
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 78, Short.MAX_VALUE)
    .addComponent(showRoundPrint)
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addComponent(ShowRoundEnterResults)))
    .addContainerGap())
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addContainerGap()
    .addComponent(showRoundTitle)
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addComponent(showRoundDrawLabel))
    .addGroup(layout.createSequentialGroup()
    .addGap(31, 31, 31)
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
    .addComponent(ShowRoundEnterResults)
    .addComponent(showRoundPrint))))
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addComponent(showRoundScroller, javax.swing.GroupLayout.DEFAULT_SIZE, 226, Short.MAX_VALUE)
    .addContainerGap())
    roundWindow.pack();
    roundWindow.setVisible(true);
    //debate round only actionlisteners
    ShowRoundEnterResults.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    enterResults();
    }JFrame 2 is constructed in the same way as JFrame 1
    Does anyone have any idea why this could be happening? I can post more code if need be. Thanks.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    hiding the form is probably more efficient than creating a new one each timeI rather think OP's both hiding the form and creating a new one each time.
    I would really like to know why it is not workingYeah, so would I.But where's the code that brings up the second JFrame? the actionListener.actionPerformed of the button that opens it?
    Better still, post a SSCCE limited to the minimum code that shows the problem.
    {color:#0000ff}http://homepage1.nifty.com/algafield/sscce.html{color}
    db

  • How to stop threads, process, streams when closing a (internal) JFrame?

    Dear all,
    I read a Javaworld article about Runtime.exec(), which will output the process outputs and error outputs to either a file or System.out. Now I want to practice it by outputing the process output/error to a Swing JTextArea. It works fine if the process ends successfully.
    My problem is that I want to stop all the output threads and clear all the streams when user click close JFrame button before the process finished. The code is shown below. Note that this frame is poped up by a click from another main frame. ( it is not exiting the main Swing application). This happened when I want to kill a process when it is running.
    I tried to implements a WindowListener and add
    public void windowClosing(WindowEvent e) to the JFrame.
    Inside this method I used process.destroy() and errorGobbler = null, outputGobbler = null, or outputGobbler.interrupt(), errorGobbler.interrupt(). But all these seems does not work. Sometimes thread was not stopped, sometimes process was not destroyed (because the stream was still print out something), sometimes the error stream was not successfully closed - by printing out interruptted by user error message.
    How can I make sure all the underlying streams and threads, including the PrintStream in StreamGobbler class are closed?
    Again this Frame could be a Dialog or InternalFrame, i.e, when I close the frame, the main frame does not exit!
    import java.util.*;
    import java.io.*;
    class StreamGobbler extends Thread
        InputStream is;
        String type;
        OutputStream os;
        StreamGobbler(InputStream is, String type, JTextArea out)
            this(is, type, null, out);
        StreamGobbler(InputStream is, String type, OutputStream redirect, JTextArea out)
            this.is = is;
            this.type = type;
            this.os = redirect;
        public void run()
            try
                PrintWriter pw = null;
                if (os != null)
                    pw = new PrintWriter(os);
                InputStreamReader isr = new InputStreamReader(is);
                BufferedReader br = new BufferedReader(isr);
                String line=null;
                while ( (line = br.readLine()) != null)
                    if (pw != null)
                        pw.println(line);
                    out.append(type + ">" + line);   
                if (pw != null)
                    pw.flush();
            } catch (IOException ioe)
                ioe.printStackTrace(); 
    public class Test extends JFrame
        private JTextArea output;
        private StreamGobbler outputGobbler;
        private StreamGobbler errorGobbler;
        public Test (String file)
            super();
            output = new JTextArea();
            try
                FileOutputStream fos = new FileOutputStream(file);
                Runtime rt = Runtime.getRuntime();
                Process proc = rt.exec("java jecho 'Hello World'");
                errorGobbler = new
                    StreamGobbler(proc.getErrorStream(), "ERROR", out);           
                outputGobbler = new
                    StreamGobbler(proc.getInputStream(), "OUTPUT", fos, out);
                errorGobbler.start();
                outputGobbler.start();
                int exitVal = proc.waitFor();
                output.append("ExitValue: " + exitVal);
                fos.flush();
                fos.close();       
            } catch (Throwable t)
                t.printStackTrace();
         setSize(400,400);
         show();
    }Thanks !

    Thread.interrupt() doesn't stop a thread. You'll have to read the API for more specifics. You could use something like interrupt to force interruption of the thread for the reason of checking the terminating case though. I believe you would want to use this in the case where operations can take a long time.
    Setting your reference to the thread to be null won't stop the thread since it's running. You just lose your reference to it.
    I believe once the thread stops running your streams will be closed, but possibly not cleanly. Someone who has more knowledge of threads might be able to answer this better, but I would generally say clean up after yourself especially if you are writting out data.

  • Trying to pass and object variable to a method

    I have yet another question. I'm trying to display my output in succession using a next button. The button works and I get what I want using test results, however what I really want to do is pass it a variable instead of using a set number.
    I want to be able to pass the object variables myProduct, myOfficeSupplies, and maxNumber to method actionPerformed so they can be in-turn passed to the displayResults method which is called in the actionPerformed method. Since there is no direct call to actionPerformed because it is called within one of the built in methods, I can't tell it to receive and pass those variables. Is there a way to do it without having to pass them through the built-in methods?
    import javax.swing.JToolBar;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JTextArea;
    import javax.swing.JScrollPane;
    import javax.swing.JPanel;
    import java.net.URL;
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    public class Panel extends JPanel implements ActionListener
         protected JTextArea myTextArea;
         protected String newline = "\n";
         static final private String FIRST = "first";
         static final private String PREVIOUS = "previous";
         static final private String NEXT = "next";
         public Panel( Product myProduct, OfficeSupplies myOfficeSupplies, int maxNumber )
                 super(new BorderLayout());
              int counter = 0;
                 //Create the toolbar.
                 JToolBar myToolBar = new JToolBar( "Still draggable" );
                 addButtons( myToolBar );
                 //Create the text area used for output.
                 myTextArea = new JTextArea( 450, 190 );
                 myTextArea.setEditable( false );
                 JScrollPane scrollPane = new JScrollPane( myTextArea );
                 //Lay out the main panel.
                 setPreferredSize(new Dimension( 450, 190 ));
                 add( myToolBar, BorderLayout.PAGE_START );
                 add( scrollPane, BorderLayout.CENTER );
              myTextArea.setText( packageData( myProduct, myOfficeSupplies, counter ) );
              setCounter( counter );
         } // End Constructor
         protected void addButtons( JToolBar myToolBar )
                 JButton myButton = null;
                 //first button
                 myButton = makeNavigationButton( FIRST, "Display first record", "First" );
                 myToolBar.add(myButton);
                 //second button
                 myButton = makeNavigationButton( PREVIOUS, "Display previous record", "Previous" );
                 myToolBar.add(myButton);
                 //third button
                 myButton = makeNavigationButton( NEXT, "Display next record", "Next" );
                 myToolBar.add(myButton);
         } //End method addButtons
         protected JButton makeNavigationButton( String actionCommand, String toolTipText, String altText )
                 //Create and initialize the button.
                 JButton myButton = new JButton();
                     myButton.setActionCommand( actionCommand );
                 myButton.setToolTipText( toolTipText );
                 myButton.addActionListener( this );
                   myButton.setText( altText );
                 return myButton;
         } // End makeNavigationButton method
             public void actionPerformed( ActionEvent e )
                 String cmd = e.getActionCommand();
                 // Handle each button.
              if (FIRST.equals(cmd))
              { // first button clicked
                          int counter = 0;
                   setCounter( counter );
                 else if (PREVIOUS.equals(cmd))
              { // second button clicked
                   counter = getCounter();
                      if ( counter == 0 )
                        counter = 5;  // 5 would be replaced with variable maxNumber
                        setCounter( counter );
                   else
                        counter = getCounter() - 1;
                        setCounter( counter );
              else if (NEXT.equals(cmd))
              { // third button clicked
                   counter = getCounter();
                   if ( counter == 5 )  // 5 would be replaced with variable maxNumber
                        counter = 0;
                        setCounter( counter );
                      else
                        counter = getCounter() + 1;
                        setCounter( counter );
                 displayResult( counter );
         } // End method actionPerformed
         private int counter;
         public void setCounter( int number ) // Declare setCounter method
              counter = number; // stores the counter
         } // End setCounter method
         public int getCounter()  // Declares getCounter method
              return counter;
         } // End method getCounter
         protected void displayResult( int counter )
              //Test statement
    //                 myTextArea.setText( String.format( "%d", counter ) );
              // How can I carry the myProduct and myOfficeSupplies variables into this method?
              myTextArea.setText( packageData( product, officeSupplies, counter ) );
                 myTextArea.setCaretPosition(myTextArea.getDocument().getLength());
             } // End method displayResult
         * Create the GUI and show it.  For thread safety,
         * this method should be invoked from the
         * event dispatch thread.
         public void createAndShowGUI( Product myProduct, OfficeSupplies myOfficeSupplies, int maxNumber )
                 //Create and set up the window.
                 JFrame frame = new JFrame("Products");
                 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                 //Add content to the window.
                 frame.add(new Panel( myProduct, myOfficeSupplies, maxNumber ));
                 //Display the window.
                 frame.pack();
                 frame.setVisible( true );
             } // End method createAndShowGUI
         public void displayData( Product myProduct, OfficeSupplies myOfficeSupplies, int maxNumber )
              JTextArea myTextArea = new JTextArea(); // textarea to display output
              JFrame JFrame = new JFrame( "Products" );
              // For loop to display data array in a single Window
              for ( int counter = 0; counter < maxNumber; counter++ )  // Loop for displaying each product
                   myTextArea.append( packageData( myProduct, myOfficeSupplies, counter ) + "\n\n" );
                   JFrame.add( myTextArea ); // add textarea to JFrame
              } // End For Loop
              JScrollPane scrollPane = new JScrollPane( myTextArea ); //Creates the JScrollPane
              JFrame.setPreferredSize(new Dimension(350, 170)); // Sets the pane size
              JFrame.add(scrollPane, BorderLayout.CENTER); // adds scrollpane to JFrame
              JFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); // Sets program to exit on close
              JFrame.setSize( 350, 170 ); // set frame size
              JFrame.setVisible( true ); // display frame
         } // End method displayData
         public String packageData( Product myProduct, OfficeSupplies myOfficeSupplies, int counter ) // Method for formatting output
              return String.format( "%s: %d\n%s: %s\n%s: %s\n%s: %s\n%s: $%.2f\n%s: $%.2f\n%s: $%.2f\n%s: $%.2f",
              "Product Number", myOfficeSupplies.getProductNumber( counter ),
              "Product Name", myOfficeSupplies.getProductName( counter ),
              "Product Brand",myProduct.getProductBrand( counter ),
              "Number of Units in stock", myOfficeSupplies.getNumberUnits( counter ),
              "Price per Unit", myOfficeSupplies.getUnitPrice( counter ),
              "Total Value of Item in Stock is", myOfficeSupplies.getProductValue( counter ),
              "Restock charge for this product is", myProduct.restockingFee( myOfficeSupplies.getProductValue( counter ) ),
              "Total Value of Inventory plus restocking fee", myOfficeSupplies.getProductValue( counter )+
                   myProduct.restockingFee( myOfficeSupplies.getProductValue( counter ) ) );
         } // end method packageData
    } //End Class Panel

    multarnc wrote:
    My instructor has not been very forthcoming with assistance to her students leaving us to figure it out on our own.Aren't they all the same! Makes one wonder why they are called instructors. <sarcasm/>
    Of course it's highly likely that enough information was imparted for any sincere, reasonably intelligent student to actually figure it out, and learn the subject in the process.
    And if everything were spoonfed, how would one grade the performance of the students? Have them recite from memory
    public class HelloWorld left-brace
    indent public static void main left-parenthesis String left-bracket right-bracket args right-parenthesis left-brace
    And everywhere that Mary went
    The lamb was sure to go
    db

  • Create button to implement windowClosed event

    I am wondering if it is possible to create a button on a forum that would act the same as the X button in the window.
    or if there is another way that i can let my parent frame, that created this new frame, know that the child frame has been closed so that the parent frame can carry on as normal until the next child frame is created.

    ok, i don't think i made my issue clear, but i might be designing this a poor way so let me know.
    my parent frame creates another frame, and listens for it to close
            JFrame edit;
            if ( frame not open ) {
                edit = new Edit_Applicator("Edit Applicator",380, 500, true);
                edit.setAlwaysOnTop(true);
                edit.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosed(WindowEvent winEvt) {
                        do thing;
            }then when i close the child i want it to be able to tell the parent that it has closed. if they click on the X my current method works perfect. however, i want to create an exit button on the child frame that will let the parent frame know it has closed as well.
    i have created the button and the actionlistener for the button, but i'm not sure how to get the button to close the same way that the X button closes the frame, and have the windowlistener in the parent "hear" that the child closed.

  • Swing to Xml

    Hi to all...
    Is there any tool is available for Xml to Java for constructing GUI design in XML.
    That is
    GUI generating engine for Java applications. Graphical User Interfaces are described in XML documents that are parsed at runtime and rendered into javax.swing objects.

    Post a small example program demonstrating your problem. The following demo works for me.
    import java.awt.*;
    import java.beans.*;
    import java.io.*;
    import javax.swing.*;
    public class MyPanel extends JPanel {
        public MyPanel() {
            add(new JLabel("this is a test"));
        public static void main(String[] args) throws IOException {
            MyPanel panel = new MyPanel();
            File file = new File("Test.xml");
            XMLEncoder e = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(file)));
            e.writeObject(panel);
            e.close();
            XMLDecoder d = new XMLDecoder(new BufferedInputStream(new FileInputStream(file)));
            Object result = d.readObject();
            d.close();
            JFrame f = new JFrame("Test");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add((Component) result);
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
    }On a separate note, why create a JPanel subclass if you aren't overriding any methods?

  • How can I stop a JFrame from closing when clicking the close button.

    I need to display a dialog when a user attempts to close my app, giving them the option to close, minimize or cancel. How can I stop the form from closing after the user makes his selection? I have the folllowing code, but my form still closes after selecting an option:
    private void formWindowClosing(java.awt.event.WindowEvent evt) {                                  
            //An array of Strings to be used a buttons in a JOptionDialog
            String[] options = {"Close", "Minimize", "Cancel"};
            //Determines what the user wants to do
            int result = JOptionPane.showOptionDialog(null, "What to you want to do?  Close the application, minimize or cancel?", "Please select an option...", 0, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
           //Determines what to do, depending on the user's choice
            if (result == 0) {
                //Close the application
                System.exit(0);
            } else if (result == 1) {
                //Minimize the application
                this.setState(Frame.ICONIFIED);
        }Any help would be much appreciated!

    import java.awt.event.*;
    import javax.swing.*;
    public class test extends JFrame {
         public static void main( String[] args ) {
              new test();
         public test() {
              setSize( 200, 200 );
              //the next line makes the JFrame not close
              setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE );
              //now add a listener that does the trick
              addWindowListener( new WindowAdapter() {
                        public void windowClosing( WindowEvent e ) {
                             //ask the user and do whatever you wish
              setVisible( true );
    }

  • Close a JFrame from a button?

    How do I close a JFrame using a JButton to trigger the event? I want to dispose of the frame.
    thanks

    I think this peace of code should do it for you:
    public class MyFrame extends JFrame{
    private MyFrame() {
    this.setTitle("MyFrame");
    Container contentPane = this.getContentPane();
    contentPane.setLayout(new BorderLayout());
    // Close the application using a JButton.
    JButton closeButton = new JButton("Close");
    closeButton.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e) {
    System.exit(0);
    contentPane.add(closeButton, BorderLayout.SOUTH);
    // Close the application using the JFrame.
    this.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);

  • How to disable close & minimize button of jframe?

    how can i disable the close and minimize button of the Jframe?

    to disable minimize
    setResizeable(false);
    to inactivate the close button
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

Maybe you are looking for

  • After 10.6.2 upgrade mac mini intermittent wifi

    Mac Mini I bought in aug was working perfectly until i upgraded to 10.6.2 after that I can see if connects to my airport but if does not get to the internet. When diagnostics come up it shows RED for internet and ISP and green for wifi and airport. A

  • Non-english characters in sqlplus

    Friends, 9.0.1,10.2.0.1 CAn the non-english characters be displayed in sqlplus prompt? I have to print the data with some hindi charcaters like name from the report generated via proc. What is teh workaround for this? Thanks

  • Patch for crystal reports 2013 takes 3 hours?

    I am deploying crystal reports server 2013 sp2. I started patch 1, three hours ago. I is still executing. Is this normal? Server has 8 gig ram.

  • SQL Report not Working

    We have this DCM report in SCCM 2007 and we want to migrate it to SCCM 2012. In SCCM 2007, this report is working when you run it in the sccm console, but does not work when you run it in sql management studio. The error that I am encountering in sql

  • Shutdown NOT due to heat

    Whenever I play GTA V on optimal graphics (via GeForce Experience) it powers off after 5-10 minutes and then reboots automatically after another 2-3 mins. It s definitely not an overheating issue, since I know the laptop has been hotter before and I