使用策略文件读取服务器端文件

<script type="text/javascript"> google_ad_client = "pub-8800625213955058"; /* 336x280, 创建于 07-11-21 */ google_ad_slot = "0989131976"; google_ad_width = 336; google_ad_height = 280; // </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> WeatherApplet.policy grant { permission java.net.SocketPermission "iwin.nws.noaa.gov:80", "connect"; }; WeatherApplet.java import java.net.*; import java.io.*; import java.util.*; import java.awt.*; import java.awt.event.*; import java.applet.*; import javax.swing.*; public class WeatherApplet extends JApplet implements ActionListener { public void init() { Container contentPane = getContentPane(); contentPane.setLayout(new BorderLayout()); JPanel listPanel = new JPanel(); state = makeList(states, 6, listPanel); report = makeList(reports, 6, listPanel); contentPane.add(listPanel, "North"); weather = new JTextArea(20, 80); weather.setFont(new Font("Courier", Font.PLAIN, 12)); contentPane.add(new JScrollPane(weather), "Center"); JPanel buttonPanel = new JPanel(); JButton reportButton = new JButton("Get report"); reportButton.addActionListener(this); buttonPanel.add(reportButton); contentPane.add(buttonPanel, "South"); } public JList makeList(final String[][] items, int visibleRows, Container parent) { JList list = new JList(new AbstractListModel() { public Object getElementAt(int i) { return items[i][0]; } public int getSize() { return items.length; } }); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setVisibleRowCount(visibleRows); parent.add(new JScrollPane(list)); return list; } public String getItem(JList list, String[][] items) { return items[list.getSelectedIndex()][1]; } public void actionPerformed(ActionEvent evt) { weather.setText(""); getWeather(getItem(state, states), getItem(report, reports)); } public void getWeather(String state, String report) { String r = new String(); try { String queryBase = getParameter("queryBase"); String query = queryBase state "/" report ".html"; URL url = new URL(query); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String line; while ((line = in.readLine()) != null) weather.append(removeTags(line) "/n"); } catch(IOException e) { showStatus("Error " e); } } public static String removeTags(String s) { while (true) { int lb = s.indexOf('<'); if (lb < 0) return s; int rb = s.indexOf('>', lb); if (rb < 0) return s; s = s.substring(0, lb) " " s.substring(rb 1); } } private JTextArea weather; private JList state; private JList report; private String[][] states = { { "Alabama", "al" }, { "Alaska", "ak" }, { "Arizona", "az" }, { "Arkansas", "ar" }, { "California", "ca" }, { "Colorado", "co" }, { "Connecticut", "ct" }, { "Delaware", "de" }, { "Florida", "fl" }, { "Georgia", "ga" }, { "Hawaii", "hi" }, { "Idaho", "id" }, { "Illinois", "il" }, { "Indiana", "in" }, { "Iowa", "ia" }, { "Kansas", "ks" }, { "Kentucky", "ky" }, { "Lousisiana", "la" }, { "Maine", "me" }, { "Maryland", "md" }, { "Massachusetts", "ma" }, { "Michigan", "mi" }, { "Minnesota", "mn" }, { "Mississippi", "ms" }, { "Missouri", "mo" }, { "Montana", "mt" }, { "Nebraska", "ne" }, { "Nevada", "nv" }, { "New Hampshire", "nh" }, { "New Jersey", "nj" }, { "New Mexico", "nm" }, { "New York", "ny" }, { "North Carolina", "nc" }, { "North Dakota", "nd" }, { "Ohio", "oh" }, { "Oklahoma", "ok" }, { "Oregon", "or" }, { "Pennsylvania", "pa" }, { "Rhode Island", "ri" }, { "South Carolina", "sc" }, { "South Dakota", "sd" }, { "Tennessee", "tn" }, { "Texas", "tx" }, { "Utah", "ut" }, { "Vermont", "vt" }, { "Virginia", "va" }, { "Washington", "wa" }, { "West Virginia", "wv" }, { "Wisconsin", "wi" }, { "Wyoming", "wy" } }; private String[][] reports = { { "Hourly (State Weather Roundup)", "hourly" }, { "State Forecast", "state" }, { "Zone Forecast", "zone" }, { "Short Term (NOWCASTS)", "shortterm" }, { "Forecast Discussion", "discussion" }, { "Weather Summary", "summary" }, { "Public Information", "public" }, { "Climate Data", "climate" }, { "Hydrological Data", "hydro" }, { "Watches", "watches" }, { "Special Weather Statements", "special" }, { "Warnings and Advisories", "allwarnings" } }; } WeatherApplet.html Cay Horstmann's Weather Report Applet
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值