| /* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| */ |
| package demo; |
| |
| public class DisplayDialog extends javax.swing.JDialog { |
| public static final int RET_CANCEL = 0; |
| public static final int RET_OK = 1; |
| |
| //Step 1: Initialize the Groovy class: |
| DisplayProvider display = new DisplayProvider(); |
| |
| public DisplayDialog(java.awt.Frame parent, boolean modal) { |
| super(parent, modal); |
| initComponents(); |
| //Step 2: Call the method in the Groovy class: |
| String text = display.getText().toString(); |
| //Step 3: Do something with the result: |
| displayerField.setText(text); |
| } |
| |
| public int getReturnStatus() { |
| return returnStatus; |
| } |
| |
| /** 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">//GEN-BEGIN:initComponents |
| private void initComponents() { |
| |
| okButton = new javax.swing.JButton(); |
| cancelButton = new javax.swing.JButton(); |
| displayerField = new javax.swing.JTextField(); |
| |
| setTitle("Displayer"); |
| addWindowListener(new java.awt.event.WindowAdapter() { |
| public void windowClosing(java.awt.event.WindowEvent evt) { |
| closeDialog(evt); |
| } |
| }); |
| |
| okButton.setText("OK"); |
| okButton.addActionListener(new java.awt.event.ActionListener() { |
| public void actionPerformed(java.awt.event.ActionEvent evt) { |
| okButtonActionPerformed(evt); |
| } |
| }); |
| |
| cancelButton.setText("Cancel"); |
| cancelButton.addActionListener(new java.awt.event.ActionListener() { |
| public void actionPerformed(java.awt.event.ActionEvent evt) { |
| cancelButtonActionPerformed(evt); |
| } |
| }); |
| |
| org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); |
| getContentPane().setLayout(layout); |
| layout.setHorizontalGroup( |
| layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
| .add(layout.createSequentialGroup() |
| .addContainerGap() |
| .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
| .add(displayerField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 288, Short.MAX_VALUE) |
| .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() |
| .add(okButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 67, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) |
| .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) |
| .add(cancelButton))) |
| .addContainerGap()) |
| ); |
| |
| layout.linkSize(new java.awt.Component[] {cancelButton, okButton}, org.jdesktop.layout.GroupLayout.HORIZONTAL); |
| |
| layout.setVerticalGroup( |
| layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
| .add(layout.createSequentialGroup() |
| .addContainerGap() |
| .add(displayerField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) |
| .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) |
| .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) |
| .add(cancelButton) |
| .add(okButton)) |
| .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) |
| ); |
| |
| pack(); |
| }// </editor-fold>//GEN-END:initComponents |
| |
| private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed |
| doClose(RET_OK); |
| }//GEN-LAST:event_okButtonActionPerformed |
| |
| private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed |
| doClose(RET_CANCEL); |
| }//GEN-LAST:event_cancelButtonActionPerformed |
| |
| private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog |
| doClose(RET_CANCEL); |
| }//GEN-LAST:event_closeDialog |
| |
| private void doClose(int retStatus) { |
| returnStatus = retStatus; |
| setVisible(false); |
| dispose(); |
| } |
| |
| public static void main(String args[]) { |
| java.awt.EventQueue.invokeLater(new Runnable() { |
| public void run() { |
| DisplayDialog dialog = new DisplayDialog(null, true); |
| dialog.addWindowListener(new java.awt.event.WindowAdapter() { |
| @Override |
| public void windowClosing(java.awt.event.WindowEvent e) { |
| System.exit(0); |
| } |
| }); |
| dialog.setVisible(true); |
| } |
| }); |
| } |
| |
| // Variables declaration - do not modify//GEN-BEGIN:variables |
| private javax.swing.JButton cancelButton; |
| private javax.swing.JTextField displayerField; |
| private javax.swing.JButton okButton; |
| // End of variables declaration//GEN-END:variables |
| |
| private int returnStatus = RET_CANCEL; |
| |
| } |