• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

save image

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have written a program that will draw a line.
I want a save button which would help me to save the picture in GIF or JPG format.
the program that I hv written to draw the lines is as below:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Lines extends JFrame
{
private String s = (" Using javaStrings ");
public Lines()
{
super(" Drawing Lines ");
setSize(500,165);
show();
}
public void paint( Graphics g)
{
g.setColor(Color.blue);
g.fillRect(20,120,50,5);
g.setColor(Color.blue);
g.fillRect(100,120,50,5);
g.setColor(Color.blue);
g.fillRect(170,120,50,5);
g.setColor(Color.blue);
g.fillRect(240,120,50,5);
g.setColor(Color.blue);
g.fillRect(300,120,50,5);
g.setColor(Color.green);
g.fillRect(70,100,30,5);
g.setColor(Color.green);
g.fillRect(150,100,20,5);
g.setColor(Color.green);
g.fillRect(220,100,20,5);
g.setColor(Color.green);
g.fillRect(290,100,10,5);
g.setColor(Color.red);
g.fillRect(20,150,350,5);

}
public static void main(String[] args)
{
Lines app= new Lines();
app.addWindowListener( new WindowAdapter ()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
}
}
Kindly help me out in saving the image that is been displayed after running this program.
Regards,
Vijju
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch Vijju.
I have modified you program to write to a file Lines.jpg
I do not know if it is the best way.
The example uses com.sun.image.codec.jpeg clases, for which there is no API. You can look at the source code by something like jar -tvf c:\j2sdk1.4.2_01\src.zip com/sun/image/codec/jpeg

[ December 08, 2003: Message edited by: Jose Botella ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic