Liang,
You need to have the html page load the java plug-in in order to run this in the
browser. Otherwise, the browser's jvm knows nothing about java 2d or other enhancements
to java since 1.1.7 or so.
You can find an application called HTMLConverter in the bin directory of any jdk that
is at least 1.3. Run this and it will convert html files so they know to load the
plugin before running any java applet.
-Mike
Daniel Guo wrote:
> Hello,
>
> The following code is modified from Java2D
> AlphaComposite, I can run java applet successfully,
> but can not display in web browser, simply is class
> AlphaComp not found. how to solve that?
>
> The another thing is that I try to user a slider
> SRC_OVER method to overlay three images, the first
> half slider swap 1998 and 1999 images the second half
> swap 1999 and 2000 image. Is it possible to do that,
> if so, what additional code need to add so as
> transparency 1999 image and paint 2000 image on the
> second half slider.
>
> Attachment includes the source code and images.
>
> Any help on this will be highly appreciated.
>
> Regards,
> Liang
>
> import java.lang.Integer;
> import java.awt.*;
> import java.awt.event.*;
> import java.awt.font.*;
> import java.awt.geom.*;
> import java.awt.image.*;
> import java.awt.event.ItemListener;
> import java.awt.event.ItemEvent;
> import javax.swing.*;
> import javax.swing.event.*;
>
> public class AlphaComp extends JApplet //implements
> ItemListener
> {
> CompPanel comp;
> JLabel alphaLabel, rulesLabel;
> JComboBox alphas, rules;
> JSlider alphaslide;
> float alpha = 0.5f;
> int rule = 0;
>
> // Initializes the layout of the components.
> public void init() {
> GridBagLayout layOut = new GridBagLayout();
> getContentPane().setLayout(layOut);
>
> GridBagConstraints l = new
> GridBagConstraints();
> l.weightx = 1.0;
> l.fill = GridBagConstraints.BOTH;
> l.gridwidth = GridBagConstraints.RELATIVE;
> alphaLabel = new JLabel();
> alphaLabel.setText("Alpha Value");
>
> alphaLabel.setHorizontalAlignment(JLabel.CENTER);
> layOut.setConstraints(alphaLabel, l);
> getContentPane().add(alphaLabel);
> GridBagConstraints c = new
> GridBagConstraints();
> getContentPane().setLayout(layOut);
>
> l.gridwidth = GridBagConstraints.REMAINDER;
> rulesLabel = new JLabel();
> rulesLabel.setText("Composition Rules");
>
> rulesLabel.setHorizontalAlignment(JLabel.CENTER);
> layOut.setConstraints(rulesLabel, l);
> getContentPane().add(rulesLabel);
>
> GridBagConstraints a = new
> GridBagConstraints();
> a.gridwidth = GridBagConstraints.RELATIVE;
> a.weightx = 1.0;
> a.fill = GridBagConstraints.BOTH;
>
> //Slider used to change the alpha values
> final JSlider alphaslide =
> new JSlider(JSlider.HORIZONTAL, 0, 200,
> (int)(alpha*200));
> alphaslide.setMajorTickSpacing(50);
> alphaslide.setMinorTickSpacing(20);
> alphaslide.setPaintTicks(true);
> getContentPane().add(alphaslide);
>
> //Detects changes in the alpha slider
> alphaslide.addChangeListener(new
> ChangeListener( ) {
> public void stateChanged(ChangeEvent e) {
> alpha = (float)alphaslide.getValue(
> )/200;
> System.out.println("alpha value "+
> alpha);
> comp.changeRule(alpha*2);
> //comp.changeRule(alpha*2, rule);
> }
> });
>
> //Combo box used to change the composition
> rule.
> a.gridwidth = GridBagConstraints.REMAINDER;
> rules = new JComboBox();
> layOut.setConstraints(rules, a);
> rules.addItem("SRC_OVER");
> getContentPane().add(rules);
>
> //Panel that the two primitives are drawn in.
> GridBagConstraints fC = new
> GridBagConstraints();
> fC.fill = GridBagConstraints.BOTH;
> fC.weightx = 1.0;
> fC.weighty = 1.0;
> fC.gridwidth = GridBagConstraints.REMAINDER;
> comp = new CompPanel();
> layOut.setConstraints(comp, fC);
> getContentPane().add(comp);
>
> validate();
> }
>
> }
>
> class CompPanel extends JPanel {
>
> //Alphacomposite used to change the compostion and
> transparency.
> AlphaComposite ac =
> AlphaComposite.getInstance(AlphaComposite.SRC_OVER);
> float alpha = 0.5f;
>
> public CompPanel(){}
>
> // Resets the alpha and composite rules with selected
> items.
> /*public float getAlpha() {
> ac = AlphaComposite.getAlpha(alpha);
> repaint();
> }*/
>
> public float changeRule(float a) {
> //public void changeRule(float a, int rule) {
> alpha = a;
> ac =
> AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
> alpha);
> System.out.println(" ac = " + ac);
> repaint();
> return a;
> }
>
> public void paintComponent(Graphics g) {
> super.paintComponent( g );
> Graphics2D g2 = (Graphics2D) g;
>
> Dimension d = getSize();//size of the drawing
> area
> int w = d.width;
> int h = d.height;
>
> // Creates the buffered image.
> Image img =
> Toolkit.getDefaultToolkit().getImage("98mtrp.gif");
> Image img2 =
> Toolkit.getDefaultToolkit().getImage("99mtrp.gif");
> Image img3 =
> Toolkit.getDefaultToolkit().getImage("00mtrp.gif");
>
> int width = img.getWidth(this);
> int height = img.getHeight(this);
>
> int width2 = img2.getWidth(this);
> int height2 = img2.getHeight(this);
>
> BufferedImage buffImg = new BufferedImage(width,
> height, BufferedImage.TYPE_INT_RGB);
> Graphics2D gbi = buffImg.createGraphics();
>
> BufferedImage buffImg2 = new BufferedImage(width2,
> height2, BufferedImage.TYPE_INT_RGB);
> Graphics2D gbi2 = buffImg2.createGraphics();
>
> // Clears the previously drawn image.
> g2.setColor(Color.white);
> g2.fillRect(0, 0, w, h);
>
> // Draws the image into the buffered image.
>
> gbi.drawImage(img3, 0, 0, null);
> gbi.drawImage(img2, 0, 0, null);
> //gbi.setComposite(ac);
>
> gbi.setComposite(ac);
> gbi.drawImage(img, 0, 0, null);
>
> // Draws the buffered image.
> g2.drawImage(buffImg, null, 0, 0);
> //g2.drawImage(buffImg2, null, 0, 0);
>
> //gbi.setComposite(ac);
>
> //g2.drawImage(buffImg, null, 0, 0);
>
> }
> }
>
> __________________________________________________
> Do You Yahoo!?
> NEW from Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month.
> http://geocities.yahoo.com/ps/info1
>
> ------------------------------------------------------------------------
> Name: Alphacomp.zip
> Type: Zip Compressed Data (application/x-zip-compressed)
> Alphacomp.zip Encoding: base64
> Description: Alphacomp.zip
> Download Status: Not downloaded with message
--
******************************************
Mike Robinson, Computer Science Department
Maharishi University of Management
Fairfield, IA 52557 USA
Voice: 1-641-472-7000 ext. 4300
Email: [EMAIL PROTECTED]
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".