import java.awt.Dimension; import java.awt.Font; import java.awt.Image; import java.awt.Graphics; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import javax.swing.JPanel; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.ImageIcon; import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JTextField; import javax.swing.KeyStroke; /** * * @author */ public class PopUp extends JDialog { private JPanel popUpPanel; private JLabel message; private JButton okButton; private JTextField textField; private Image icon; private ImageIcon background; private String frameTitle; private String messageLabel; private String buttonCommand; private PopUp(String title, String label) { frameTitle = title; messageLabel = label; initComponents(); } private void initComponents() { icon = new ImageIcon("c:/pics/mercuryLogo.jpg").getImage().getScaledInstance(300, 300, 0); background = new ImageIcon("c:/pics/popupbck4.jpg"); okButton = new JButton("Ok"); message = new JLabel(); textField = new JTextField(); popUpPanel = new JPanel() { @Override public void paintComponent(Graphics g) { // Scale image to size of component Dimension d = getSize(); g.drawImage(background.getImage(), 0, 0, d.width, d.height, null); super.paintComponent(g); } }; popUpPanel.setOpaque(false); // set this panel's layout to null for absolute positioning of // components popUpPanel.setLayout(null); // set the properties and actions of this button okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // WHAT SHOULD I DO TO THIS COMMAND TO RETURN A VALUE? } }); okButton.setBounds(130, 38, 75, 20); okButton.setFont(new Font("Monospaced", Font.BOLD, 11)); okButton.setBackground(Color.LIGHT_GRAY); okButton.registerKeyboardAction(okButton.getActionForKeyStroke( KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, false)), KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false), JComponent.WHEN_IN_FOCUSED_WINDOW); okButton.registerKeyboardAction(okButton.getActionForKeyStroke( KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, true)), KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true), JComponent.WHEN_IN_FOCUSED_WINDOW); // set the properties of this label message.setText(messageLabel); message.setBounds(10, 3, 500, 30); message.setFont(new Font("Monospaced", Font.BOLD, 12)); textField.setBounds(130, 10, 170, 20); popUpPanel.add(message); popUpPanel.add(okButton); popUpPanel.add(textField); // add the components to this container getContentPane().add(popUpPanel); // set the properties of this dialog setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); setIconImage(icon); setTitle(frameTitle); setSize(350, 100); setLocationRelativeTo(null); setResizable(false); setVisible(true); } public static void popTheInput(String title, String message) { new PopUp(title, message); } public static void main(String[] args) { PopUp.popTheInput("Frame", "Message"); } }