Part of my web site requires the need to run an Applet that talks directly to a client device. My applet acquires an image and sends it back to the server. My applet skills are minimal and I would like to contract out development of a specific part of this applet for re-displaying the acquired image and
providing the use a button to try again.
## Deliverables
All I need for this bid is to see a test applet with a button
that will process the actionlistener and redisplay the
applet with a new image.
The following test applet may be a starting point for you.
I can integrate the modified test applet into my web
site for testing. If the applet refreshes or redisplays a
new image based on an event, then I will be able to
integrate this into the real applet in my product.
=========================================
package [login to view URL];
import [login to view URL];
import java.applet.*;
import java.awt.*;
import [login to view URL];
import [login to view URL];
import [login to view URL];
import javax.swing.*;
import javax.swing.border.*;
import [login to view URL];
import java.awt.event.*;
import [login to view URL];
import [login to view URL];
import [login to view URL];
import [login to view URL];
import [login to view URL];
import [login to view URL];
import [login to view URL];
import [login to view URL];
public class TestApplet extends JApplet
implements ActionListener {
private TextField nameField = null;
private JButton buttonRetry = null;
private JButton buttonSave = null;
private JButton imageButton = null;
private static String BUTTON_RETRY = "Retry";
private static String BUTTON_SAVE = "Save";
private ImageIcon imageIcon = null;
private ImageButton imgButton = null;
byte[] readBuf;
public TestApplet() throws HeadlessException
{
super();
}
public static void main(String[] args) {
}
public void destroy() {
[login to view URL]();
}
public void init() {
[login to view URL]();
try {
readBuf = getBytesFromFile(new
File("C:\\dfvault\\[login to view URL]"));
} catch (Exception e) {}
//BufferedImage bufImg = new
BufferedImage(readBuf);
imageIcon = new ImageIcon(readBuf);
imageButton = new JButton(imageIcon);
[login to view URL]([login to view URL]);
[login to view URL](true);
[login to view URL]([login to view URL]([login to view URL]));
[login to view URL]([login to view URL]);
buttonRetry = new JButton( BUTTON_RETRY
);
buttonSave = new JButton( BUTTON_SAVE
);
nameField = new TextField("press a
button",20);
[login to view URL]( this );
[login to view URL]( this );
add(buttonRetry,
BorderLayout.PAGE_START);
//add(buttonSave, [login to view URL]);
add(imageButton, [login to view URL]);
add(nameField, BorderLayout.PAGE_END);
setVisible(true);
}
public void actionPerformed( ActionEvent
actionEvent ) {
String actionName =
[login to view URL]().trim();
if ([login to view URL]() ==
buttonRetry) {
[login to view URL]("Retry button was
pressed!");
try {
readBuf = getBytesFromFile(new
File("C:\\dfvault\\owner_3\\[login to view URL]"));
} catch (Exception e) {}
imageIcon = new ImageIcon(readBuf);
imageButton = new JButton(imageIcon);
[login to view URL]([login to view URL]);
[login to view URL](true);
[login to view URL]([login to view URL]([login to view URL]));
[login to view URL]([login to view URL]);
repaint();
}
else if ([login to view URL]() ==
buttonSave) {
[login to view URL]("Save button was
pressed!");
repaint();
}
}
public void paint(Graphics g) {
[login to view URL]([login to view URL](), 20,
100);
}
public class ImageButton extends JButton {
protected void paintComponent(Graphics g)
{
// Paint the default look of the
button.
[login to view URL](g);
// Your custom painting here.
//[login to view URL](foregroundImage, 0, 0,
this);
}
}
public void start() {
// TODO Auto-generated method stub
[login to view URL]();
}
public void stop() {
// TODO Auto-generated method stub
[login to view URL]();
}
public byte[] getBytesFromFile(File file)
throws IOException {
InputStream is = new
FileInputStream(file);
long length = [login to view URL]();
if (length > Integer.MAX_VALUE) {
// File is too large
return null;
}
byte[] bytes = new byte[(int)length];
int offset = 0;
int numRead = 0;
while (offset < [login to view URL]
&& (numRead=[login to view URL](bytes, offset,
bytes.length-offset)) >= 0) {
offset += numRead;
}
if (offset < [login to view URL]) {
throw new IOException("Could not
completely read file "+[login to view URL]());
}
[login to view URL]();
return bytes;
}
}