>Dialog Box - java.awt.Dialog

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class DialogDemo2 extends JFrame implements ActionListener {
	JPanel p1;
	JButton b1[];
	Dialog2 d2;

	public DialogDemo2() {
		super("win");
		d2 = new Dialog2();
		d2.setVisible(true);

		getContentPane().add(p1 = new JPanel());
		b1 = new JButton[50];
		for (int i = 0; i < b1.length; i++) {
			p1.add(b1[i] = new JButton("Button " + i));
		}
		d2.b1.addActionListener(this);
		d2.b2.addActionListener(this);
		setSize(500, 500);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		Object o1 = e.getSource();
		if (o1 == d2.b1) {
			String s1 = d2.t1.getText();
			String s2 = d2.t2.getText();
			if (s1.equals("sks") && s2.equals("sks")) {
				// perform all the validations
				d2.setVisible(false);
				setVisible(true);
			} else {
				JOptionPane.showMessageDialog(null, "user not authorized");
				d2.t1.setText("");
				d2.t2.setText("");
				d2.t1.requestFocus();
			}
		}
		if (o1 == d2.b2) {
			System.exit(0);
		}
	}

	public static void main(String args[]) {
		new DialogDemo2();
	}
}

class Dialog2 extends JDialog {
	JPanel p2;
	JLabel l1, l2;
	JTextField t1, t2;
	JButton b1, b2;

	public Dialog2() {
		super();
		setSize(200, 300);
		getContentPane().add(p2 = new JPanel());
		p2.add(l1 = new JLabel("Enter id"));
		p2.add(t1 = new JTextField(15));
		p2.add(l2 = new JLabel("Enter password"));
		p2.add(t2 = new JTextField(15));
		p2.add(b1 = new JButton("Save"));
		p2.add(b2 = new JButton("cancel"));
	}
}

Download

Swing Dialogboxes

Dialog Boxes - File, Modelless, Model, Color Dialog box
Dialog Box - java.awt.Dialog


Write your Comment

Name :
Email Id : [ We will not publish your email id ]
Your Comment : [ Maximum 200 chars ]
Enter Security code