
i have one button.when clicked on it has to show a dialog box.but even click on it several times it has to open dialog box only once. if it is already not opened atleast once,then only it has to open dialog box.plese send code for this.
Thanks in advance raveen

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class Form extends JDialog {
JLabel label1 = new JLabel("Name");
JLabel label2 = new JLabel("Address");
JButton b = new JButton("Submit");
JTextField text1 = new JTextField();
JTextField text2 = new JTextField();
public Form(final Frame f, boolean check) {
super(f, check);
this.setLayout(new GridLayout(3, 2));
this.add(label1);
this.add(text1);
this.add(label2);
this.add(text2);
this.add(b);
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
f.setVisible(false);
}
});
}
}
public class JDialogExample extends JFrame {
Form dialog = new Form(this, false);
public JDialogExample() {
this.getContentPane().setLayout(new FlowLayout());
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final Form dialog = new Form(this, false);
JButton button = new JButton("Show Dialog");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
dialog.setSize(250, 100);
dialog.setVisible(true);
}
});
this.getContentPane().add(button);
}
public static void main(String[] args) {
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
JDialogExample frame = new JDialogExample();
frame.pack();
frame.setVisible(true);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.