javax.jnlp.UnavailableServiceException: uninitialized問題

zhonghuaas 2014-01-03 10:05:23
//Loading, displaying and scaling an image in an applet

import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.jnlp.FileContents;
import javax.jnlp.FileOpenService;
import javax.jnlp.ServiceManager;
import javax.swing.ImageIcon;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class LoadImageAndScale extends JApplet
{
private ImageIcon image;//references image to display
private JPanel scaleJPanel;//JPanel containing the scale-selector
private JLabel percentJLabel;//label for JTextField
private JTextField scaleInputJTextField;//obtains user's input
private JButton scaleChangeJButton;//initiates scaling of image
private double scaleValue = 1.0; //scale percentage for image

//load image when applet is loaded
public void init()
{
scaleJPanel = new JPanel();
percentJLabel = new JLabel("scale percent:");
scaleInputJTextField = new JTextField("100");
scaleChangeJButton= new JButton("Set Scale");

// add components and place scaleJPanel in applet's NORTH region
scaleJPanel.add(percentJLabel);
scaleJPanel.add(scaleInputJTextField);
scaleJPanel.add(scaleChangeJButton);
add(scaleJPanel,BorderLayout.NORTH);

//register event handler for scaleChangeJButton
scaleChangeJButton.addActionListener(
new ActionListener()
{
//when the JButton is pressed,set scaleValue and repaint
public void actionPerformed(ActionEvent e)
{
scaleValue = Double.parseDouble(
scaleInputJTextField.getText())/100.0;
repaint();//causes image to be redisplayed at new scale
}// end method actionPerformed
}//end anonymous inner class
);//end call to addActionListener

//use JNLP services to open an image file that the user selects
try
{
//get a reference to the FileOpenService
FileOpenService fileOpenService =
(FileOpenService) ServiceManager.lookup(
"javax.jnlp.FileOpenService");

//get file's contents from the FileOpenService
FileContents contents =
fileOpenService.openFileDialog(null, null);

//byte array to store image's data
byte[] imageData = new byte[(int) contents.getLength()];
contents.getInputStream().read(imageData);//read image bytes
image = new ImageIcon(imageData);//create the image

//if image successfully loaded,create and add DrawJPanel
add(new DrawJPanel(),BorderLayout.CENTER);
}//end try
catch(Exception e)
{
e.printStackTrace();
}// end catch
}//end method init

//DrawJPanel used to display loaded image
private class DrawJPanel extends JPanel
{
//display image
public void paintComponent(Graphics g)
{
super.paintComponent(g);

//the following values are used to center the image
double spareWidth=
getWidth()-scaleValue*image.getIconHeight();
double spareHeight=
getHeight()-scaleValue*image.getIconHeight();

//draw image with scaled width and height
g.drawImage(image.getImage(),
(int) (spareWidth)/2,(int)(spareHeight)/2,
(int) (image.getIconWidth()*scaleValue),
(int) (image.getIconHeight()*scaleValue),this);
}//end method paint
}//end class DrawJPanel

}//end class LoadImageAndScale
----------------------------------
以上是源码。在eclipse里编的,然后直接运行run。但没有出现“open”对话框。是和java start有关吗?如何达成效果啊,可以用eclipse做到吗?

----------------------------
javax.jnlp.UnavailableServiceException: uninitialized
at javax.jnlp.ServiceManager.lookup(Unknown Source)
at LoadImageAndScale.init(LoadImageAndScale.java:61)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)


这是错误信息。
---------
没有出现“open”对话框,这是为什么啊?
...全文
335 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
另一花生 2014-01-30
  • 打赏
  • 举报
回复
想回答,但是你这种贴了一堆代码谁愿意看呢,你这样做javax.jnlp.UnavailableServiceException: uninitialized把这个去百度看看,应该是没有触发弹出对话框所以不open
zhonghuaas 2014-01-04
  • 打赏
  • 举报
回复
无人回答吗?
内容概要:本文详细复现并实现了“电动汽车聚合可行域的内-外结合近似方法”的Matlab代码,旨在通过对大量电动汽车充放电能力的建模,构建其聚合可行域的内近似与外近似集合,从而科学刻画电动汽车集群作为柔性资源参与电网调度的整体潜力。研究基于多面体理论,系统阐述了电动汽车集群聚合建模的技术流程,并将其集成至包含分布式电源、储能系统及常规负荷的微电网经济调度模型中,验证该方法在提升系统运行经济性、灵活性与可再生能源消纳能力方面的有效性。文中不仅提供了完整的数学模型推导与优化框架,还深入分析了模型特性及其在虚拟电厂、车网互动(V2G)等新兴电力系统场景中的应用前景。; 适合人群:具备电力系统分析基础和Matlab编程能力的研究生、科研人员,以及从事新能源并网、智能电网、需求响应和能源互联网相关领域的工程师与技术人员。; 使用场景及目标:①掌握基于多面体理论的电动汽车集群聚合建模方法,理解其作为“虚拟电池”参与系统调度的内在机理;②学习如何将海量异质个体的时空灵活性聚合为可操作的可行域,并应用于微电网或主动配电网的优化调度问题;③为开展车网互动(V2G)、分布式资源聚合、鲁棒调度、虚拟电厂等前沿课题的研究提供坚实的模型基础与可复用的代码参考。; 阅读建议:建议读者结合文中提供的Matlab代码,逐模块运行与调试,重点关注电动汽车个体可行域的构建、多面体聚合的内近似算法实现以及微电网调度模型中约束条件的耦合方式,鼓励通过修改参数、增删设备类型或扩展为多时段模型等方式进行二次开发,以深化对聚合机理与优化逻辑的理解。

62,621

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧