This week's book giveaway is in the Agile forum.
We're giving away four copies of Head First Agile and have Andrew Stellman & Jennifer Greene on-line!
See this thread for details.
Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

urgent help needed  RSS feed

 
padma patil
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Following is the code for drawing rectangle using java.awt.Graphics class.
Problem is it is only displaying frame not the rectangle.
what's wroung with this.
import java.awt.Image;
import java.awt.Graphics;
import java.awt.Frame;
import java.awt.Color;
import javax.swing.*;
import java.awt.Component;
public class SaveImage
{
public static void main(String arg[])
{
//JFrame f=new JFrame("Save Image");
Component dummy;
dummy= new JFrame("Save Image");
dummy.addNotify();
Image img=dummy.createImage(200,200);
Graphics g=img.getGraphics();
g.setColor(Color.yellow);
g.fillRect(20,20,100,100);

dummy.setSize(500,500);
dummy.setVisible(true);
}
}

Thanks,
padmashree
 
King Tan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class SaveImage extends JFrame {
public SaveImage(String t) {
super(t);
}
public void paint(Graphics g) {
g.setColor(Color.yellow);
g.fillRect(20,20,100,100);
}
public static void main(String[] args) {
SaveImage imageframe =
new SaveImage("title");
imageframe.setSize(150, 150);
imageframe.setVisible(true);
}
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!