Java Swing - save JPanel as GIF/JPEG.
WE are using Java swing to draw graph(Genes, SNP ,repeats etc related to bio-informatics).text files we are using are quite big eg- more than 25 MB. first it makes the process slow.One of our problem is to save whatever "we draw as an image file(GIF/JPEG file)" and another problem is save a data in a data structure(array,vector) which grow upto 15-20 MB.
plotting this data makes the speed too slow.We want to optimize this.
For saving images have a look at JAI - the Java Advanced Imaging API. It's got fairly straightforward ways of saving images. Note that saving as GIF images is not recommended; patents were placed on the encoding so it's no longer a free option. PNG will give you lossless compression like GIF but is more flexible.
http://java.sun.com/products/java-media/jai/
Saving the generated (mined?) data structure for future retrieval can be quite straightforward depending on how you're doing it. The easiest way is simply to serialise it (use an ObjectOutputStream) but this has compatibility problems if you change your data structure.
Saving out in a custom format may seem like a lot of work but it's not all that hard to do. Alternatively you can use one of the Java to XML convertors - in your case this might generate too large a file, however.
YOu can always use Java's zip functions to improve file size should this become problematic.
Hope this helps
Similar Messages
-
How to save applet in image(gif/jpeg) format
Hi there !
how to save applet in image (gif/jpeg) format. i have just gone through JIMI package where serilization is there ,WHERE U CAN SORE in image format ...........can anybudy help me out.........if possible then pleeez provide me some example.
Thanks in advan...........I think that is possible because i have seen some commercial applets that do that.
-http://www.izhuk.com/painter/
-http://www.lawrencegoetz.com/programs/signature/
Thses two saves the image in the server since applets cant write in the host they are running. Maybe it would be possible whit JFS, i don't know.
For now I am trying to store an image draw in the applet on my server.
My idea now is copying the image to a buffer or something, open a connection to the server and receive the image with a perl CGI.
There is an example with text:
-http://java.sun.com/docs/books/tutorial/networking/urls/readingWriting.html
I want to do something similar but with an image. -
How combine a jpeg image & animated gif image & save it as GIF ?
i have an jpeg image, & also aminated gif image, how do i place the animated gif image over (in the center of the image) a jpeg image & save it as gif file ??
First thing you need to do is stop thinking in terms of file formats once the files are in photoshop they are all the same. The exception being vector vs raster. But in this instance the process is rteally the same so 6 on one hand a half a dozen on the other. Or as some would say Tomatoe, tomahtoe(mispelled on purpose).
The jpeg I would assume is the background image and the gif image is the fore ground object. Open the jpeg, and then place the gif file. As long as the fore ground object has transparency, your job is pretty much done. If not, then it will be up to you to mask what you want to keep vs what you don't and apply that selection to the foregrounds layer as a mask.
Google the net or skim the users manual for the keywords - mask, selections, quickmask, pen tool, paths. Each of these can in one way or another take care of your issue.
It would be worth your time to also go through the numerous videos about photoshop and see how its done.
Either go to adobe tv,
Itunes podcasts
or one of the following web sites:
http://kelbytv.com/
http://creativesuitepodcast.com/ -
PL/SQL and Java Swing interface
Everybody in this forum knows that Oracle is the best database around
with many functionalities, stability, performance, etc. We also know
that PL/SQL is a great language to manipulate information directly
in the database with many built in functions, OOP capability,
transaction control, among other features. Today an application that
manipulates information, which needs user interface, requires components
to be developed using different technologies and normally running in
different servers or machines. For example, the interface is done using
a dynamic HTML generator like JSP, PHP, PL/SQL Web Toolkit, etc.
This page is executed in an application server like Oracle iAS or
Tomcat, just to name two, which in turn access a database like Oracle to
build the HTML. Also rich clients like Java applets require an intermediate
server to access the database (through servlets for example) although
it is possible to access the database directly but with security issues.
Another problem with this is that complexity increases a lot, many
technologies, skills and places to maintain code which leads to a greater
failure probability. Also, an application is constantly evolving, new
calculations are added, new tables, changed columns. If you have an
application with product code for example and you need to increase its
size, you need to change it in the database, search for all occurrences
of it in the middle-tier code and perhaps adjust interfaces. Normally
there is no direct dependency among the tier components. On another
issue, many application interfaces today are based on HTML which doesn't
have interactive capabilities like rich-client interfaces. Although it
is possible to simulate many GUI widgets with JavaScript and DHTML, it is
far from the interactive level we can accomplish in rich clients like
Java Swing, Flash MX, Win32, etc. HTML is also a "tag-based" language
originally created to publish documents so even small pages require
many bytes to be transmitted, far beyond of what we see on the screen.
Even in fast networks you have a delay time to wait the page to be
loaded. Another issue, the database is in general the central location
for all kinds of data. Most applications relies on it for security,
transaction and availability. My proposal is to use Oracle as the
central location for interface, processing and data. With this approach
we can create not only the data manipulation procedures in the database,
but procedures that also control and manage user interfaces. Having
a Oracle database as the central location for all components has many
advantages:
- Unique point of maintenance, backup and restore
- Integrated database security
- One language for everything, PL/SQL or Java (even both if desired)
- Inherited database cache, transaction and processing optimizations
- Direct access to the database dictionary
- Application runs on Oracle which has support for many platforms.
- Transparent use of parallel processing, clusters and future
background technologies
Regarding the interface, I already created a Java applet renderer
which receives instructions from the database on how to create GUI
objects and how to respond to events. The applet is only 8kb and can
render any Swing or AWT object/event. The communication is done
through HTTP or HTTPS using Oracles's MOD_PLSQL included in the Apache
HTTP server which comes with the database or application server (iAS).
I am also creating a database framework and APIs in PL/SQL to
create and manipulate the client interface. The applet startup is
very fast because it is very small, you don't need to download large
classes with the client interface. Execution is done "on-demand"
according to instructions received from the database. The instructions
are very optimized in terms of network bandwidth and based on preliminary
tests it can be up to 1/10 of a similar HTML screen. Less network usage
means faster response and means that even low speed connections will
have a good performance (a future development can be to use this in
wireless devices like PDAs e even cell phones, just an idea for now).
The applet can also be executed standalone by using Java Web Start.
With this approach no business code, except the interface, is executed
on the client. This means that alterations in the application are
dynamically reflected in the client, no need to "re-download" the
application. Events are transmitted when required only so network
usage is minimized. It is also possible to establish triggering
events to further reduce network usage. Since the protocol used is
HTTP (which is stateless), the database framework I am creating will
be responsible to maintain the state of connections, variables, locks
and session information, so the developer don't need to worry about it.
The framework will have many layers, from communication up to
application so there will be pre-built functions to handle queries,
pagination, lock, mail, log, etc. The final objective is to have a
rich client application integrated into the database with minimum
programming and maintenance requirements, not forgetting customization
capabilities. Below is a very small example of what can de done. A
desktop with two windows, each window with two fields, a button with an
image to switch the values, and events to convert the typed text when
leaving the field or double-clicking it. The "leave" event also has an
optimization to only be triggered when the text changes. I am still
developing the framework and adjusting the renderer but I think that all
technical barriers were transposed by now. The framework is still in
the early stages, my guess is that only 5% is done so far. As a future
development even an IDE can be created so we have a graphical environment
do develop applications. I am willing to share this with the PL/SQL
community and listen to ideas and comments.
Example:
create or replace procedure demo1 (
jre_version in varchar2 := '1.4.2_01',
debug_info in varchar2 := 'false',
compress_buffer in varchar2 := 'false',
optimize_buffer in varchar2 := 'true'
) as
begin
interface.initialize('demo1_init','JGR Demo 1',jre_version,debug_info,compress_buffer,optimize_buffer);
end;
create or replace procedure demo1_init as
begin
toolkit.initialize;
toolkit.create_icon('icon',interface.global_root_url||'img/switch.gif');
toolkit.create_internal_frame('frame1','Frame 1',50,50,300,136);
toolkit.create_label('frame1label1','frame1',10,10,50,20,'Field 1');
toolkit.create_label('frame1label2','frame1',10,40,50,20,'Field 2');
toolkit.create_text_field('frame1field1','frame1',50,10,230,20,'Field 1','Field 1',focus_event=>true,mouse_event=>true);
toolkit.create_text_field('frame1field2','frame1',50,40,230,20,'Field 2','Field 2',focus_event=>true,mouse_event=>true);
toolkit.set_text_field_event('frame1field1',toolkit.focus_lost_event,'demo1_set_upper',toolkit.get_text_method,'FIELD 1','false');
toolkit.set_text_field_event('frame1field2',toolkit.focus_lost_event,'demo1_set_upper',toolkit.get_text_method,'FIELD 2','false');
toolkit.set_text_field_event('frame1field1',toolkit.mouse_double_clicked_event,'demo1_set_lower',toolkit.get_text_method,'field 1','false');
toolkit.set_text_field_event('frame1field2',toolkit.mouse_double_clicked_event,'demo1_set_lower',toolkit.get_text_method,'field 2','false');
toolkit.create_button('button1','frame1',10,70,100,25,'Switch','Switch the values of "Field 1" and "Field 2"','S','icon');
toolkit.set_button_event('button1',toolkit.action_performed_event,'demo1_switch_fields(''frame1field1'',''frame1field2'')','frame1field1:'||toolkit.get_text_method||',frame1field2:'||toolkit.get_text_method);
toolkit.create_internal_frame('frame2','Frame 2',100,100,300,136);
toolkit.create_label('frame2label1','frame2',10,10,50,20,'Field 1');
toolkit.create_label('frame2label2','frame2',10,40,50,20,'Field 2');
toolkit.create_text_field('frame2field1','frame2',50,10,230,20,'Field 1','Field 1',focus_event=>true,mouse_event=>true);
toolkit.create_text_field('frame2field2','frame2',50,40,230,20,'Field 2','Field 2',focus_event=>true,mouse_event=>true);
toolkit.set_text_field_event('frame2field1',toolkit.focus_lost_event,'demo1_set_upper',toolkit.get_text_method,'FIELD 1','false');
toolkit.set_text_field_event('frame2field2',toolkit.focus_lost_event,'demo1_set_upper',toolkit.get_text_method,'FIELD 2','false');
toolkit.set_text_field_event('frame2field1',toolkit.mouse_double_clicked_event,'demo1_set_lower',toolkit.get_text_method,'field 1','false');
toolkit.set_text_field_event('frame2field2',toolkit.mouse_double_clicked_event,'demo1_set_lower',toolkit.get_text_method,'field 2','false');
toolkit.create_button('button2','frame2',10,70,100,25,'Switch','Switch the values of "Field 1" and "Field 2"','S','icon');
toolkit.set_button_event('button2',toolkit.action_performed_event,'demo1_switch_fields(''frame2field1'',''frame2field2'')','frame2field1:'||toolkit.get_text_method||',frame2field2:'||toolkit.get_text_method);
end;
create or replace procedure demo1_set_upper as
begin
toolkit.set_string_method(interface.global_object_name,toolkit.set_text_method,upper(interface.array_event_value(1)));
toolkit.set_text_field_event(interface.global_object_name,toolkit.focus_lost_event,'demo1_set_upper',toolkit.get_text_method,upper(interface.array_event_value(1)),'false');
end;
create or replace procedure demo1_set_lower as
begin
toolkit.set_string_method(interface.global_object_name,toolkit.set_text_method,lower(interface.array_event_value(1)));
toolkit.set_text_field_event(interface.global_object_name,toolkit.mouse_double_clicked_event,'demo1_set_lower',toolkit.get_text_method,lower(interface.array_event_value(1)),'false');
end;
create or replace procedure demo1_switch_fields (
field1 in varchar2,
field2 in varchar2
) as
begin
toolkit.set_string_method(field1,toolkit.set_text_method,interface.array_event_value(2));
toolkit.set_string_method(field2,toolkit.set_text_method,interface.array_event_value(1));
toolkit.set_text_field_event(field1,toolkit.focus_lost_event,'demo1_set_upper',toolkit.get_text_method,upper(interface.array_event_value(2)),'false');
toolkit.set_text_field_event(field2,toolkit.focus_lost_event,'demo1_set_upper',toolkit.get_text_method,upper(interface.array_event_value(1)),'false');
toolkit.set_text_field_event(field1,toolkit.mouse_double_clicked_event,'demo1_set_lower',toolkit.get_text_method,lower(interface.array_event_value(2)),'false');
toolkit.set_text_field_event(field2,toolkit.mouse_double_clicked_event,'demo1_set_lower',toolkit.get_text_method,lower(interface.array_event_value(1)),'false');
end;Is it sound like Oracle Portal?
But you want to save a layer 9iAS.
Basically, that was the WebDB.(Oracle changed the name to Portal when version 3.0)
Over all, I agree with you.
>>Having a Oracle database as the central location for all components has many
>>advantages:
>>
>>- Unique point of maintenance, backup and restore
>>- Integrated database security
>>- One language for everything, PL/SQL or Java (even both if desired)
>>- Inherited database cache, transaction and processing optimizations
>>- Direct access to the database dictionary
>>- Application runs on Oracle which has support for many platforms.
>>- Transparent use of parallel processing, clusters and future
>>background technologies
I would like to build 'ZOPE' inside Oracle DB as a back-end
Using Flash MX as front-end.
Thomas Ku. -
Chess: java swing help need
Hi, I have just learn java swing and now creating a chess game. I have sucessfully create a board and able to display chess pieces on the board. By using JLayeredPane, I am able to use drag and drop for the piece. However, there is a problem which is that I can drop the chess piece off the board and the piece would disappear. I have try to solve this problem by trying to find the location that the chess piece is on, store it somewhere and check if the chess piece have been drop off bound. However, I could not manage to solve it. Also, I am very confuse with all these layer thing.
Any suggestion would be very helpful. Thanks in advance
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
public class ChessBoard extends JFrame implements MouseListener, MouseMotionListener
Object currentPosition;
Color currentColor;
Dimension boardSize = new Dimension(600, 600);
JLayeredPane layeredPane;
JPanel board;
JPanel box;
JLabel chessPiece;
int xAdjustment;
int yAdjustment;
public ChessBoard()
// Use a Layered Pane for this this application
layeredPane = new JLayeredPane();
getContentPane().add(layeredPane);
layeredPane.setPreferredSize( boardSize );
layeredPane.addMouseListener( this );
layeredPane.addMouseMotionListener( this );
// Add a chess board to the Layered Pane
board = new JPanel();
// set "board" to the lowest layer (default_layer)
layeredPane.add(board, JLayeredPane.DEFAULT_LAYER);
board.setLayout( new GridLayout(8, 8) );
board.setPreferredSize( boardSize );
board.setBounds(0, 0, boardSize.width, boardSize.height);
addShade();
addPiece();
public void addShade()
for (int i = 0; i < 64; i++)
box = new JPanel( new BorderLayout() );
board.add( box, BorderLayout.CENTER );
if( ((i / 8) % 2) == 0)
if( (i % 2) ==0)
box.setBackground(Color.lightGray);
} else {
box.setBackground( Color.white);
} else {
if( (i % 2) ==0)
box.setBackground(Color.white);
} else {
box.setBackground(Color.lightGray);
//Method for adding chess pieces to the board
public void addPiece()
// Add a few pieces to the board
//black pieces
for (int i = 0; i < 64; i++)
//adding black pieces
if (i < 8)
String fileName = i + ".gif";
JLabel blackPieces = new JLabel( new ImageIcon( fileName ) );
JPanel panel = (JPanel)board.getComponent( i );
panel.add( blackPieces );
//adding black pones
if ((i > 7) && (i < 16))
String fileName = "8.gif";
JLabel blackPones = new JLabel( new ImageIcon( fileName ) );
JPanel panel = (JPanel)board.getComponent( i );
panel.add( blackPones );
//jump to white position (Component 48)
if (i == 16) i = 48;
//adding white pones
if(( i > 47 ) && (i < 56))
JLabel whitePones = new JLabel( new ImageIcon("48.gif") );
JPanel panel = (JPanel)board.getComponent( i );
panel.add( whitePones );
//adding white pieces
if (i > 55)
String fileName = i + ".gif";
JLabel whitePieces = new JLabel( new ImageIcon( fileName ) );
JPanel panel = (JPanel)board.getComponent( i);
panel.add( whitePieces );
** Add the selected chess piece to the dragging layer so it can be moved
public void mousePressed(MouseEvent e)
chessPiece = null;
Component c = board.findComponentAt(e.getX(), e.getY());
c.setBackground(Color.red);
if (c instanceof JPanel) return;
Point parentLocation = c.getParent().getLocation();
xAdjustment = parentLocation.x - e.getX();
yAdjustment = parentLocation.y - e.getY();
chessPiece = (JLabel)c;
chessPiece.setLocation(e.getX() + xAdjustment, e.getY() + yAdjustment);
chessPiece.setSize(chessPiece.getWidth(), chessPiece.getHeight());
layeredPane.add(chessPiece, JLayeredPane.DRAG_LAYER);
** Move the chess piece around
public void mouseDragged(MouseEvent me)
if (chessPiece == null) return;
chessPiece.setLocation(me.getX() + xAdjustment, me.getY() + yAdjustment);
** Drop the chess piece back onto the chess board
public void mouseReleased(MouseEvent e)
Component c = board.findComponentAt(e.getX(), e.getY());
int x = (int)c.getBounds().getX();
int y = (int)c.getBounds().getY();
System.out.println(c.getLocation());
System.out.println(x + " "+ y);
c.setBackground(currentColor);
if (chessPiece == null) return;
chessPiece.setVisible(false);
if (c instanceof JLabel)
Container parent = c.getParent();
//remove the piece that is capture
parent.remove(0);
parent.add( chessPiece );
else
Container parent = (Container)c;
parent.add( chessPiece );
chessPiece.setVisible(true);
public void mouseClicked(MouseEvent e) {}
public void mouseMoved(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
private static void createAndShowGUI()
//Make sure we have nice window decorations
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new ChessBoard();
frame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
//Display the window
frame.pack();
frame.setResizable( false );
frame.setLocationRelativeTo( null );
frame.setVisible(true);
public static void main(String[] args)
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI
javax.swing.SwingUtilities.invokeLater( new Runnable()
public void run()
createAndShowGUI();
}import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
public class ChessBoardRx extends JFrame implements MouseListener, MouseMotionListener
Object currentPosition;
Color currentColor;
Dimension boardSize = new Dimension(600, 600);
JLayeredPane layeredPane;
JPanel board;
JPanel box;
JLabel chessPiece;
int xAdjustment;
int yAdjustment;
Container lastParent;
public ChessBoardRx()
// Use a Layered Pane for this this application
layeredPane = new JLayeredPane();
getContentPane().add(layeredPane);
layeredPane.setPreferredSize( boardSize );
layeredPane.addMouseListener( this );
layeredPane.addMouseMotionListener( this );
// Add a chess board to the Layered Pane
board = new JPanel();
// set "board" to the lowest layer (default_layer)
layeredPane.add(board, JLayeredPane.DEFAULT_LAYER);
board.setLayout( new GridLayout(8, 8) );
board.setPreferredSize( boardSize );
board.setBounds(0, 0, boardSize.width, boardSize.height);
addShade();
addPiece();
// populateBoard();
public void addShade()
for (int i = 0; i < 64; i++)
box = new JPanel( new BorderLayout() );
board.add( box, BorderLayout.CENTER );
if( ((i / 8) % 2) == 0)
if( (i % 2) ==0)
box.setBackground(Color.lightGray);
} else {
box.setBackground( Color.white);
} else {
if( (i % 2) ==0)
box.setBackground(Color.white);
} else {
box.setBackground(Color.lightGray);
//Method for adding chess pieces to the board
public void addPiece()
// Add a few pieces to the board
//black pieces
for (int i = 0; i < 64; i++)
//adding black pieces
if (i < 8)
String fileName = i + ".gif";
JLabel blackPieces = new JLabel( new ImageIcon( fileName ) );
JPanel panel = (JPanel)board.getComponent( i );
panel.add( blackPieces );
//adding black pones
if ((i > 7) && (i < 16))
String fileName = "8.gif";
JLabel blackPones = new JLabel( new ImageIcon( fileName ) );
JPanel panel = (JPanel)board.getComponent( i );
panel.add( blackPones );
//jump to white position (Component 48)
if (i == 16) i = 48;
//adding white pones
if(( i > 47 ) && (i < 56))
JLabel whitePones = new JLabel( new ImageIcon("48.gif") );
JPanel panel = (JPanel)board.getComponent( i );
panel.add( whitePones );
//adding white pieces
if (i > 55)
String fileName = i + ".gif";
JLabel whitePieces = new JLabel( new ImageIcon( fileName ) );
JPanel panel = (JPanel)board.getComponent( i);
panel.add( whitePieces );
private void populateBoard() {
int[][] pos = {
{ 9, 7, 5, 1, 3, 5, 7, 9 },
{ 8, 6, 4, 0, 2, 4, 6, 8 }
for(int j = 0; j < 8; j++) {
String fileName = "chessImages/" + pos[0][j] + ".jpg";
JLabel label = new JLabel( new ImageIcon( fileName ) );
JPanel panel = (JPanel)board.getComponent( j );
panel.add( label );
for(int j = 8; j < 16; j++) {
String fileName = "chessImages/" + 11 + ".jpg";
JLabel label = new JLabel( new ImageIcon( fileName ) );
JPanel panel = (JPanel)board.getComponent( j );
panel.add( label );
for(int j = 56, k = 0; j < 64; j++, k++) {
String fileName = "chessImages/" + pos[1][k] + ".jpg";
JLabel label = new JLabel( new ImageIcon( fileName ) );
JPanel panel = (JPanel)board.getComponent( j );
panel.add( label );
for(int j = 48; j < 56; j++) {
String fileName = "chessImages/" + 10 + ".jpg";
JLabel label = new JLabel( new ImageIcon( fileName ) );
JPanel panel = (JPanel)board.getComponent( j );
panel.add( label );
** Add the selected chess piece to the dragging layer so it can be moved
public void mousePressed(MouseEvent e)
chessPiece = null;
Component c = board.findComponentAt(e.getX(), e.getY());
c.setBackground(Color.red);
if (c instanceof JPanel) return;
lastParent = c.getParent();
Point parentLocation = c.getParent().getLocation();
xAdjustment = parentLocation.x - e.getX();
yAdjustment = parentLocation.y - e.getY();
chessPiece = (JLabel)c;
chessPiece.setLocation(e.getX() + xAdjustment, e.getY() + yAdjustment);
chessPiece.setSize(chessPiece.getWidth(), chessPiece.getHeight());
layeredPane.add(chessPiece, JLayeredPane.DRAG_LAYER);
** Move the chess piece around
public void mouseDragged(MouseEvent me)
if (chessPiece == null) return;
chessPiece.setLocation(me.getX() + xAdjustment, me.getY() + yAdjustment);
** Drop the chess piece back onto the chess board
public void mouseReleased(MouseEvent e)
Component c = board.findComponentAt(e.getX(), e.getY());
if(c == null) {
layeredPane.remove(chessPiece);
lastParent.add(chessPiece);
Rectangle r = lastParent.getBounds();
chessPiece.setLocation(r.x+xAdjustment, r.y+yAdjustment);
lastParent.validate();
lastParent.repaint();
return;
int x = (int)c.getBounds().getX();
int y = (int)c.getBounds().getY();
System.out.println(c.getLocation());
System.out.println(x + " "+ y);
c.setBackground(currentColor);
if (chessPiece == null) return;
chessPiece.setVisible(false);
if (c instanceof JLabel)
Container parent = c.getParent();
//remove the piece that is capture
parent.remove(0);
parent.add( chessPiece );
else
Container parent = (Container)c;
parent.add( chessPiece );
chessPiece.setVisible(true);
public void mouseClicked(MouseEvent e) {}
public void mouseMoved(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
private static void createAndShowGUI()
//Make sure we have nice window decorations
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new ChessBoardRx();
frame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
//Display the window
frame.pack();
frame.setResizable( false );
frame.setLocationRelativeTo( null );
frame.setVisible(true);
public static void main(String[] args)
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI
javax.swing.SwingUtilities.invokeLater( new Runnable()
public void run()
createAndShowGUI();
} -
How to convert images to gif/jpeg files
I have created images in java. Now i want to convert this image into a gif/jpeg file so that i can save this gif/jpeg file in one particular folder on the system & also show the same file to the user.
use
javax.imageio.ImageIO.write
for an introduction see:
http://java.sun.com/products/jfc/tsc/articles/javaOne2001/600/ -
Converting swf file to Gif/Jpeg/Png file
Hi,
I want to save a flash file(swf) in the server as gif/jpeg/png file. Problem is that if on the browser i want to take a snapshot of flash file then how can I convert that SWF file to gif file before sending it to server.I used third party java library "Flagstone Software" the sample code for which is as follows:
File aFile = new File("Flashfile.swf");
byte[] bytes = new byte[(int)aFile.length()];
System.out.println("**Number of bytes in before encoding= "+bytes.length);
try {
FileInputStream imageContents = new FileInputStream(aFile);
imageContents.read(bytes);
imageContents.close();
FSMovieObject fsMov = new FSDefineJPEGImage(26,bytes);
byte[] b = ((FSDefineJPEGImage)fsMov).getImage();
ConstructingGif cGIF = new ConstructingGif(b);
catch (FileNotFoundException e) {
//throw new FileNotFoundException("MovieClip.swf");
catch (IOException e) {
//throw new IOException("MovieClip.swf");
The ConstructingGif class simply writes byte array to disk with file extension as gif or jpeg.
Now when I try to open the generated file through Photo Editor, I am being shown the error message as "Can't determine type".
Is this the problem of encoding...If so then what can be the solution? -
What is difference between C# Gzip and Java swing GZIPOutputStream?
Hi All,
I have a Java swing tool where i can compress file inputs and we have C# tool.
I am using GZIPOutputStream to compress the stream .
I found the difference between C# and Java Gzip compression while a compressing a file (temp.gif ) -
After Compression of temp.gif file in C# - compressed file size increased
while in java i found a 2% percentage of compression of data.
Could you please tell me , can i achieve same output in Java as compared to C# using GZIPOutputStream ?
Thank a lot in advance.797957 wrote:
Does java provides a better compression than C#?no idea, i don't do c# programming. and, your question is most likely really: "does java default to a higher compression level than c#".
Btw what is faster compression vs. better compression?meaning, does the code spend more time/effort trying to compress the data (slower but better compression) or less time/effort trying to compress the data (faster but worse compression). most compression algorithms allow you to control this tradeoff depending on whether you care more about cpu time or disk/memory space. -
Save For Web always saves as a GIF
Hi Guys,
I think I may have a bit of a bug with Photoshop CS6 on my Mac. Every time I try to save an image through Save For Web, the file will automatically save as a GIF, regardless of what option I choose from the drop down menu. I have tried a reinstall of Photoshop and checked my setting against someone elses machine but I can't seem to resolve the problem.
When I enter the Save For Web window, in the bottom left hand corner it says 'GIF' (just above the preview button and zoom button), if I was to change the drop down menu in the top right hand corner to JPEG or PNG, the GIF in the bottom left hand corner would stay the same, meaning that the file format would stay as a GIF.
I've added an screenshot to show whats going on, the image in the preview is just text with a outer glow around it.
Any ideas on this, as i'm a bit stumped on what my next move should be.
Cheers,
ChrisNever seen this problem before. Have you tried the classic; resetting your preferences? http://forums.adobe.com/thread/963474?tstart=0
-
Save to Web for JPEG Does Not Work
Originally when I installed CS4, save to web worked great. When I would downsize an image so as to post on the web, it would downsize with ease and I could save it as a JPEG.
Problem now: On the right upper corner of the page, I have it set for JPEG. When I downsize the image to 250, the "GIF" in the far left bottom corner does not convert over to JPEG. Thus, the image is not getting downsized properly as it used to.
I still have Photoshop Elements 7 on my computer so now when I want to downsize an image, I work on it first in CS4, get out of CS4 and then go into PS7.
Again, for weeks, the GIF would turn into JPEG on the far let. Now in CS4 it does not.
What do I need to do to fix this? I have added a screenshot to show my settings in CS4.
Thanks.Are you saying if you select JPEG top right it still says GIF bottom left of the preview window?
How and where are you "downsizing to 250" ? 250 what? -
FirstGUI.java:7: Package java.swing not found in import.
Hi,
I am currently taking JAVA at UGA and am trying to learn the GUI part on my own, since our professor is not going to cover this. This is the first error I get when I compile the program. Any help is greatly appreciated...
Thanks,
Joe
Below is the program...
/* A first GUI. This class creates a label and a button. The count in the label is incremented each
time that the button is pressed.
import java.awt.*;
import java.awt.event.*;
import java.swing.*;
public class FirstGUI extends JPanel {
// Instance variables
private int count = 0; // Number of pushes
private JButton pushButton; // Push button
private JLabel label; // Label
// Initialization method
public void init() {
// Set the layout manager
setLayout( new BorderLayout() );
// Create a label to hold the push count
label = new JLabel("Push Count: 0");
add( label, BorderLayout.NORTH );
label.setHorizontalAlignment( label.CENTER );
// Create a button
pushButton = new JButton("Test Button");
pushButton.addActionListener( new ButtonHandler (this) );
add( pushButton, BorderLayout.SOUTH );
// Method to update push count
public void updateLabel() {
label.setText( "Push Count: " + (++count) );
// Main method to create frame
public static void main(String a[]) {
// Create a frame to hold the application
JFrame fr = new JFrame("FirstGUI ...");
fr.setSize(200,100);
// Create a Window Listener to handle "close" events
WindowHandler 1 = new WindowHandler();
fr.addWindowListener(1);
// Create and initialize a FirstGUI object
FirstGUI fg = new FirstGUI();
fg.init();
// Add the object to the center of the frame
fr.getContentPane().add(fg, BorderLayout.CENTER);
// Display the frame
fr,setVisible( true );
class ButtonHandler implements ActionListener {
private FirstGUI fg;
// Constructor
public ButtonHandler ( FirstGUI fg1 ) {
fg = fg1;
// Execute when an event occurs
public void actionPerformed( ActionEvent e ) {
fg.updateLabel();
}The error is below...
A:\ENGR1140>javac FirstGUI.java
FirstGUI.java:39: Identifier expected.
public static void main(String s[]) {
^
FirstGUI.java:39: 'class' or 'interface' keyword expected.
public static void main(String s[]) {
^
I don't think the actual error is on line 39, I looked in the book that has the code and line 39 is typed just as it is shown in the book.
Below is the program...
/* A first GUI. This class creates a label and a button. The count in the label is incremented each
time that the button is pressed.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class FirstGUI extends JPanel {
// Instance variables
private int count = 0; // Number of pushes
private JButton pushButton; // Push button
private JLabel label; // Label
// Initialization method
public void init() {
// Set the layout manager
setLayout( new BorderLayout() );
// Create a label to hold the push count
label = new JLabel("Push Count: 0");
add( label, BorderLayout.NORTH );
label.setHorizontalAlignment( label.CENTER );
// Create a button
pushButton = new JButton("Test Button");
pushButton.addActionListener( new ButtonHandler (this) );
add( pushButton, BorderLayout.SOUTH );
// Method to update push count
public void updateLabel() {
label.setText( "Push Count: " + (++count) );
// Main method to create frame
public static void main(String s[]) {
// Create a frame to hold the application
JFrame fr = new JFrame("FirstGUI ...");
fr.setSize(200,100);
// Create a Window Listener to handle "close" events
WindowHandler 1 = new WindowHandler();
fr.addWindowListener(1);
// Create and initialize a FirstGUI object
FirstGUI fg = new FirstGUI();
fg.init();
// Add the object to the center of the frame
fr.getContentPane().add(fg, BorderLayout.CENTER);
// Display the frame
fr,setVisible( true );
class ButtonHandler implements ActionListener {
private FirstGUI fg;
// Constructor
public ButtonHandler ( FirstGUI fg1 ) {
fg = fg1;
// Execute when an event occurs
public void actionPerformed( ActionEvent e ) {
fg.updateLabel(); -
Hi people!i need some help
Im a new user for java programming language.Well im programming an application using java swing libraries. I have some problems trying to accesing variables from those swing Jpanels. Ill make it clear....
Im using Netbeans...
I have a class for the window (a JFrame) including 2 Jtextfields and 2 Jlabels
import .......
public class myclass extends javax.swing.JFrame{
public double gp;
public double gv;
public G() {
initComponents();
gpnom=this.gpnom;
gvnom=this.gvnom;
private void TXFgpnom(java.awt.event.ActionEvent evt) { //TXField
gpnom= Double.parseDouble(TXFgpnom.getText());
gvnom= Double.parseDouble(TXFgvnom.getText());
.......//theres a lot of more code .for listeners..next...
Now ive created a new file (a new class)in the same package ,but i cant access public variables from swing class
//the next class was created in a new file
public class hi () {
JPanel prin =(JPanel) new myclass().getContentPane(); //ok
double number=gpnom // error variable not found
When i try to get the value of "number" ...i always get "ERROR" And the class for that textfield was public..i think...
HOw can i use variables from that Jpanel?
Id appreciate an answer...
thanx for your help!
PacoIn future Swing related questions should be posted in the Swing forum and camickr will be more likely to answer if you have used code tags to properly format your code.
Luckily this problem does not seem to be Swing related in the least because the public variables you have in your other class are named gp and gv and further when you access public variables (or properties) of a class you must access them by an instance of that class. Which you don't appear to be doing either. -
i want to use ACME's GifEncoder to encode the JPanel as gif ...
for encoding Jpeg, i just printAll() the JPanel to form a BufferedImage for encoding ...
but the GifEncode need a Image object (not BufferedImage), so how could i create a BufferedImage from a JPanel ??
thxHi Yundi! :-)
One hand washes the other one, right?
I suppose you mean: How to create an Image from a JPanel and not a BuffedImage?
I do this like that (ok, bit of dirty way, but I have to scale my image):
BufferedImage bi;
Image img = bi.getScaledInstance( width, height, Image.SCALE_DEFAULT ); -
Use Adobe Reader (or others) in Java Swing
Hi,
is there an adobe solution to show pdf files inside an java swing application?
Regards
Arno>(1.)Is there a limit to saving the form data?
It is my understanding that you can harvest data from a form 500 times whether that be from one user of 500 users.
>(2.)If there is a limit to saving the form like 500 times, can the same form be recreated and the limit of 500 starts all over again
You'd probably be walking on thin ice by trying that. Could be a loophole but maybe not.
>(3.)Do I need to purchase a license to save these form data?
Not if you stay within the limit that is stated in the EULA.
>(4.)How many forms can have enable usage rights in Adobe Reader per Adobe Acrobat professional?
Different forms? As far as I know there is no limit to the amount of different forms you use.
In my opinion, if you think you are going to go anywhere near the limitations of the EULA, consult with your attorney before proceeding. The form enabling function was never intended for large business use. Adobe has another, more costly, solution for that. -
Placing a telnet session within a java swing program
I was wondering if there was a way to maybe anchor a telnet session into a JPanel within a Java Swing program. Most of my users end up running a telnet session while using my Swing Program and I was hoping to find a way to bring the two together. If this is possible could someone point me in the right direction (like an online resource) that might show me how to do this.
You could use sockets and a TextArea and build your own simple telnet application.
Socket tutorial: http://java.sun.com/docs/books/tutorial/networking/sockets/index.html
Maybe you are looking for
-
I recently downloaded my itunes account to a hard drive whilst my laptop was wiped and cleared of viruses. Having now re downloaded itunes and logged into my account my music etc doesnt show. When i download itunes from the hard drive and found it on
-
I'm told I have to install Flash Player, when I try to install it, it says I already have it (??????)
-
I had a stolen macbook pro 15 "
I had a stolen macbook pro 15 "MD546LL/A S/N: C0******24T. Please help me find it! It is very important to me, my 1.5 year of heavy labour! <Edited by Host>
-
Frame rate problems with Apple Intermediate Codec.
Hi, I have just upgraded to a new Mac Pro and FCE 4.1. I went to carry on working with an existing FCE HD file. It loaded and updated fine. When the project was played back it appeared jumpy and too fast. I looked at the clip properties and the FPS f
-
Tree - selecting and expanding root node
I want to have a tree root node expanded at start. I have tried: tree.selectedIndex = 0; if (tree.selectedItem && tree.dataDescriptor.isBranch(tree.selectedItem)) tree.expandChildrenOf(tree.selectedItem, true); ...but it doesnt work. Anyone ...?