Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

urgent help needed

 
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);
}
}
 
You save more money with a clothesline than dozens of light bulb purchases. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!