I'm trying to get the PayPal logo come up when you click the 'rightbutton' is clicked. Unfortunately, all that shows is the default Java logo with the cup of coffee and a pen.
Also, how can I make it so once you click "OK" or "Cancel" it closes the JOptionPane, currently, when you click "OK" nothing happens, it keeps giving you the "OK" / "Cancel" option.
rightbutton = new JButton("Right.");
add(rightbutton);
rightbutton.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event){
//what do we want to happen when we
//click the button
final ImageIcon icon = new ImageIcon("C:\\Users\\Scr3am\\Desktop\\paypal.jpg");
JOptionPane.showOptionDialog(null, "Congratulations, you clicked the button.", "Congrats", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, new Object[] { panel }, icon);
}
}
);
FULL CODE
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class Password extends JFrame {
JButton leftbutton;
JButton centerbutton;
JButton rightbutton;
FlowLayout layout;
Container container;
Password(){
super("Toolbar");
layout = new FlowLayout();
//get bulk of window, so it knows where to put the stuff
container = getContentPane();
setLayout(layout);
//left stuff in here
leftbutton = new JButton("Left");
add(leftbutton);
leftbutton.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event){
//what do we want to happen when we
//click the button
layout.setAlignment(FlowLayout.LEFT);
}
}
);
final JPanel panel = new JPanel();
panel.add(new JButton("OK"));
panel.add(new JButton("Cancel"));
//center stuff in here
centerbutton = new JButton("Center");
add(centerbutton);
centerbutton.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event){
//what do we want to happen when we
//click the button
layout.setAlignment(FlowLayout.CENTER);
layout.layoutContainer(container);
}
}
);
//right stuff in here
rightbutton = new JButton("Right.");
add(rightbutton);
rightbutton.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event){
//what do we want to happen when we
//click the button
try {
final ImageIcon icon = new ImageIcon(ImageIO.read(new File("paypalicon.gif")));
JOptionPane.showOptionDialog(
null,
"Congratulations, you clicked the button.",
"Congrats",
JOptionPane.OK_OPTION,
JOptionPane.PLAIN_MESSAGE,
icon,
new Object[]{"Okay"},
"Okay");
} catch (IOException exp) {
exp.printStackTrace();
}
}
}
);
}
}
Errors:
javax.imageio.IIOException: Can't read input file!
at javax.imageio.ImageIO.read(ImageIO.java:1275)
at Password$3.actionPerformed(Password.java:79)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6414)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3275)
at java.awt.Component.processEvent(Component.java:6179)
at java.awt.Container.processEvent(Container.java:2084)
at java.awt.Component.dispatchEventImpl(Component.java:4776)
at java.awt.Container.dispatchEventImpl(Container.java:2142)
at java.awt.Component.dispatchEvent(Component.java:4604)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4618)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4279)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4209)
at java.awt.Container.dispatchEventImpl(Container.java:2128)
at java.awt.Window.dispatchEventImpl(Window.java:2492)
at java.awt.Component.dispatchEvent(Component.java:4604)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:717)
at java.awt.EventQueue.access$400(EventQueue.java:82)
at java.awt.EventQueue$2.run(EventQueue.java:676)
at java.awt.EventQueue$2.run(EventQueue.java:674)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:690)
at java.awt.EventQueue$3.run(EventQueue.java:688)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:687)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)