hi guys..... am a newbie in java i found difficulties when am trying to put picture or an ascii art in jframe maybe u guys can give me some hints....(based on my code),here i submit a part of my code in jframe section:.. import java awt.*; import javax swing.*;import java awt. Color;import javax swing. JOptionPane;import java util. Date;class MyFrame extends JFrame { public void paint ( Graphics g ) {this setBackground(Color. BLACK);g setColor(Color. RED);g setFont(new Font("Serif". Font. BOLD. 18));g drawString("WELCOME". 200. 50);g setFont(new Font("Serif". Font. BOLD. 14));g drawString("\n". 10. 70 );g drawString("Date = " + new Date(). 10. 140); }}
You should never (well almost never) override the paint() method of a JFrame. You should override the paintComponent(Graphics g) method of another component (say a JPanel) and set the component as the 'content pane' of the JFrame
thanks for the reply sabre150.. did you mean i must create a new object inside that frame (like JPanel) instead of painting the frame itself? but how if you want to put picture or even painting the object itself?
but how if you want to put picture or even painting the object itself?
I don't really understand. Do as you have in your current code but do it in the paintComponet method of a JPanel and set the JPanel as the 'content pane' of your JFrame. I don't know how else to say it!
In the future. Swing related questions should be posted in the Swing forum. Read the Swing tutorial on "Custom Painting" for a step by step example:http://java sun com/docs/books/tutorial/uiswing/painting/index html
Forex Groups - Tips on Trading
Related article:
http://forum.java.sun.com/thread.jspa?threadID=5233111
comments | Add comment | Report as Spam
|