New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

Pictures on Simple Java GUI won't work.


Post Reply New Thread Subscribe

 
Thread Tools
macuser1232

 
Member Since: Aug 15, 2011
Posts: 372
macuser1232 can only hope to improve
Mac Specs: Early 2011 13 inch MacBook Pro i5 with 8gb of Ram

macuser1232 is offline
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.
QUOTE Thanks
macuser1232

 
Member Since: Aug 15, 2011
Posts: 372
macuser1232 can only hope to improve
Mac Specs: Early 2011 13 inch MacBook Pro i5 with 8gb of Ram

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

Topic Closed
QUOTE Thanks

Post Reply New Thread Subscribe


« Xcode Destination Issue | Open a GUI app as root command line? »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
Java - Help please! leemarquis OS X - Operating System 10 08-28-2007 05:09 PM
weird java problem rerks OS X - Apps and Games 0 01-28-2007 05:59 AM
java question rerks OS X - Operating System 0 01-23-2007 03:05 AM
AN ultra simple Java app develpoment studio? indykid Web Design and Hosting 0 07-04-2005 03:01 PM
Java From Terminal jdgti OS X - Development and Darwin 10 03-26-2005 07:16 PM

All times are GMT -4. The time now is 05:29 PM.

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

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?