0

I am developing a simple database application with Java as the front-end and MySQL as my back-end database. I am trying to use iReport. Now I have a Java form created using Netbeans IDE. I want to have a JButton in that form and when I press that button, I should get a report with some values displayed on it.

Kindly help me out in achieving that.

Alex K
  • 22,315
  • 19
  • 108
  • 236
  • 1
    [What have you tried?](http://www.whathaveyoutried.com/) I mean *besides* asking random strangers on the internet to do it for you. – Andrew Thompson Nov 11 '12 at 22:32
  • Andrew::: Ya I have tried ... but id didnt work... that is why I am asking for help –  Nov 12 '12 at 02:59
  • 1
    *"Ya I have tried"* The question was not *'have you tried anything?'* it was **'what have you tried?'**, pay attention & explain in code. *"but id didnt work..."* Gee, can you vague that up for me? That is about as useful as a screen-door on a submarine. What did you expect to happen? What happened instead? Voting to close as 'not a real question'. – Andrew Thompson Nov 12 '12 at 03:04
  • @venkateshsridharan *iReport* is just an editor for designing report's templates. What is a reason to call it? – Alex K Nov 12 '12 at 10:41

1 Answers1

2

Simply add an ActionListener to the JButton:

JButton btn=new JButton("Do something");

btn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            // do something for button 
        }
});

If you want Netbeans to do it for you:

  • Drag a JButton from the palette to your container (Select Windows > Palette to open the Palette if you don't see it. You use the Palette to drag and drop UI components to the design area)

  • Simply double click on the JButton in question in the designer view and it will auto create an ActionListener and override actionPerformed. and in the method it creates is here you would do the work. It should generate something like:

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
         //TODO: Add your handling code here:
    }
    
David Kroukamp
  • 36,155
  • 13
  • 81
  • 138
  • David :: I know how about actionlisteners... But I want to know what method to call for the ireport to be triggered. –  Nov 12 '12 at 03:00
  • @venkateshsridharan: you can run it as a command line using `ProcessBuilder`, mentioned [here](http://stackoverflow.com/a/5986376/230513). – trashgod Nov 12 '12 at 03:47