java源码实现
‘壹’ 求一个java实现自动下载的源代码
您好,这样的:
/**
*
*/
package com.b510.base.bean.install;
import java.io.File;
import java.io.FileWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @author hongten([email protected])
* @date 2013-2-24
*/
@SuppressWarnings("unchecked")
public class BeanUtils {
//公共部分
private static final String RT_1 = "\r\n";
private static final String RT_2 = RT_1+RT_1;
private static final String BLANK_1 =" ";
private static final String BLANK_4 =" ";
private static final String BLANK_8 =BLANK_4 + BLANK_4;
//注释部分
private static final String ANNOTATION_AUTHOR_PARAMTER = "@author ";
private static final String ANNOTATION_AUTHOR_NAME = "hongten([email protected])";
private static final String ANNOTATION_AUTHOR = ANNOTATION_AUTHOR_PARAMTER + ANNOTATION_AUTHOR_NAME;
private static final String ANNOTATION_DATE = "@date ";
private static final String ANNOTATION = "/**"+RT_1+BLANK_1+"*"+BLANK_1+ANNOTATION_AUTHOR +RT_1+BLANK_1+"*"+BLANK_1+ANNOTATION_DATE +getDate()+RT_1+BLANK_1+"*/"+RT_1;
//文件 地址
//private static final String BEAN_PATH = "com/b510/base/bean";
private static final String DAO_PATH = "com/b510/base/";
private static final String DAO_IMPL_PATH = "com/b510/base//impl";
private static final String SERVICE_PATH = "com/b510/base/service";
private static final String SERVICE_IMPL_PATH = "com/b510/base/service/impl";
//包名
private static final String BEAN_URL = "com.b510.base.bean";
private static final String DAO_URL = "com.b510.base.";
private static final String DAO_IMPL_URL = "com.b510.base..impl";
private static final String SERVICE_URL = "com.b510.base.service";
private static final String SERVICE_IMPL_URL = "com.b510.base.service.impl";
//基本类名称
private static final String BASE_DAO_NAME = DAO_URL + ".BaseDao";
private static final String ABSTRACT_BASE_DAO_IMPL_NAME = DAO_IMPL_URL + ".AbstractBaseDaoImpl";
private static final String BASE_SERVICE_NAME = SERVICE_URL + ".BaseService";
private static final String ABSTRACT_BASE_SERVICE_IMPL_NAME = SERVICE_IMPL_URL + ".AbstractBaseServiceImpl";
/**
* 创建bean的Dao<br>
*
* @param c
* @throws Exception
*/
public void createBeanDao(Class c) throws Exception {
String cName = c.getName();
String fileName = System.getProperty("user.dir") + "/src/" + DAO_PATH
+ "/" + getLastChar(cName) + "Dao.java";
File f = new File(fileName);
FileWriter fw = new FileWriter(f);
fw.write("package "+DAO_URL+";"+RT_2+ANNOTATION+"public interface " +
getLastChar(cName) + "Dao extends "+BASE_DAO_NAME+" <" + cName + "> {"+RT_2+"}");
fw.flush();
fw.close();
showInfo(fileName);
}
/**
* 创建bean的Dao的实现类
* @param c
* @throws Exception
*/
public void createBeanDaoImpl(Class c) throws Exception{
String cName = c.getName();
String fileName = System.getProperty("user.dir") + "/src/" + DAO_IMPL_PATH
+ "/" + getLastChar(cName) + "DaoImpl.java";
File f = new File(fileName);
FileWriter fw = new FileWriter(f);
fw.write("package "+DAO_IMPL_URL+";"+RT_2+ANNOTATION+"public class " +
getLastChar(cName) + "DaoImpl extends "+ABSTRACT_BASE_DAO_IMPL_NAME+"<" +
cName + "> implements "+DAO_URL+"."+getLastChar(cName)+"Dao{"+RT_2+"}");
fw.flush();
fw.close();
showInfo(fileName);
}
/**
* 创建bean的service
* @param c
* @throws Exception
*/
public void createBeanService(Class c) throws Exception{
String cName = c.getName();
String fileName = System.getProperty("user.dir") + "/src/" + SERVICE_PATH
+ "/" + getLastChar(cName) + "Service.java";
File f = new File(fileName);
FileWriter fw = new FileWriter(f);
fw.write("package "+SERVICE_URL+";"+RT_2+ANNOTATION+"public interface " +
getLastChar(cName) + "Service extends "+BASE_SERVICE_NAME+"<"+ cName +">{"+RT_2+"}");
fw.flush();
fw.close();
showInfo(fileName);
}
/**
* 创建bean的service的实现类
* @param c
* @throws Exception
*/
public void createBeanServiceImpl(Class c) throws Exception{
String cName = c.getName();
String fileName = System.getProperty("user.dir") + "/src/" + SERVICE_IMPL_PATH
+ "/" +getLastChar(cName)+"ServiceImpl.java";
File f = new File(fileName);
FileWriter fw = new FileWriter(f);
fw.write("package "+SERVICE_IMPL_URL+";"+RT_2+ANNOTATION+"public class "
+ getLastChar(cName) + "ServiceImpl extends "+ABSTRACT_BASE_SERVICE_IMPL_NAME+"<"+ cName
+ "> implements "+SERVICE_URL+"."+getLastChar(cName)+"Service{"+RT_2+BLANK_4
+"private "+DAO_URL+"."+getLastChar(cName)+"Dao "+getLowercaseChar(getLastChar(cName))
+"Dao;"+RT_2+BLANK_4+"public void set"+getLastChar(cName)+"Dao("+DAO_URL+"."+getLastChar(cName)+"Dao "
+getLowercaseChar(getLastChar(cName))+"Dao){"+RT_1+BLANK_8+"this."+getLowercaseChar(getLastChar(cName))+"Dao = "
+getLowercaseChar(getLastChar(cName))+"Dao;"+RT_1+BLANK_4+"}"+RT_2+BLANK_4+"@Override"+RT_1+BLANK_4
+"public "+DAO_URL+"."+"BaseDao<"+BEAN_URL+"."+getLastChar(cName)+"> getBaseDao(){"+RT_1+BLANK_8
+"return "+getLowercaseChar(getLastChar(cName))+"Dao;"+RT_1+BLANK_4+"}"+RT_2+"}");
fw.flush();
fw.close();
showInfo(fileName);
}
/**
* 获取路径的最后面字符串<br>
* 如:<br>
* <code>str = "com.b510.base.bean.User"</code><br>
* <code> return "User";<code>
* @param str
* @return
*/
public String getLastChar(String str) {
if ((str != null) && (str.length() > 0)) {
int dot = str.lastIndexOf('.');
if ((dot > -1) && (dot < (str.length() - 1))) {
return str.substring(dot + 1);
}
}
return str;
}
/**
* 把第一个字母变为小写<br>
* 如:<br>
* <code>str = "UserDao";</code><br>
* <code>return "userDao";</code>
* @param str
* @return
*/
public String getLowercaseChar(String str){
return str.substring(0,1).toLowerCase()+str.substring(1);
}
/**
* 显示信息
* @param info
*/
public void showInfo(String info){
System.out.println("创建文件:"+ info+ "成功!");
}
/**
* 获取系统时间
* @return
*/
public static String getDate(){
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
return simpleDateFormat.format(new Date());
}
}
‘贰’ java源代码如何用
java源代码是txt格式的.java文件,用记事本就可以打开。
用eclipse打开java文件的方式是:
如果java文件是一个eclipse工程(根目录带有.project文件),用file/import/general/exist java project/(大概是)然后找到你的目录。
否则需要自己新建一个工程file/new/java project
然后把java文件拷贝到.src目录下。
.class文件是直接的编译好的文件,可以用jad把.class文件反编译成java文件,不过反编译的代码和原来的代码不一定完全一样。
‘叁’ Java源码 实现网络爬虫
//Java爬虫demo
importjava.io.File;
importjava.net.URL;
importjava.net.URLConnection;
importjava.nio.file.Files;
importjava.nio.file.Paths;
importjava.util.Scanner;
importjava.util.UUID;
importjava.util.regex.Matcher;
importjava.util.regex.Pattern;
publicclassDownMM{
publicstaticvoidmain(String[]args)throwsException{
//out为输出的路径,注意要以\结尾
Stringout="D:\JSP\pic\java\";
try{
Filef=newFile(out);
if(!f.exists()){
f.mkdirs();
}
}catch(Exceptione){
System.out.println("no");
}
Stringurl="http://www.mzitu.com/share/comment-page-";
Patternreg=Pattern.compile("<imgsrc="(.*?)"");
for(intj=0,i=1;i<=10;i++){
URLuu=newURL(url+i);
URLConnectionconn=uu.openConnection();
conn.setRequestProperty("User-Agent","Mozilla/5.0(WindowsNT6.3;WOW64;Trident/7.0;rv:11.0)likeGecko");
Scannersc=newScanner(conn.getInputStream());
Matcherm=reg.matcher(sc.useDelimiter("\A").next());
while(m.find()){
Files.(newURL(m.group(1)).openStream(),Paths.get(out+UUID.randomUUID()+".jpg"));
System.out.println("已下载:"+j++);
}
}
}
}
‘肆’ 谁有Java实现的学生信息管理系统源码
可以试试看啊
以下方法实现了用户界面登陆
import java.awt.*;
import java.awt.event.*;
public class DengLuJieMian extends Frame implements ActionListener
{
Label username=new Label("用户名:");//使用文本创建一个用户名标签
TextField t1=new TextField();//创建一个文本框对象
Label password=new Label("密码:");//创建一个密码标签
TextField t2=new TextField();
Button b1=new Button("登陆");//创建登陆按钮
Button b2=new Button("取消");//创建取消按钮
public DengLuJieMian()
{
this.setTitle("学生信息管理系统");//设置窗口标题
this.setLayout(null);//设置窗口布局管理器
username.setBounds(50,40,60,20);//设置姓名标签的初始位置
this.add(username);// 将姓名标签组件添加到容器
t1.setBounds(120,40,80,20);// 设置文本框的初始位置
this.add(t1);// 将文本框组件添加到容器
password.setBounds(50,100,60,20);//密码标签的初始位置
this.add(password);//将密码标签组件添加到容器
t2.setBounds(120,100,80,20);//设置密码标签的初始位置
this.add(t2);//将密码标签组件添加到容器
b1.setBounds(50,150,60,20);//设置登陆按钮的初始位置
this.add(b1);//将登陆按钮组件添加到容器
b2.setBounds(120,150,60,20);//设置取消按钮的初始位置
this.add(b2);// 将取消按钮组件添加到容器
b1.addActionListener(this);//给登陆按钮添加监听器
b2.addActionListener(this);// 给取消按钮添加监听器
this.setVisible(true);//设置窗口的可见性
this.setSize(300,200);//设置窗口的大小
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});//通过内部类重写关闭窗体的方法
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)//处理登陆事件
{
String name=t1.getText();
String pass=t2.getText();
if(name!=null&&pass.equals("000123"))//判断语句
{
new StudentJieMian();
}
}
}
public static void main(String args[])//主函数
{
new DengLuJieMian();
}
}
以下方法实现了学生界面设计
import java.awt.*;
import java.awt.event.*;
class StudentJieMian extends Frame implements ActionListener
{
MenuBar m=new MenuBar();//创建菜单栏
Menu m1=new Menu("信息");//创建菜单“信息”
MenuItem m11=new MenuItem("插入");//创建“插入”的菜单项
MenuItem m12=new MenuItem("查询");
Menu m2=new Menu("成绩");//创建菜单“成绩”
MenuItem m21=new MenuItem("查询");
public StudentJieMian()
{
this.setTitle("学生界面");//设置窗口标题
this.setLayout(new CardLayout());//设置窗口布局管理器
this.setMenuBar(m);//将菜单栏组件添加到容器
m.add(m1);//将信息菜单放入菜单栏
m.add(m2);
m1.add(m11);//将“插入”菜单项添加到“信息”菜单
m1.add(m12); //将“查询”菜单项添加到“信息”菜单
m2.add(m21); //将“查询”菜单项添加到“成绩”菜单
m11.addActionListener(this); //给“插入”菜单项添加监听器
m12.addActionListener(this); //给“查询”菜单项添加监听器
m21.addActionListener(this); //给“查询”菜单项添加监听器
this.setVisible(true); //设置窗口的可见性
this.setSize(300,200); //设置窗口的大小
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);//关闭窗口
}
});
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==m11) //处理“添加信息”事件
{
new AddStudent();
}
if(e.getSource()==m12) //处理“查询信息”事件
{
new SelectStudent();
}
if(e.getSource()==m21) //处理“查询成绩”事件
{
new ChengJiStudent();
}
}
public static void main(String args[])
‘伍’ 什么是java源代码 怎么查看
不知道你说的是浏览器的还是什么的,
如果是浏览器的那么简单找到工具-查看源代码,你就能看见代码了,
还有一个就是被编译成class文件的java用反编译工具可以看到源代码,
如果以上都不是你想要的答案,那么你所说的代码就是程序员写好的代码文件
‘陆’ Java源码 实现网络爬虫
给我邮箱~~~~ 看你问好几天了