当前位置: 技术问答>java相关
为什么我的applet在浏览器里和appletview里运行得不一样?
来源: 互联网 发布时间:2015-09-10
本文导语: 原代码如下: import java.net.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class MyApplet extends JApplet { public void init() { Container...
原代码如下:
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class MyApplet extends JApplet
{
public void init()
{
Container contentPane = getContentPane();
ImagePanel panel = new ImagePanel();
contentPane.add(panel);
}
}
class ImagePanel extends JPanel
{
public ImagePanel()
{
setLayout(new BorderLayout());
JPanel panel = new JPanel();
JButton nextButton = new JButton("NEXT");
panel.add(nextButton);
nextButton.addActionListener(new NextAction());
JButton preButton = new JButton("Preview");
panel.add(preButton);
preButton.addActionListener(new PreAction());
this.add(panel,BorderLayout.SOUTH);
imageURL = ImagePanel.class.getResource(n);
image = new ImageIcon(imageURL);
label = new JLabel(image);
add(label,BorderLayout.CENTER);
}
private class NextAction implements ActionListener{
//让文件名加1
public void actionPerformed(ActionEvent e) {
if(i==7)
{JOptionPane.showMessageDialog(null,new String ("没有了,只有这3张!"));
return;
}
i=i+1;
System.out.println(n);
n=((String)(i+".jpg"));
imageURL = ImagePanel.class.getResource(n);
image =new ImageIcon(n) ;
label.setIcon(image);
System.out.println(n);
}
}
private class PreAction implements ActionListener{
public void actionPerformed(ActionEvent e) {
if(i==5){
JOptionPane.showMessageDialog(ImagePanel.this,new String("Only 3 pic"));
return;
}
i=i-1;
System.out.println(n);
n=((String)(i+".jpg"));
imageURL = ImagePanel.class.getResource(n);
image =new ImageIcon(n);
label.setIcon(image);
System.out.println(n);
}
}
public String n="5.jpg";//代表加载的那个jpg文件.
private URL imageURL;
private JLabel label;
private int i=5;
private ImageIcon image;
}
//为什么我用appletview运行时就能切换图片但是用浏览器时就不能切换图片了呢?
//ie和netscape都不行。
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class MyApplet extends JApplet
{
public void init()
{
Container contentPane = getContentPane();
ImagePanel panel = new ImagePanel();
contentPane.add(panel);
}
}
class ImagePanel extends JPanel
{
public ImagePanel()
{
setLayout(new BorderLayout());
JPanel panel = new JPanel();
JButton nextButton = new JButton("NEXT");
panel.add(nextButton);
nextButton.addActionListener(new NextAction());
JButton preButton = new JButton("Preview");
panel.add(preButton);
preButton.addActionListener(new PreAction());
this.add(panel,BorderLayout.SOUTH);
imageURL = ImagePanel.class.getResource(n);
image = new ImageIcon(imageURL);
label = new JLabel(image);
add(label,BorderLayout.CENTER);
}
private class NextAction implements ActionListener{
//让文件名加1
public void actionPerformed(ActionEvent e) {
if(i==7)
{JOptionPane.showMessageDialog(null,new String ("没有了,只有这3张!"));
return;
}
i=i+1;
System.out.println(n);
n=((String)(i+".jpg"));
imageURL = ImagePanel.class.getResource(n);
image =new ImageIcon(n) ;
label.setIcon(image);
System.out.println(n);
}
}
private class PreAction implements ActionListener{
public void actionPerformed(ActionEvent e) {
if(i==5){
JOptionPane.showMessageDialog(ImagePanel.this,new String("Only 3 pic"));
return;
}
i=i-1;
System.out.println(n);
n=((String)(i+".jpg"));
imageURL = ImagePanel.class.getResource(n);
image =new ImageIcon(n);
label.setIcon(image);
System.out.println(n);
}
}
public String n="5.jpg";//代表加载的那个jpg文件.
private URL imageURL;
private JLabel label;
private int i=5;
private ImageIcon image;
}
//为什么我用appletview运行时就能切换图片但是用浏览器时就不能切换图片了呢?
//ie和netscape都不行。
|
看这里。
http://www.csdn.net/expert/topic/1037/1037476.xml?temp=.64526
http://www.csdn.net/expert/topic/1037/1037476.xml?temp=.64526
|
我也有同样的问题,我还是没看懂,没解决聊问题
|
你可以在IE里打开java控制台,看看有没有异常。
某些类jdk升级之后有不兼容现象?应该不会吧。。。
某些类jdk升级之后有不兼容现象?应该不会吧。。。