1、实验目的与要求

(1) 掌握Java应用程序的打包操作;

(2) 了解应用程序存储配置信息的两种方法;

(3) 掌握基于JNLP协议的java Web Start应用程序的发布方法;

(5) 掌握Java GUI 编程技术。

2、实验内容和步骤

实验1: 导入第13章示例程序,测试程序并进行代码注释。

测试程序1

在elipse IDE中调试运行教材585页程序13-1,结合程序运行结果理解程序;

将所生成的JAR文件移到另外一个不同的目录中,再运行该归档文件,以便确认程序是从JAR文件中,而不是从当前目录中读取的资源。

 1 package resource;
 2 
 3 import java.awt.*;
 4 import java.io.*;
 5 import java.net.*;
 6 import java.util.*;
 7 import javax.swing.*;
 8 
 9 /**
10  * @version 1.41 2015-06-12
11  * @author Cay Horstmann
12  */
13 public class ResourceTest
14 {
15    public static void main(String[] args)
16    {
17       EventQueue.invokeLater(() -> {
18          JFrame frame = new ResourceTestFrame();
19          frame.setTitle("ResourceTest");
20          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
21          frame.setVisible(true);
22       });
23    }
24 }
25 
26 /**
27  * 一个加载图像和文本资源的框架。
28  */
29 class ResourceTestFrame extends JFrame
30 {
31    private static final int DEFAULT_WIDTH = 300;
32    private static final int DEFAULT_HEIGHT = 300;
33 
34    public ResourceTestFrame()
35    {
36       setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
37       //获取资源文件
38       URL aboutURL = getClass().getResource("about.gif");
39       Image img = new ImageIcon(aboutURL).getImage();
40       setIconImage(img);
41 
42       JTextArea textArea = new JTextArea();
43       //从当前class下面的路径找文件
44       InputStream stream = getClass().getResourceAsStream("about.txt");
45       //这几句没理解
46       try (Scanner in = new Scanner(stream, "UTF-8"))
47       {
48          while (in.hasNext())
49             textArea.append(in.nextLine() + "\n");
50       }
51       add(textArea);
52    }
53 }
View Code

相关文章:

  • 2021-09-18
  • 2021-07-13
  • 2021-09-12
  • 2022-02-26
  • 2022-03-03
  • 2021-08-01
  • 2021-06-27
  • 2022-12-23
猜你喜欢
  • 2021-06-27
  • 2022-01-11
  • 2021-09-21
  • 2021-05-18
  • 2022-02-02
  • 2021-10-06
  • 2022-01-22
相关资源
相似解决方案