Pictures on Simple Java GUI won't work.

Joined
Aug 15, 2011
Messages
373
Reaction score
1
Points
18
Your Mac's Specs
Early 2011 13 inch MacBook Pro i5 with 8gb of Ram
Ok so here's my code:

import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

public class Gui extends JFrame{

private JButton reg;
private JButton custom;

public Gui(){
super("The title");
setLayout(new FlowLayout());

reg = new JButton("reg Button");
add(reg);

Icon b = new ImageIcon(getClass().getResource("b.png"));
Icon x = new ImageIcon(getClass().getResource("x.png"));
custom = new JButton("Custom", b);
custom.setRolloverIcon(x);
add(custom);

HandlerClass handler = new HandlerClass();
reg.addActionListener(handler);
custom.addActionListener(handler);
}

private class HandlerClass implements ActionListener{
public void actionPerformed(ActionEvent event) {
JOptionPane.showMessageDialog(null, String.format("%s", event.getActionCommand()));
}

}

}


Main Class:

import javax.swing.JFrame;
class apples{
public static void main(String[] args){

Gui go = new Gui();
go.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
go.setSize(300,200);
go.setVisible(true);

}
}



When I run it, the .png's don't show.
 
OP
M
Joined
Aug 15, 2011
Messages
373
Reaction score
1
Points
18
Your Mac's Specs
Early 2011 13 inch MacBook Pro i5 with 8gb of Ram
We'll after using a picture off the internet instead of one i made in photoshop, it worked.

Topic Closed
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top