i need some quick help here please..
i have a class names PopUpFrame class
public class PopUpFrame extends JFrame { private JPanel popUpPanel; private JLabel errorMessage; private Image icon; private ImageIcon background; private JButton okButton; private String errorNotificationFrameTitle; private String errorNotificationLabel; private int popUpWindowWidth; private int buttonXPosition; public PopUpFrame() { icon = new ImageIcon("c:/pics/mercuryLogo.jpg").getImage().getScaledInstance(300, 300, 0); background = new ImageIcon("c:/pics/mainbck2.jpg"); okButton = new JButton("Ok"); errorMessage = new JLabel(); errorNotificationFrameTitle = ""; errorNotificationLabel = ""; popUpWindowWidth = 300; buttonXPosition = 110; } public void setComponents(Container cont) { 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 Action closeAction = new AbstractAction() { public void actionPerformed(ActionEvent ae) { int x = JOptionPane.CLOSED_OPTION; if (x == 1) { System.exit(0); } } }; okButton.addActionListener(closeAction); okButton.setBounds(buttonXPosition, 35, 75, 20); okButton.setFont(new Font("Monospaced", Font.BOLD, 11)); okButton.setBackground(Color.LIGHT_GRAY); // set the properties of this label errorMessage.setText(errorNotificationLabel); errorMessage.setBounds(20, 5, 500, 30); errorMessage.setFont(new Font("SansSerif", Font.BOLD, 11)); popUpPanel.add(errorMessage); popUpPanel.add(okButton); // add the panel to the container cont.add(popUpPanel); } /** * Sets the error title for this pop-up frame. * * @param frameTitle title for the pop-up frame */ public void setErrorNotificationFrameTitle(String frameTitle) { errorNotificationFrameTitle = frameTitle; } /** * Sets the error label message for this pop-up frame. * * If the message is too long, extend the width of the pop-up frame, and * make the button in the center by calculating its x coordinate according * to the width of the frame. * * @param labelMessage error message for this pop-up frame */ public void setErrorNotificationLabel(String labelMessage) { if (labelMessage.length() > 50) { popUpWindowWidth = popUpWindowWidth + 300; buttonXPosition = buttonXPosition + 150; } else if (labelMessage.length() > 40) { popUpWindowWidth = popUpWindowWidth + 250; buttonXPosition = buttonXPosition + 120; } else if (labelMessage.length() > 30) { popUpWindowWidth = (popUpWindowWidth * 2) - 200; buttonXPosition = (buttonXPosition * 2) - 60; } errorNotificationLabel = labelMessage; } public void createPopUpFrame() { this.setDefaultCloseOperation(PopUpFrame.EXIT_ON_CLOSE); this.setComponents(this.getContentPane()); this.setTitle(errorNotificationFrameTitle); this.setIconImage(icon); this.setSize(popUpWindowWidth, 100); this.setLocationRelativeTo(null); this.setResizable(false); this.setVisible(true); } }
and i have a simple main class that extends the JFrame class
public class NewMain { public static void main(String[] args) { JFrame f = new JFrame(); PopUpFrame p = new PopUpFrame(); f.setSize(400, 500); f.setVisible(true); f.setLocationRelativeTo(null); p.createPopUpFrame(); } }
my problem here is.. when i run the main class, the popUpFrame object will pop up..
but the problem is it DOESNT ACT like THE JOptionPane...
when i press the exit button.. all the frames are exiting.... how can i resolve this one...
i need this customize frame for my program...