gpt4 book ai didi

java - 访问被拒绝 java.lang.runtimepermission exitvm.0

转载 作者:行者123 更新时间:2023-12-02 05:56:32 24 4
gpt4 key购买 nike

我是小程序新手,我遇到了访问被拒绝的问题 java.lang.runtimepermission exitvm.0 它在 Safari 上向我显示了此错误,Firefox 根本没有向我显示任何内容,我不知道为什么会这样,它在我的 Eclipse 上完美运行,但在 Web 浏览器上不起作用 有帮助吗?谢谢。

    package test;



import javax.imageio.ImageIO;
import javax.swing.*;

import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.image.BufferedImage;
import java.awt.image.FilteredImageSource;
import java.awt.image.ImageFilter;
import java.awt.image.ImageProducer;
import java.awt.image.RGBImageFilter;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.lang.reflect.Method;
public class app extends JApplet{
URL url;
String methodName;
String f1="http://localhost/webpage/upload/suit.jpeg";
String f2="http://localhost/webpage/customers/download.jpeg";
boolean setR=false;
Image image=null;
int x=0;
int y=0;
int endX;
int endY;
int center1;
int center2;
int imageWidth;
int imageHeight;
boolean clicked=false;
int initialX=0;
int initialY=0;
public void init(){
load();
}
public void start(){
load();
}
public void load(){
//String methodName = method.getName();

// try{
Image img= getImage(getDocumentBase(), f1);
makeColorTransparent(img,Color.white);
initialX=img.getWidth(null);
initialY=img.getHeight(null);
// }//catch (InvocationTargetException ex) {
//ex.getTargetException();

// }
}
public Image makeColorTransparent
(Image im, final Color color) {
ImageFilter filter = new RGBImageFilter() {
// the color we are looking for... Alpha bits are set to opaque
public int markerRGB = color.getRGB() | 0xFF000000;

public final int filterRGB(int x, int y, int rgb) {
if ( ( rgb | 0xFF000000 ) == markerRGB ) {
// Mark the alpha bits as zero - transparent
return 0x00FFFFFF & rgb;
}
else {
// nothing to do
return rgb;
}
}
};

ImageProducer ip = new FilteredImageSource(im.getSource(), filter);
image=Toolkit.getDefaultToolkit().createImage(ip);
drawing();
return Toolkit.getDefaultToolkit().createImage(ip);
}
public void drawing(){
Image img=null;
//File f=new File("./src/trans1/download.jpeg");
draw2();
//buff=ImageIO.read(img);
//try {
// img = ImageIO.read(new File("download.jpeg"));
// } catch (IOException e) {
// }
BufferedImage buff=new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
//buff=img;
ImageIcon pic1=null;
//try {
// pic1 = new ImageIcon(ImageIO.read(new File("./src/trans1/download.jpeg")));
System.out.println("I am working");
// } catch (IOException e) {
// TODO Auto-generated catch block
// e.printStackTrace();
//}
JFrame frame=new JFrame();
Graphics2D bGr = buff.createGraphics();
bGr.drawImage(img, 0, 0, null);
bGr.dispose();
buff.getGraphics().drawImage(img, 100, 100, null);

//JLabel label1=new JLabel(pic1);
frame.setSize(300,300);
// frame.add(label1);
// this.add(label1);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(this);
this.addMouseListener(new MouseL());
this.addMouseMotionListener(new MouseList());
frame.setVisible(true);
}
public void draw2(){
BufferedImage buff;
int type;
int width;
int height;
try {
// buff=new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
url = new URL (getCodeBase(), f2 );
buff=ImageIO.read(url);
Image img=ImageIO.read(url);
type=buff.getType();
width=buff.getWidth();
height=buff.getHeight();
Graphics g=buff.getGraphics();
g.drawImage(img, width, height, null);

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
public void draw3(Graphics g, Image img){
g.drawImage(img, 0, 0, null);
// g.drawImage(img, img.getWidth(null), img.getWidth(null), null);
}
public void paint(Graphics g){
Image img=getImage(getDocumentBase(), f2);
draw3(g,img);
draw2();
if(image == null) return;
if(clicked==false){
imageWidth = image.getWidth(this);
imageHeight = image.getHeight(this);}
endX=x+imageWidth;
endY=y+imageHeight;
g.drawImage(image, x, y, imageWidth, imageHeight, this );
if(setR){
g.drawRect(x, y, imageWidth, imageHeight);
center1=(x+endX)/2;
center2=(y+endY)/2;
g.drawRect(center1, y, 3, 3);
g.drawRect(center1,endY, 3,3);
g.drawRect(x, center2, 3, 3);
g.drawRect(endX, center2, 3, 3);
}
}
int inX;
int inY;
int subX;
int subY;
int diffX;
int diffY;
long ratio;
boolean isSet=false;
class MouseList implements MouseMotionListener{
@Override
public void mouseDragged(MouseEvent arg0) {
setR=true;
if(isSet==true){
subX=arg0.getX();
subY=arg0.getY();
diffX=subX-inX;
diffY=subY-inY;
x=x+diffX;
y=y+diffY;
repaint();
inX=arg0.getX();
inY=arg0.getY();
//setR=false;
repaint();
}else{
if(clicked==true){
subY=arg0.getY();
diffY=subY-inY;
if(ratio==0){
ratio=1;
}
diffX=(int) (diffY/ratio);
y=y-diffY;
x=x-diffX;
imageHeight=imageHeight+diffY;
imageWidth=imageWidth+diffX;
//size of the screen
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

//height of the task bar
Insets scnMax = Toolkit.getDefaultToolkit().getScreenInsets(getGraphicsConfiguration());
int taskBarSize = scnMax.bottom;

//available size of the screen
//setLocation(screenSize.width - getWidth(), screenSize.height - taskBarSize - getHeight());
if(imageHeight<0 || imageWidth<0 || imageWidth>=screenSize.width ||imageHeight>=screenSize.height){
imageHeight=initialY;
x=0;
y=0;
imageWidth=initialX;
}
setR=false;
repaint();
}
}
}
@Override
public void mouseMoved(MouseEvent arg0) {
// TODO Auto-generated method stub

}

}
class MouseL implements MouseListener{

@Override
public void mouseClicked(MouseEvent arg0) {
// TODO Auto-generated method stub
if((arg0.getX()<x &&arg0.getY()<y)||(arg0.getX()<x && arg0.getY()>endY)||(arg0.getX()>endX && arg0.getY()<y)||(arg0.getX()>endX && arg0.getY()>endY)){
System.out.println(" 1 I am working");
setR=false;
repaint();
}

}

@Override
public void mouseEntered(MouseEvent arg0) {
/* if(arg0.getX()>x && arg0.getX()<endX && arg0.getY()>y && arg0.getY()<endY){
if(isSet==false){
inX=arg0.getX();
inY=arg0.getY();
isSet=true;
}
}*/
if(arg0.getX()>x && arg0.getX()<endX && arg0.getY()>y && arg0.getY()<endY){
System.out.println("Yes i am here");
Cursor c=new Cursor(Cursor.HAND_CURSOR);
setCursor(c);
}else if((arg0.getX()>=center1 && arg0.getX()<=center1+3)&&((arg0.getY()>=y && arg0.getY()<=y+3)||(arg0.getY()>=endY&& arg0.getY()<=endY+3))||(arg0.getY()>=center2 && arg0.getY()<=center2+3)&&((arg0.getX()>=x && arg0.getX()<=x+3)||(arg0.getX()>=endX && arg0.getX()<=endX+3))){
System.out.println("No i am here");
Cursor c=new Cursor(Cursor.N_RESIZE_CURSOR);
setCursor(c);
}/*else if(arg0.getX()<x || arg0.getX()>endX && arg0.getY()<y || arg0.getY()>endY){
System.out.println(" 1 I am working");
setR=false;
repaint();
}*/

}

@Override
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub

}

@Override
public void mousePressed(MouseEvent arg0) {
System.out.println(x+" "+y+" "+endX+" "+endY+" "+arg0.getX()+" "+arg0.getY());
if(arg0.getX()>x && arg0.getX()<endX && arg0.getY()>y && arg0.getY()<endY){
if(isSet==false){
inX=arg0.getX();
inY=arg0.getY();
isSet=true;
}
//repaint();
System.out.println("2");
}
else if((arg0.getX()>=center1 && arg0.getX()<=center1+3)&&((arg0.getY()>=y && arg0.getY()<=y+3)||(arg0.getY()>=endY&& arg0.getY()<=endY+3))||(arg0.getY()>=center2 && arg0.getY()<=center2+3)&&((arg0.getX()>=x && arg0.getX()<=x+3)||(arg0.getX()>=endX && arg0.getX()<=endX+3))){
if((arg0.getX()>=center1 && arg0.getX()<=center1+3)&&((arg0.getY()>=y && arg0.getY()<=y+3)||(arg0.getY()>=endY&& arg0.getY()<=endY+3))){
ratio=imageHeight/imageWidth;
inY=arg0.getY();
clicked=true;
}
//repaint();
System.out.println("3");
}else if((arg0.getX()<x || arg0.getY()<y)||(arg0.getX()<x || arg0.getY()>endY)||(arg0.getX()>endX || arg0.getY()<y)||(arg0.getX()>endX || arg0.getY()>endY)){
System.out.println(" 1 I am working");
setR=false;
repaint();
System.out.println("4");
}
//repaint();
/*else if((arg0.getX()<x || arg0.getX()>endX)|| (arg0.getY()<y || arg0.getY()>endY)){
System.out.println(" 1 I am working");
setR=false;
repaint();
}*/



}

@Override
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
isSet=false;
// clicked=false;
// setR=false;
// repaint();

}

}


}

最佳答案

问题出在这一行:

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

当设置EXIT_ON_CLOSE时,我们实际上是在尝试让JVM在框架关闭后立即自行关闭。小程序安全管理器(即使小程序是可信的)将阻止这种情况发生。

应该是:

frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
<小时/>

这将解决眼前的问题,但更好的解决方案是废弃该小程序并将所有必要的控件放在一个框架中。完成后,使用 Java Web Start 启动框架.

关于java - 访问被拒绝 java.lang.runtimepermission exitvm.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23047992/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com