Results 1 to 14 of 14
- 01-31-2011, 12:28 AM #1
Member
- Join Date
- Jan 2011
- Posts
- 30
- Rep Power
- 0
Can't put the image on the screen??
For some reason, when I run this code, it won't put the Start.png image on the screen! it puts the 2 Strings on the screen, but not the image..
Any help?
P.S, ignore the unneeded imports at the beginning.
Java Code:import java.awt.*; import javax.swing.*; import javax.swing.event.*; import java.io.*; public class TheWindow extends JFrame{ private StockMarket myPanel; Color customColor = new Color(100,149,237); private boolean loaded; private Image sb; public TheWindow(){ super("ProjectN (Un-named game)"); myPanel = new StockMarket(); myPanel.setBackground(customColor); add(myPanel, BorderLayout.CENTER); } public void loadPics(){ sb = new ImageIcon(getClass().getResource("Start.png")).getImage(); loaded = true; repaint(); } public void paint(Graphics g) { if(g instanceof Graphics2D){ Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } super.paint(g); g.drawString("This is the current state of the game", 60, 100); g.drawString("Things will be added soon, I'm currently working on the basic code", 60, 130); g.drawImage(sb, 10, 10, null); } }Last edited by nickburris; 01-31-2011 at 12:31 AM.
- 01-31-2011, 01:52 AM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,604
- Rep Power
- 5
First, I recommend using paintComponent rather than paint, doing so on something like a JPanel (see Trail: 2D Graphics (The Java™ Tutorials) ). Second, you define a method to load pics but never use it.
- 01-31-2011, 06:35 PM #3
Member
- Join Date
- Jan 2011
- Posts
- 30
- Rep Power
- 0
Yes I do use it,
" g.drawImage(sb, 10, 10, null);" is at the bottom.
- 01-31-2011, 08:22 PM #4
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,604
- Rep Power
- 5
- 01-31-2011, 08:27 PM #5
Member
- Join Date
- Jan 2011
- Posts
- 30
- Rep Power
- 0
I don't understand what you mean.. I'm kind of new to this, I don't know what you mean by "calling" loadPics
- 01-31-2011, 08:32 PM #6
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,604
- Rep Power
- 5
Your class has a method loadPics(). This method creates the Image which you draw later on. If you do not call this method (the way it is currently written), the Image variable sb will never be assigned (eg it will be Null). Call this method in your constructor to assign the sb variable. If you don't know how to call the method, I suggest reading Defining Methods (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
- 01-31-2011, 09:01 PM #7
Member
- Join Date
- Jan 2011
- Posts
- 30
- Rep Power
- 0
- 02-01-2011, 12:15 AM #8
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,604
- Rep Power
- 5
Once again, did you read my posts? The answer is right there...I'm done going in circles with this thread.
- 02-01-2011, 12:39 AM #9
Member
- Join Date
- Jan 2011
- Posts
- 30
- Rep Power
- 0
-
He told you that you can call the code in your constructor for this class. We can help you much better if you clarify what exactly confuses you. Otherwise all of our frustration levels may increase.
- 02-01-2011, 01:43 AM #11
Member
- Join Date
- Jan 2011
- Posts
- 30
- Rep Power
- 0
I'm confused because I don't know where to put the code that calls the method loadPics
- 02-01-2011, 01:45 AM #12
Member
- Join Date
- Jan 2011
- Posts
- 30
- Rep Power
- 0
And I need to call it to "assign" the sb variable, but I though I WAS assigning it when I wrote
because I'm assigning the sb variable to that image..Java Code:sb = new ImageIcon(getClass().getResource("Start.png")).getImage();
-
- 02-01-2011, 01:50 AM #14
Member
- Join Date
- Jan 2011
- Posts
- 30
- Rep Power
- 0
Similar Threads
-
screen captured image@client save@Server BufferedImage OutOfMemoryError:JavaHeapSpace
By mame in forum NetworkingReplies: 1Last Post: 01-27-2011, 08:14 AM -
JxCapture 2 is out for Screen Capturing into Image and Video formats!
By TeamDev in forum Reviews / AdvertisingReplies: 0Last Post: 07-01-2010, 03:56 PM -
Streaming an image byte by byte (and similtaneosly rendering it on screen)
By ea25 in forum New To JavaReplies: 1Last Post: 04-21-2010, 02:28 AM -
displaying image into screen !
By burningflower12 in forum AWT / SwingReplies: 14Last Post: 11-16-2009, 02:02 AM -
ImageSearch in Java (find an image on the screen)
By ribbs2521 in forum New To JavaReplies: 7Last Post: 02-05-2009, 05:48 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks