Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-25-2008, 10:20 AM
Member
 
Join Date: Dec 2007
Posts: 41
willemjav is on a distinguished road
Serious applet problem
Hola dear java friends

I am still hanging in the thin air: can not make my applet to
work from a html-server (get the mysterious
java.lang.ClassFormatError: Incompatible magic value 1008821359 in class file Imgslides)
Other java application (applets) do work when contacting that server.
The image application does work locally.
I do not think there is a java version problem (the applet runs on the
client machine and I do have the latest version of jvm and the applet
runs on my macbook and on the pc of my son).
THIS IS A PRETTY DESPERADO SITUATION, which I’d like to resolve.

The image applet is very flexible because it loads parameters form a source file,
(Setting size of the applet, order of the photos, a text info for each photo
the color and position of the text and the duration of each individual photo.)

Hereby I mail the code of the applet. Feel free to comment on it (of
course especially the error part).
In order the applet works well you need to prepare two more things:
1) a image folder called Imagestore (containing the pictures in jpg)
2) a source file (text only) to set the parameters of the applet
Each line of the source file sets stuff for each photo see the application info
for that:




/*
*
*
* Created on March 2, 2008, 8:10 PM
* The Slideresource file can be found in the folder
* Imagestore that should be in the work directory.
* The Imagestore folder contains all the images (jpg
* one size of the applet).
* first line of Slidessource.txt file is:
* the word imageslideapplet, int appletwidth, int appletheight
* and each following line contains:
* 1) string, image file name (string without space),
* 2) string, the info text (several words) ended by space //.
* 3) string, text color (white, black, green, red, blue).
* 4,5) int, the infotext coordinates in pixels width, height, 0, 0, standard.
* 6) the delay time for each photo in seconds like 9 (sec no miliseconds).
* 7) the number for the cross fades (not done yet).
*/




import java.applet.Applet;
import java.awt.*;
import java.awt.Image;
import java.awt.event.*;
import java.text.DecimalFormat;
import java.util.Scanner;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.net.URL;
import java.io.*;
import java.awt.image.BufferedImage;
import javax.swing.text.BadLocationException;
import java.net.MalformedURLException;



public class Imgslides extends JApplet {
private int count, maxcount, x, y, randcount,
textposx, textposy, imgwidth, imgheight, framew, frameh;
private Scanner scanner;
private Img[] img;
private JOptionPane infoPane;
private JPanel picttextPanel;
private ImageDisplay displayPanel; // The photo and info text panel
private Boolean gate;
private JLabel textLabel;
private Timer imgtimer;




public void init() {
count=0; // image and textstring counters
maxcount = 0;
framew = 350; // frame size to be set
frameh = 390;
textposx = 120; // text position to be set
textposy = 310;
displayPanel = new ImageDisplay();
textLabel = new JLabel();
EventHandler listener = new EventHandler();
imgtimer = new Timer(9000, listener);
imgtimer. setRepeats(true);
setContentPane(displayPanel);
setSize(350,390);
setLocation(0,0);
readsourcedata("Imagestore/Slidessource.txt");
displayPanel.setLayout(null);
textLabel.setBounds(textposy,textposx, 300 , 50);
displayPanel.add(textLabel);
randcount = (int)(maxcount*Math.random()) + 1;
gate = true;
imgtimer.start();
}



private class EventHandler implements ActionListener { // The event listener of the timer.

public void actionPerformed(ActionEvent evt) {

if (evt.getSource() == imgtimer) {
if (gate) // the first photo random picked
count = randcount;
gate = false; // close the random gate
count++;
if (count==maxcount)
count=0;
displayPanel.repaint();
imgtimer.setDelay(img[count].delay*1000); // set the individual delay for each photo

}

}
}



private static class Img { // the image file info record array
String name, info, textcolor;
int delay, fadeout, textx, texty;
}


private Image downloadImage(String filename) { // the image file reader
Image images=null;
URL url;
url = getClass().getResource("Imagestore/" + filename);
try {
images = ImageIO.read(url);
} catch (IOException ex) {
JOptionPane.showMessageDialog(infoPane, "can not read file " + ex);
}
try {
imgwidth = images.getWidth(this);
}
catch (Exception e) {
JOptionPane.showMessageDialog(infoPane, "can not get image width " + e);
}
try {
imgheight = images.getHeight(this);
}
catch (Exception e) {
JOptionPane.showMessageDialog(infoPane, "can not get image height " + e);
}
x = (int)(framew - imgwidth)/2; // to centre the image on the window
y = (int)(frameh - imgheight)/2;

return images;
}





private class ImageDisplay extends JPanel { // Defines the display panel.
public void paintComponent(Graphics g) { // for painting the images

this.setBackground(Color.WHITE);
super.paintComponent(g);
g.drawImage(downloadImage(img[count].name),x, y, imgwidth, imgheight,this); // width/x height/y
textLabel.setBounds(img[count].textx,img[count].texty, 300 , 50); // te image infotext
settextColor(img[count].textcolor); // color, position
textLabel.setText(img[count].info);
}
}



private void settextColor(String str) {

if (str.equalsIgnoreCase("RED"))
textLabel.setForeground(Color.RED);
else
if (str.equalsIgnoreCase("BLUE"))
textLabel.setForeground(Color.BLUE);
else
if (str.equalsIgnoreCase("GREEN"))
textLabel.setForeground(Color.GREEN);
else
if (str.equalsIgnoreCase("WHITE"))
textLabel.setForeground(Color.WHITE);
else
if (str.equalsIgnoreCase("YELLOW"))
textLabel.setForeground(Color.YELLOW);
else
textLabel.setForeground(Color.BLACK);

}





private void readsourcedata(String filename) { // the source file reader
URL txtfile=null;
String str=null, inputLine=null;
BufferedReader in=null;
int i=0, textlength=0;
try {
txtfile = new URL(getDocumentBase(), filename);

}

catch (MalformedURLException ex) {
JOptionPane.showMessageDialog(infoPane,
"can not find the source file " + filename);
ex.printStackTrace();
}

try {
in = new BufferedReader( new InputStreamReader(txtfile.openStream()));

}

catch (IOException ex) {
JOptionPane.showMessageDialog(infoPane,
"can not read the source file " + filename);
ex.printStackTrace();
}


try {
while ((inputLine = in.readLine()) != null)
maxcount++;
maxcount = maxcount - 1; // taking info lines out
img = new Img[maxcount]; // create the image record array
for ( i = 0; i < maxcount; i++) // create the objects
img[i] = new Img();

//JOptionPane.showMessageDialog(infoPane,
// " maxcount " + maxcount + " codebase " + getDocumentBase());
}

catch (IOException ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(infoPane,
"can not read number of lines in file: " + filename);
}


try {

in.close();
}

catch (IOException ex) {

JOptionPane.showMessageDialog(infoPane,
"can not close file: " + filename);
ex.printStackTrace();
}

// open file again for data reading
try {
scanner = new Scanner( new InputStreamReader(txtfile.openStream()));
}

catch (IOException ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(infoPane,
"can not read the source file " + filename);
}
str = scanner.next();
if (str.equalsIgnoreCase("dragstraimageslideapplet")) { // check the file id
framew = scanner.nextInt(); frameh = scanner.nextInt();// read the applet window size

str = scanner.nextLine();

for ( i = 0; i < maxcount; i++) { // reading the data Still INSERT CATCH CLAUSES
img[i].info = ""; // the line count is for array setup
//String str = in.readLine(); // can be ommitted when setting the number at source
img[i].name=scanner.next(); // reads the first token is image filename
str = scanner.next(); // start reading info string // marks end of string
while (!str.equalsIgnoreCase("//")) {
str = str + " ";
img[i].info = img[i].info.concat(str); // putting the string together
str = scanner.next();
}

textlength = img[i].info.length();
textlength = (int)((textlength*6.5)/2)+0; // 6.5
img[i].textcolor = scanner.next();
img[i].texty = scanner.nextInt()+(frameh-70);
img[i].textx = scanner.nextInt() + ((framew/2)-textlength);
img[i].delay = scanner.nextInt();
img[i].fadeout = scanner.nextInt();
str = scanner.nextLine();
}
img[maxcount-1].delay = img[0].delay; // delay shift, one spot advanced
for (i = 1; i < maxcount; i++) // for correct individual photo delay
img[i-1].delay = img[i].delay;

}
else {
JOptionPane.showMessageDialog(infoPane,
filename + " has not the right format");
}
scanner.close();
try {

in.close();
}
catch (IOException ex) {
JOptionPane.showMessageDialog(infoPane,
"can not close file: " + filename);
ex.printStackTrace();
}
} // end of source file reader

}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-25-2008, 06:01 PM
Senior Member
 
Join Date: Jul 2007
Posts: 910
hardwired is on a distinguished road
On this page run time error messages : Java Glossary look under the header Runtime Error Messages for the error "bad magic number".
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
IMPORTANT: Applet Problem Please Help! nvidia Java Applets 1 01-22-2008 03:25 AM
applet problem plz HELP shibajisanyal Java Applets 1 01-09-2008 02:47 AM
Problem Exporting a Jar as an Applet Hank Ag99 Eclipse 0 12-22-2007 10:22 PM
Problem with run Java Applet Albert Java Applets 1 07-13-2007 04:06 PM
Applet problem Ed Java Applets 2 07-02-2007 04:35 PM


All times are GMT +3. The time now is 09:30 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org