Results 1 to 3 of 3
Thread: problem with jpanel
- 02-21-2010, 05:29 PM #1
Member
- Join Date
- May 2008
- Posts
- 24
- Rep Power
- 0
problem with jpanel
would any body how the program below is working
Java Code:package skeleton; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import javax.swing.ImageIcon; import javax.swing.JPanel; public class Board extends JPanel { Image star; public Board() { star=new ImageIcon("img/star.png").getImage(); } public void paint(Graphics g) { Graphics2D graphics2D=(Graphics2D)g; graphics2D.drawImage(star, 100, 10, null); } }
when iam running the application the star.png is drawn without calling repaint method would any body explain why it is happening
Java Code:package skeleton; import javax.swing.JFrame; public class Image1 extends JFrame{ public Image1() { add(new Board()); setResizable(false); setVisible(true); setSize(100,200); setTitle("Amith example"); } public static void main(String[] args) { Image1 image = new Image1(); } }
- 02-21-2010, 05:43 PM #2
First, instead of using paint(...) use paintComponent(...) instead.
Secondly, the paint can be called outside of your control. Like if another window outside of your application crosses over. Or, in this case, when you add the panel to the frame and it's also called when it's shown for the first time.My Hobby Project: LegacyClone
-
Cross-posted: Java 2D - explain component
Original poster, please read this FAQ on cross-posting: BeForthrightWhenCrossPostingToOtherSites
Also just FYI: I notice that in past threads you've been in a habit of posting questions and then ignoring the replies, of never acknowledging having read them. These two behaviors (cross-posting and ignoring replies) can often place you on the do-not-help lists of many forum regulars.
Much luck.Last edited by Fubarable; 02-21-2010 at 06:48 PM.
Similar Threads
-
Problem resizing JPanel on window resize
By Nyet in forum AWT / SwingReplies: 4Last Post: 11-27-2009, 03:13 AM -
Jpanel painting problem
By kcakir in forum AWT / SwingReplies: 3Last Post: 04-15-2009, 10:21 PM -
Not another Jpanel Scrollbar problem!
By jiexx in forum AWT / SwingReplies: 3Last Post: 03-18-2009, 02:09 AM -
Problem on adding JButton on JPanel NEED HELP
By boisk in forum AWT / SwingReplies: 15Last Post: 03-15-2009, 02:27 PM -
Problem with JPanel
By ibanez270dx in forum New To JavaReplies: 2Last Post: 11-09-2007, 05:04 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks