大学JAVA实验五
大学JAVA实验五
这一次的实验做的不满意,恳请各位批评,恳请各位提供方法及建议
第一个实验
指定不同协议的URL地址,获得资源文件的内容和属性
URLStudy.java
package first;
import java.awt.FileDialog;
import java.awt.Font;
import java.awt.TextArea;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class URLStudy extends JFrame {
private static final long serialVersionUID = 1L;
private Font font = new Font("宋体", Font.CENTER_BASELINE, 13);
TextArea textarea = new TextArea();
JButton button[] = new JButton[3];
String buttonName[] = { "确定", "取消", "保存文件" };
JLabel label = new JLabel("请输入URL地址:");
JTextField urlfield = new JTextField(20);
JPanel panel = new JPanel();
URLStudyListener listener = new URLStudyListener(this);
private String file = "";
private FileDialog filesave;
public URLStudy() {
super.setTitle("资源文件的内容和属性查看器");
ImageIcon icon = new ImageIcon("195032.jpg");//在当前目录下加入名为195032.jpg的图片即可改变窗口左上角的咖啡图片,不愿意改就注释这行与下一行
setIconImage(icon.getImage());
textarea.setFont(font);
label.setFont(font);
urlfield.setFont(font);
panel.add(label);
panel.add(urlfield);
for (int i = 0; i < buttonName.length; i++) {
button[i] = new JButton(buttonName[i]);
button[i].addActionListener(listener);
button[i].setFont(font);
panel.add(button[i]);
}
super.setDefaultCloseOperation(EXIT_ON_CLOSE);
&
相关文档:
JDK1.4中
Map map = new HashMap();
Iterator it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
Object key = entry.getKey();
Object value = entry.getValue();
}
JDK1.5中,应用新特性For-Each循环
Map m = new HashMap();
......
example: 求5的阶乘。。
如下:
public class Test {
static int multiply(int n){
if(n==1||n==0)
return n;
else
return n*multiply(n-1);
}
public static void main(String[] args){
System.out.println(multiply(10));
}
......
java 循环打印出某对象所在类的类名和方法
public class A {
public void b(){}
public void c(){}
public void d(){}
public void e(){}
}
import java.lang.reflect.*;
public class StaticTest {
public static void test(Object obj)
{
Class myclass = obj.getClass();
//System.out.prin ......
java 列出某文件夹下的所有文件
import java.io.*;
public class ListFiles {
private static String s = "";
private static BufferedReader in = new BufferedReader(
new InputStreamReader(System.in));
public static void main(String[] args) {
try {
s = in.readLine();
ge ......