Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jun 26, 2012, 10:25 PM   #1
macuser1232
macrumors 6502a
 
Join Date: Jan 2012
Pictures on Simple Java GUI won't work.

Ok so here's my code:
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.

Last edited by OllyW; Jun 27, 2012 at 01:24 AM. Reason: Code tags
macuser1232 is offline   0 Reply With Quote
Old Jun 26, 2012, 11:17 PM   #2
macuser1232
Thread Starter
macrumors 6502a
 
Join Date: Jan 2012
We'll after using a picture off the internet instead of one i made in photoshop, it worked.

Topic Closed
macuser1232 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Java on Mavericks doesn't seem to work... thinkpatience OS X Mavericks (10.9) 4 Oct 21, 2013 11:03 AM
Why does Java work? AHDuke99 OS X 3 Apr 26, 2013 02:44 PM
Java applet won't run tnsmart OS X 10.8 Mountain Lion 4 Jan 10, 2013 03:38 AM
Can't get Java to work :( freemusic86 OS X 10.8 Mountain Lion 14 Dec 8, 2012 12:34 PM
Java Update won't install portcontrol7 Mac OS X 10.7 Lion 2 Jun 19, 2012 08:27 PM

Forum Jump

All times are GMT -5. The time now is 01:13 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC