Closing a Jframe on button click

Dear all,
Please help me !!!
I am having a jframe inside which I am having a jbutton. I want to close the jframe on that jbutton click.
rock

import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JTextField;
public class Check extends JFrame {
     private javax.swing.JPanel jContentPane = null;
     private JButton jButton = null;
     private JTextField jTextField = null;
     private JButton getJButton() {
          if (jButton == null) {
               jButton = new JButton();
               jButton.addActionListener(new java.awt.event.ActionListener() {
               public void actionPerformed(java.awt.event.ActionEvent e) {                                                          Check pop = new Check();
                           pop.dispose();  // here I want this frame should be close on clicking this button
          return jButton;
     private JTextField getJTextField() {
          if (jTextField == null) {
               jTextField = new JTextField();
          return jTextField;
       public static void main(String[] args) {
          Check c = new Check();
     public Check() {
          super();
          initialize();
     private void initialize() {
          this.setSize(300,200);
          this.setContentPane(getJContentPane());
          this.setTitle("JFrame");
          this.setVisible(true);
     private javax.swing.JPanel getJContentPane() {
          if(jContentPane == null) {
               jContentPane = new javax.swing.JPanel();
               jContentPane.setLayout(new java.awt.BorderLayout());
               jContentPane.add(getJButton(), java.awt.BorderLayout.EAST);
               jContentPane.add(getJTextField(), java.awt.BorderLayout.NORTH);
          return jContentPane;
}THis is my code I use dispose but it is not working

Similar Messages

  • Resizing JFrame on button click to show an image on the JFrame

    Dear All,
    I have a JFrame which has an empty label. On button click I want to set an icon for the label and want the JFrame to be resized to show that icon. I am using frame.pack() and I am not using any other sizing function. The code that I have right now, prints the image on the panel, but does not resize the frame to show the image. Pleae could someone help.package gui;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.Toolkit;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.ItemEvent;
    import java.awt.event.ItemListener;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    public class ComponentDemo extends JPanel implements ActionListener,
    ItemListener, MouseListener, KeyListener {
         private JTextArea textarea;
         private JButton button;
         private final static String newline = "\n";
         private JLabel imageIcon;
         public ComponentDemo() {
              button = new JButton("JButton welcomes you  to CO2001");
              button.addActionListener(this);
              add(button);
              textarea = new JTextArea(10, 50);
              textarea.setEditable(false);
              addMouseListener(this);
              textarea.addKeyListener(this);
              JScrollPane scrollPane = new JScrollPane(textarea);
              add(scrollPane);
              imageIcon = new JLabel();
              add(imageIcon);
              setBackground(Color.pink);
              new JScrollPane(this);
          * Create the GUI and show it. For thread safety, this method should be
          * invoked from the event-dispatching thread.
         private static void createAndShowGUI() {
              // Create and set up the window.
              JFrame frame = new JFrame("Simple FrameDemo");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
              frame.setLocation(700, 200);
              // get the content pane and set the background colour;
              frame.add(new ComponentDemo());
         //     frame.setSize(screenSize);
              // frame.getContentPane().setBackground(Color.cyan);
              // Display the window.
              frame.pack();
              frame.setVisible(true);
              frame.setResizable(true);
         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() {
                        createAndShowGUI();
         @Override
         public void actionPerformed(ActionEvent e) {
              // TODO Auto-generated method stub
              if (e.getSource() instanceof JButton) {
                   // System.out.println(e.getSource());
                   String text = ((JButton) e.getSource()).getText();
                   textarea.append(text + newline);
                   textarea.setBackground(Color.cyan);
                   textarea.setForeground(Color.BLUE);
                   textarea.setCaretPosition(textarea.getDocument().getLength());
                   imageIcon.setIcon(createImageIcon("SwingingDuke.png",
                   "Image to be displayed"));
         @Override
         public void itemStateChanged(ItemEvent arg0) {
              // TODO Auto-generated method stub
         @Override
         public void mouseClicked(MouseEvent arg0) {
              textarea.append("A Mouse click welcomes you to CO2001" + newline);
              textarea.setBackground(Color.green);
              textarea.setCaretPosition(textarea.getDocument().getLength());
         @Override
         public void mouseEntered(MouseEvent arg0) {
              // TODO Auto-generated method stub
         @Override
         public void mouseExited(MouseEvent arg0) {
              // TODO Auto-generated method stub
         @Override
         public void mousePressed(MouseEvent arg0) {
              // TODO Auto-generated method stub
         @Override
         public void mouseReleased(MouseEvent arg0) {
              // TODO Auto-generated method stub
         @Override
         public void keyPressed(KeyEvent e) {
              System.out.println(e.getKeyChar());
              textarea.append("The key " + e.getKeyChar()
                        + " click welcomes you to CO2001" + newline);
              textarea.setBackground(Color.YELLOW);
              textarea.setFont(new Font("Arial", Font.ITALIC, 16));
              textarea.setCaretPosition(textarea.getDocument().getLength());
         @Override
         public void keyReleased(KeyEvent e) {
              System.out.println(e.getKeyChar());
              // textarea.append("The key "+
              // e.getKeyChar()+" click welcomes you to CO2001" + newline);
              // textarea.setBackground(Color.green);
              // textarea.setCaretPosition(textarea.getDocument().getLength());
         @Override
         public void keyTyped(KeyEvent e) {
              // TODO Auto-generated method stub
              System.out.println(e.getKeyChar());
              // textarea.append("The key "+
              // e.getKeyChar()+" click welcomes you to CO2001" + newline);
              // textarea.setBackground(Color.blue);
              // textarea.setCaretPosition(textarea.getDocument().getLength());
         /** Returns an ImageIcon, or null if the path was invalid. */
         protected ImageIcon createImageIcon(String path, String description) {
              java.net.URL imgURL = getClass().getResource(path);
              if (imgURL != null) {
                   System.out.println("found");
                   return new ImageIcon(imgURL, description);
              } else {
                   System.err.println("Couldn't find file: " + path);
                   return null;
    }

    myJPanel.setPerferredSize(new Dimension(new_width, new_hight));
    myJFrame.pack();

  • Closing a JFrame when you click on another JFrame...

    Hi,
    I was hoping someone could help me.
    I have a main application, which assigned to one of my buttons is a new instance of another class which loads up another GUI. What i wish to do is when the user pushes this button and loads up the new GUI, i want this new GUI to close automatically when the user clicks back on to the main application GUI.
    Is this possible???? I have tried searching for a solution, however I have hod no luck :(
    If anyone has any suggestions please let me know, thank you!
    Claire
    x

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Test2 extends JFrame {
      public Test2() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container content = getContentPane();
        JButton jb = new JButton("New Frame");
        content.add(jb, BorderLayout.SOUTH);
        jb.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent ae) { showFrame(); }
        setSize(300,300);
        setVisible(true);
      private void showFrame() {
        JFrame jf = new JFrame("I am new frame");
        jf.setBounds(300,300,200,200);
        jf.getContentPane().add(new JButton("I am button"));
        jf.setVisible(true);
        jf.addWindowListener(new WindowAdapter() {
          public void windowDeactivated(WindowEvent we) { ((JFrame)we.getSource()).setVisible(false); }
      public static void main(String[] args) { new Test2(); }
    }

  • Having Trouble Closing a JFrame With a Button Click in Swing

    I am brand new to Java so this is probably something really stupid.
    On my main form I have a table displaying records from a database. When you double click a record, it pops up a second form showing the details of that record. You can then edit the data in this second form and click a "save" button which saves the data to the database. I want this button to also close that second form, however in the button click event, the second form variable is null.
    Here is some code showing the basic concept:
    public class SampleForm {
        private JButton  saveJobButton;
        private JFrame frame;
        private JFrame editDetailFrame;
        public static void main(String[] args) {
            SampleForm sample = new SampleForm();
            sample.createMainFrame();
        public void createMainFrame() {
            frame = new JFrame();
            JComponent panel = buildPanel(); 
            frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            frame.getContentPane().add(panel); 
            frame.pack();
            frame.setVisible(true);
        public void createEditFrame() {
            editDetailFrame = new JFrame();
            editDetailFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
            JComponent editPanel = new SampleForm().buildDetailPanel();
            editDetailFrame.getContentPane().add(editPanel);
            editDetailFrame.pack();
            editDetailFrame.setVisible(true);
            editDetailFrame.validate();
    // save button
        private JButton getSaveJobButton() {
            if (saveJobButton == null) {
                saveJobButton = new JButton();
                saveJobButton.setText("Save Job");
                saveJobButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent e) {
                       .. saves data to database.
                        // here is where I thought the dispose() should go but the editDetailFrame is null at this point.
                        editDetailFrame.dispose();
            return saveJobButton;
        }Any assistance would be much appreciated.

    That handles the NullPointer, but still doesn't close my second Frame. The editDetailFrame should not be null at this point as I am clicking a button on the editDetailFram itself so I think the problem is that I just don't have a reference to the actual object at that point and my variable is just an empty one.

  • Another JFrame from a Button Click

    Hi...
    I was just wondering how I could write a code where I could bring up another JFrame (let say JFrame2) from a button click on a main JFrame (let say JFrame1)......
    Could anyone show me an example......
    Thanks
    Ashley Q

    Thanks.........
    Btw, I am trying to output 2 different JFrame, by clicking 2 JButtons. On JFrame frame, there's 2 button, the Synthesizer Button which bring up the Synthesizer JFrame and the Recognizer Button which bring up the Recognizer JFrame. However, there's a some problems probably with my coding......Could someone help me...
    import java.io.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class VoicePronunciationSystem extends JFrame implements ActionListener
         public Component createComponents()
              JButton RecognizerButton = new JButton ("Recognizer");
              RecognizerButton.setMnemonic('r');
              RecognizerButton.addActionListener(this);
              JButton SynthesizerButton = new JButton ("Synthesizer");
              SynthesizerButton.setMnemonic('s');
              SynthesizerButton.addActionListener(this);
              JLabel label = new JLabel ("This is a Voice Pronunciation System");
              JPanel panel = new JPanel();
              panel.setBorder(BorderFactory.createEmptyBorder(120,120,120,120));
              panel.setLayout(new GridLayout(1, 1));
              panel.add(label);
              panel.setLayout(new GridLayout(2, 2));
              panel.add(RecognizerButton);
              panel.setLayout(new GridLayout(2, 3));
              panel.add(SynthesizerButton);
              return panel;
         public void actionPerformed(ActionEvent event)
              Object source = event.getSource();
              if( source == RecognizerButton) {
                   JFrame frame2 = new JFrame("Recognition");
                   frame2.getContentPane().add(new JTextField(20));
                   frame2.pack();
                   frame2.setVisible(true);
              if( source == SynthesizerButton) {
                   JFrame frame3 = new JFrame("Synthesizer");
                   frame3.getContentPane().add(new JTextField(20));
                   frame3.pack();
                   frame3.setVisible(true);
         public static void main(String[] args)
              try
                   UIManager.setLookAndFeel(
                   UIManager.getCrossPlatformLookAndFeelClassName());
              } catch (Exception e) { }
              JFrame frame = new JFrame("VoicePronunciationSystem");
              //JFrame frame2 = new JFrame ("Recognition");
              //JLabel label = new JLabel ("This is a Voice Pronunciation System");
              //frame.getContentPane().add(label);
              VoicePronunciationSystem sys = new VoicePronunciationSystem();
              Component contents = sys.createComponents();
              frame.getContentPane().add(contents, BorderLayout.CENTER);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.pack();
              frame.setVisible(true);
    }

  • I somehow set portrait lock on my iphone4, and then closed the app by double clicking the home button.  So now how to I access it again? Or do I have to completely restore my ph to factory settings?

    I somehow set portrait lock on my iphone4, and then closed the app by double clicking the home button. 
    So now how to I access it again? Or do I have to completely restore my ph to factory settings?

    Double click the home button again, slide to the left and tap the screen lock button.

  • Open Dialog box on button click using Visual Webpart

    Hi,
    I am trying to create New Item,Edit Item & Delete Item button in Visual web part.On clicking on the button it should open the corresponding custom form on dialogue box.I don't want to create any button in the ribbon.I just want to create UI page for
    all buttons and also corresponding input forms on button click in Visual web part.
    Is it possible through visual web part?
    I will be needing your initial guidance to achieve this.
    Please help.
    Thank you.

    Hi,
    According to your post, my understanding is that you want to open modal dialog in a visual web part.
    To open a modal dialog, there are multiple ways, such as using JavaScript.
    However, for your scenario, you should register the script from the C# code, there are some articles for this topic, you can refer to them.
    http://www.ashokraja.me/articles/How-to-Programmatically-Show-or-Hide-a-Modal-Popup-Dialog-with-Server-Side-Code-in-Share-Point-2013
    http://blogs.perficient.com/microsoft/2012/01/sharepoint-2010-closing-a-modaldialog-manually-from-code-c-and-javascript/
    More reference:
    http://blogs.msdn.com/b/chaks/archive/2011/09/14/modal-dialog-box-in-sharepoint-sandbox.aspx
    Thanks & Regards,
    Jason
    Jason Guo
    TechNet Community Support

  • Download the PDF Form as a attachment when button click in BSP application

    Hi All,
    I have scenario, when button click in the BSP application PDF Form want to download in the IE (like one window open with Open,Save and cancel button).
    I have written this code:
    data: pdf type fpformoutput-pdf.
    < Logic for populate value to pdf field ....
    .>
    response->set_header_field(
                         name  = 'cache-control'
                         value = 'max-age=0' ).
      response->set_header_field(
                         name  = 'content-disposition'
                         value = 'attachment; filename=webforms.pdf' ).
      response->set_data( data   = pdf ).
    Once button is clicked pop up is opened and closed automatically because of browser or adobe reader issue.
    How can I resolve this problem ?
    In the IE i need to change any settings ?
    IE version = 7.0
    Adobe reader = 9.0
    I have tried in the same code with IE = 6.0 and adobe reader 8.1.2 its getting download the pdf form working fine.
    The same think i want in IE 7.0 and adobe reader 9.0, what needs to be done ?
    Regards,
    Boopathi M

    Hello Ravi,
    Best would be to bind the dataSource of the InteractiveForm ui element to the parent node containing the table's data. Then specify a name of a template to be created in the templateSource and hit <enter>. Some popups later, the system will have created a template from the structure of the context. All you need to do now is to drag&drop the data structure inside the template designer to the template itself. This will result in a table. Save, activate and return the Web Dynpro view. Don't forget to unbind the pdfSource and enjoy.
    Best regards,
    Thomas

  • Problem in refreshing JTree inside Jscrollpane on Button click

    hi sir,
    i have problem in refreshing JTree on Button click inside JscrollPane
    Actually I am removing scrollPane from panel and then again creating tree inside scrollpane and adding it to Jpanel but the tree is not shown inside scrollpane. here is the dummy code.
    please help me.
    import javax.swing.*;
    import java.awt.*;
    import javax.swing.tree.*;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.awt.event.WindowListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    public class Test
    public static void main(String[] args)
         JFrame jf=new TestTreeRefresh();
         jf.addWindowListener( new
         WindowAdapter()
         public void windowClosing(WindowEvent e )
         System.exit(0);
         jf.setVisible(true);
    class TestTreeRefresh extends JFrame
         DefaultMutableTreeNode top;
    JTree tree;
         JScrollPane treeView;
         JPanel jp=new JPanel();
         JButton jb= new JButton("Refresh");
    TestTreeRefresh()
    setTitle("TestTree");
    setSize(500,500);
    getContentPane().setLayout(null);
    jp.setBounds(new Rectangle(1,1,490,490));
    jp.setLayout(null);
    top =new DefaultMutableTreeNode("The Java Series");
    createNodes(top);
    tree = new JTree(top);
    treeView = new JScrollPane(tree);
    treeView.setBounds(new Rectangle(50,50,200,200));
    jb.setBounds(new Rectangle(50,300,100,50));
    jb.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent ae)
              jp.remove(treeView);
              top =new DefaultMutableTreeNode("The Java ");
    createNodes(top);
              tree = new JTree(top);
                   treeView = new JScrollPane(tree);
                   treeView.setBounds(new Rectangle(50,50,200,200));
                   jp.add(treeView);     
                   jp.repaint();     
    jp.add(jb);     
    jp.add(treeView);
    getContentPane().add(jp);
    private void createNodes(DefaultMutableTreeNode top) {
    DefaultMutableTreeNode category = null;
    DefaultMutableTreeNode book = null;
    category = new DefaultMutableTreeNode("Books for Java Programmers");
    top.add(category);
    book = new DefaultMutableTreeNode("The Java Tutorial: A Short Course on the Basics");
    category.add(book);
    book = new DefaultMutableTreeNode("The Java Tutorial Continued: The Rest of the JDK");
    category.add(book);
    book = new DefaultMutableTreeNode("The JFC Swing Tutorial: A Guide to Constructing GUIs");
    category.add(book);
    book = new DefaultMutableTreeNode("Effective Java Programming Language Guide");
    category.add(book);
    book = new DefaultMutableTreeNode("The Java Programming Language");
    category.add(book);
    book = new DefaultMutableTreeNode("The Java Developers Almanac");
    category.add(book);
    category = new DefaultMutableTreeNode("Books for Java Implementers");
    top.add(category);
    book = new DefaultMutableTreeNode("The Java Virtual Machine Specification");
    category.add(book);
    book = new DefaultMutableTreeNode("The Java Language Specification");
    category.add(book);
    }

    hi sir ,
    thaks for u'r suggession.Its working fine but the
    properties of the previous tree were not working
    after setModel() property .like action at leaf node
    is not working,I'm sorry but I don't understand. I think you are saying that the problem is solved but I can read it to mean that you still have a problem.
    If you still have a problem then please post some code (using the [code] tags of course).

  • Please HELP on Button Click. URGENT Folks.!!!

    Folks,
    I need some very URGENT help.
    When I click a Button,how do I associate this Button clicked with a particular Key?
    I am reading data from a Hashtable in the foll.format
    Monday Data [ More Info]
    Tuesday Data [ More Info]
    where :
    Data to display is a Label
    [More Info] is a JButton.
    But I am unable to associate the button clicked with that particular Data.
    ie I am unable to link the button clicked with the Key its associated to.
    So when I click the 2nd More Info Button,I must be associated with Tuesday Data.
    I am not being able to link Button Clicked to its Key Value.
    Any one can help me to get the Key Value please?
    Or is displayng thru Hashtable not right? Do I need to use some
    other collection.
    My code is:
    public class JPanelDemo extends JFrame{
    private JPanel JButtonPanel;
    private Hashtable ht = new Hashtable();
    Enumeration enum;
    String str;
    public JPanelDemo() {
    JButtonPanel = new JPanel();
    Container c = getContentPane();
    // Put Data into Table.
    ht.put("Monday ", new JButton("More Info"));
    ht.put("Tuesday ", new JButton("More Info"));
    ht.put("Wednesday ", new JButton("More Info"));
    ht.put("Thursday ", new JButton("More Info"));
    JButtonPanel.setLayout(new GridLayout(ht.size(),ht.size()) ) ;
    // Instantiate ButtonHandler.
    ButtonHandler handler = new ButtonHandler();
    // Enumerate thru Keys.
    enum = ht.keys();
    while(enum.hasMoreElements()){
    str = (String) enum.nextElement();
    JButtonPanel.add(new JLabel(str)); // Key
    JButton jB = (JButton)ht.get(str); // Value
    JButtonPanel.add(jB);
    jB.addActionListener(handler);
    c.add(JButtonPanel,BorderLayout.NORTH);
    show();
    public static void main(String[] args) {
    JPanelDemo JPanelDemo1 = new JPanelDemo();
    // Inner Class for BUTTON handling.
    private class ButtonHandler implements ActionListener {
    public void actionPerformed(ActionEvent e) {
    JOptionPane.showMessageDialog(null,
    "You Pressed " + e.getActionCommand(),
    "I NEED THE KEY VALUE HERE", /* key VALUE required ie Monday,Tuesday..*?
    0);
    } // End ButtonHandler.
    } // End of class

    Hi,
    i have modified your program to produce the intended results..
    Hope this helps!
    josh
    public class JPanelDemo extends JFrame{
    private JPanel JButtonPanel;
    private Hashtable ht = new Hashtable();
    Enumeration enum;
    String str;
    public JPanelDemo() {
    JButtonPanel = new JPanel();
    Container c = getContentPane();
    // Put Data into Table.
    ht.put("Monday ", new JButton("More Info"));
    ht.put("Tuesday ", new JButton("More Info"));
    ht.put("Wednesday ", new JButton("More Info"));
    ht.put("Thursday ", new JButton("More Info"));
    JButtonPanel.setLayout(new GridLayout(ht.size(),ht.size()) ) ;
    // Instantiate ButtonHandler.
    ButtonHandler handler = new ButtonHandler();
    // Enumerate thru Keys.
    enum = ht.keys();
    while(enum.hasMoreElements()){
    str = (String) enum.nextElement();
    JButtonPanel.add(new JLabel(str)); // Key
    JButton jB = (JButton)ht.get(str); // Value
    JButtonPanel.add(jB);
    jB.addActionListener(handler);
    c.add(JButtonPanel,BorderLayout.NORTH);
    show();
    public static void main(String[] args) {
    JPanelDemo JPanelDemo1 = new JPanelDemo();
    public String compare(JButton b){
    int i = ht.size();
    Enumeration enum1 = ht.keys();
    while(enum1.hasMoreElements()){
    String str = (String) enum1.nextElement();
    JButton jB = (JButton)ht.get(str); // Value
    if( jB.equals(b) ){
    return str;
    return null;
    // Inner Class for BUTTON handling.
    private class ButtonHandler implements ActionListener {
    public void actionPerformed(ActionEvent e) {
    JButton b = (JButton)e.getSource();
    String s = compare(b);
    JOptionPane.showMessageDialog(null,
    "You Pressed " + s,
    "I NEED THE KEY VALUE HERE",0);
    } // End of class

  • Professional way to call that frame on button click?

    Hi
    Nice to get new look and feel for forum :)
    Wel my question is I have a frame which has many buttons textfields labels and other components too.
    On clicking one of the button I am opening a frame which is like calculator(display is same as calculator)
    I am using frame for that calculator.
    My question is that what will be the most professional way to call that frame on button click?
    All you java professionals your kind attention will be appreciated
    Regards

    Good question, I've often wondered this myself!
    Personally, I don't like to use anonymous inner classes for handling events. I generally handle events two ways:
    1. Make the main class implement lots of interfaces and use action commands. eg
    public class MyFrame extends JFrame implements ActionListener {
        public static final String CALC_BUTTON = "cb";
        public MyFrame() {
            super();
            JButton cButton = new JButton("Calculator");
            cButton.addActionListener(this);
            cButton.setActionCommand(CALC_BUTTON);
        public void actionPerformed(ActionEvent ae) {
             if (ae.getActionCommand().equals(CALC_BUTTON) {
                 //do something
    2. Subclass AbstractAction.
    public class MyAction extends AbstractAction {
        //create a constructor specific to the goal
        public MyAction(/*Some arguments*/) {
            //set  variables
        public void actionPerformed(ActionEvent ae) {
             //handle the action
    //and in the main class
    JButton cButton = new JButton("Calculator");
    cButton.setAction(new MyAction());I tend to use the first method more often, but if there's some specific kind of action, then I use the second method.
    I'm interested to know what other people do though. :)
    -Muel

  • 2 Events on single button click in JSP.

    Hello!
    I want your help in the following topic.
    I want to load 1 html-report page as well as i want to open 1 window on the single(same) button click, on the JSP page & as soon as the html-report page gets loaded , the window should get closed.
    I don't know how to do this. If anyone knows please help me in this.
    Thank You.

    I don't see why you want to open a second page, then close the first one.
    However each page must be generated by a separate request from the browser to the server so the essential stuff all has to be done on the client side with JavaScript. JSPs are nothing to do with it. JSPs are intended to do one thing - generate HTML and the JSP has done it's job before the page arrives on your browser.
    To open a popup window your Javascript used Window.open(url, windowName).
    What you'll get with be a pop-up window, so check your browser settings (which may block pop-up windows). This might be a reason to re-think your design.

  • How to run report on Button Click in Forms 9i

    Hi ,
    I want to run a report , when I press button on form
    it is RDF file . I have complied it and create a REP File .
    I has also set the report path in registry / HKEY_LOCAL_MACHINE/ SOFTWARE /ORACLE/ HOME1
    And then i has written these command line on Button click
    Declare
         pl_id           ParamList;
         al_id Alert;
         al_button     Number;
         M_RepFile     Varchar2(80);
    Begin
         pl_id := Get_Parameter_List('tmpdata');
         IF NOT Id_Null(pl_id) THEN
              Destroy_Parameter_List( pl_id );
         END IF;
         pl_id := Create_Parameter_List('tmpdata');
    Run_Product(REPORTS,'sitereport', SYNCHRONOUS,RUNTIME,FILESYSTEM,pl_id,NULL);
    Show_Window('MAIN');
    End;
    Message('Now Closing');Message('Now Closing');
    But only message at last is showing . No report being open .

    Look at this one
    Re: Run Report10g  Through form 10g

  • Invoking another form from a button click..

    Hi,...
    I am a beginner in Java Swing Programming using the Netbeans IDE.I want to invoke a form from an existing form thru a button click; thnx...
    Code:
    1st form : NewJFrame.java
    public class NewJFrame extends javax.swing.JFrame {
    /** Creates new form NewJFrame */
    public NewJFrame() {
    initComponents();
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {
    jButton1 = new javax.swing.JButton();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    jButton1.setText("jButton1");
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(151, 151, 151)
    .addComponent(jButton1)
    .addContainerGap(176, Short.MAX_VALUE))
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(130, 130, 130)
    .addComponent(jButton1)
    .addContainerGap(147, Short.MAX_VALUE))
    pack();
    }// </editor-fold>
    * @param args the command line arguments
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new NewJFrame().setVisible(true);
    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    // End of variables declaration
    2nd Form:
    public class NewJFrame1 extends javax.swing.JFrame {
    /** Creates new form NewJFrame1 */
    public NewJFrame1() {
    initComponents();
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGap(0, 400, Short.MAX_VALUE)
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGap(0, 300, Short.MAX_VALUE)
    pack();
    }// </editor-fold>
    * @param args the command line arguments
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new NewJFrame1().setVisible(true);
    }

    shelton141 wrote:
    using the Netbeans IDE.I want to invoke a form from an existing form thru a button clickNote that, instead of JFrame, we normally use JDialog (either a modal or a non modal) for secondary windows.
    We can add an actionPerformed event to the jButton1 in design mode, or manually like this:
    public NewJFrame() {
        initComponents();
        jButton1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                new NewJFrame1().setVisible(true);
    }

  • Creating tables with a button click

    can anyone give me a sample code for creating multiple tables in a scrollpane
    with a button click.
    Thanks

    Here is an example that returns a JTable in a JScrollPane in a JInternalFrame:
    import java.awt.*;
    import javax.swing.JFrame;
    import javax.swing.JInternalFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import java.awt.GridLayout;
    public class TablaJ extends JPanel{
         public TablaJ(){
         public TablaJ(String data[][], String columnNames[]){
             super(new GridLayout(1,0));
             final JTable table = new JTable(data, columnNames);
            //Create the scroll pane and add the table to it.
            JScrollPane scrollPane = new JScrollPane(table);
            //Add the scroll pane to this panel.
            add(scrollPane);
        static JInternalFrame crearFrameConTabla(String data[][], String columnNames[], String tabla) {
            //Create and set up the window.
            JInternalFrame frame = new JInternalFrame(tabla,true,true,true,true);
            frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            //Create and set up the content pane.
            TablaJ newContentPane = new TablaJ(data, columnNames);
            newContentPane.setOpaque(true); //content panes must be opaque
            frame.setContentPane(newContentPane);
            frame.pack();
            return frame;
    }

Maybe you are looking for

  • No Error Log generated in 'Costing' step in Costing Run (CK40N)

    In the Costing Run, when the 'Costing' step is run (after 'Material selection'  and 'BOM Explosion' steps), it gives a hard stop when it encounters the 1st error, instead of completing the 'Costing ' step and giving an Error Log with material informa

  • Subtotals in ALV Report

    Hello,   I am developing a report using ALV FM, i have field catalog(vbeln posnr matnr netpr). i know how to set subtotals using layout settings once after program execution.but i want subtotals to set before execution( i mean that, in coding itself)

  • Updating .rpd file in oracle Fusion middleware control 11G

    Hi people, I've a problem. I tried to upload my .rpd file by loggin in oracle Fusion middleware control 11G, doing this steps: correaplications-> implantation-> repository -> block editconfiguration-> search repository in folder -> insert password->

  • Image colors depend on the computer that publishes my Domain file?!?!

    Here's a weird one... First, the setup. My site is published from two different computers both using iWeb '08, using the same Domain.sites2 file that's passed from computer to computer using my idisk. The Domain file is always copied down to a local

  • Exporting for After effects CS3

    Hey all, im trying to export some clips from final cut pro 6 to use in After effects. How do i go about doing this without losing any quality? Thanks