Mac Forums

Mac Forums (
-   OS X - Development and Darwin (
-   -   Pictures on Simple Java GUI won't work. (

macuser1232 06-26-2012 11:37 PM

Pictures on Simple Java GUI won't work.
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");

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

HandlerClass handler = new HandlerClass();

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();


When I run it, the .png's don't show.

macuser1232 06-27-2012 12:18 AM

We'll after using a picture off the internet instead of one i made in photoshop, it worked.

Topic Closed

All times are GMT -4. The time now is 12:17 AM.

Powered by vBulletin
Copyright ©2000 - 2015, Jelsoft Enterprises Ltd.