完整java项目源码(java开源项目源码)
本文目录一览:
求JAVA小项目的完整代码
给你个做好了的Java的源程序的记事本,自己看看就行了的,不怎么难的···
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
public class MyNotepad implements ActionListener{
private JFrame frame=new JFrame("新记事本");
private JTextArea jta=new JTextArea();
private String result="";
private boolean flag=true;
private File f;
private JButton jb=new JButton("开始");
private JTextField jtf=new JTextField(15);
private JTextField jt=new JTextField(15);
private JButton jbt=new JButton("替换为");
private JButton jba=new JButton("全部替换");
private Icon ic=new ImageIcon("D:\\java课堂笔记\\GUI\\11.gif");
private String value;
private int start=0;
private JFrame jf=new JFrame("查找");
private JFrame jfc=new JFrame("替换");
@Override
public void actionPerformed(ActionEvent e) {
String comm=e.getActionCommand();
if("新建".equals(comm)){
if(!(frame.getTitle().equals("新记事本"))){
if(!flag){
write();
newNew();
}else{
JFileChooser jfc=new JFileChooser("D:\\java课堂笔记");
int returnVal = jfc.showDialog(null,"保存为");
if(returnVal == JFileChooser.APPROVE_OPTION) {//选择文件后再执行下面的语句,保证了程序的健壮性
f=jfc.getSelectedFile();
flag=false;
write();
}
}
}else if(!(jta.getText().isEmpty())){
JFileChooser jfc=new JFileChooser("D:\\java课堂笔记");
int returnVal = jfc.showDialog(null,"保存为");
if(returnVal == JFileChooser.APPROVE_OPTION) {//选择文件后再执行下面的语句,保证了程序的健壮性
f=jfc.getSelectedFile();
flag=false;
write();
newNew();
}
}else{
newNew();
}
}else if("打开".equals(comm)){
JFileChooser jfc=new JFileChooser("D:\\java课堂笔记");
jfc.setDialogType(JFileChooser.OPEN_DIALOG);
int returnVal = jfc.showOpenDialog(null);
if(returnVal == JFileChooser.APPROVE_OPTION) {//选择文件后再执行下面的语句,保证了程序的健壮性
f=jfc.getSelectedFile();
frame.setTitle(f.getName());
result=read();
flag=false;
value=result;
jta.setText(result);
}
}else if("保存".equals(comm)){
JFileChooser jfc=new JFileChooser("D:\\java课堂笔记");
if(flag){
int returnVal = jfc.showDialog(null,"保存为");
if(returnVal == JFileChooser.APPROVE_OPTION) {//选择文件后再执行下面的语句,保证了程序的健壮性
f=jfc.getSelectedFile();
flag=false;
write();
}
}else{
write();
}
}else if("另存".equals(comm)){
JFileChooser jfc=new JFileChooser("D:\\java课堂笔记");
int returnVal = jfc.showDialog(null,"另存");
if(returnVal == JFileChooser.APPROVE_OPTION) {//选择文件后再执行下面的语句,保证了程序的健壮性
f=jfc.getSelectedFile();
write();
}
}else if("退出".equals(comm)){
System.exit(0);
}else if("撤销".equals(comm)){
jta.setText(value);
}else if("剪切".equals(comm)){
value=jta.getText();
jta.cut();
}else if("复制".equals(comm)){
jta.copy();
}else if("粘贴".equals(comm)){
value=jta.getText();
jta.paste();
}else if("删除".equals(comm)){
value=jta.getText();
jta.replaceSelection(null);
}else if("全选".equals(comm)){
jta.selectAll();
}else if("查找".equals(comm)){
value=jta.getText();
jf.add(jtf,BorderLayout.CENTER);
jf.add(jb,BorderLayout.SOUTH);
jf.setLocation(300,300);
jf.pack();
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}else if("替换".equals(comm)){
value=jta.getText();
GridLayout gl=new GridLayout(3,3);
JLabel jl1=new JLabel("查找内容:");
JLabel jl2=new JLabel("替换为:");
jfc.setLayout(gl);
jfc.add(jl1);
jfc.add(jtf);
jfc.add(jb);
jfc.add(jl2);
jfc.add(jt);
jfc.add(jbt);
JLabel jl3=new JLabel();
JLabel jl4=new JLabel();
jfc.add(jl3);
jfc.add(jl4);
jfc.add(jba);
jfc.setLocation(300,300);
jfc.pack();
jfc.setVisible(true);
jfc.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}else if("版本".equals(comm)){
JDialog jd=new JDialog(frame,"关于对话框");
jd.setSize(200,200);
JLabel l=new JLabel("哈哈哈哈哈哈哈哈哈哈呵呵呵呵呵呵呵呵呵呵呵呵呵");
jd.add(l,BorderLayout.CENTER);
jd.setLocation(100,200);
jd.setSize(300,300);
jd.setVisible(true);
// jd.pack();
jd.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
}else if("开始".equals(comm)||"下一个".equals(comm)){
String temp=jtf.getText();
int s=value.indexOf(temp,start);
if(value.indexOf(temp,start)!=-1){
jta.setSelectionStart(s);
jta.setSelectionEnd(s+temp.length());
jta.setSelectedTextColor(Color.GREEN);
start=s+1;
jb.setText("下一个");
// value=value.substring(s+temp.length());//不能截取字串
}else {
JOptionPane.showMessageDialog(jf, "查找完毕!", "提示", 0, ic);
jf.dispose();
}
}else if("替换为".equals(comm)){
String temp=jtf.getText();
int s=value.indexOf(temp,start);
if(value.indexOf(temp,start)!=-1){
jta.setSelectionStart(s);
jta.setSelectionEnd(s+temp.length());
jta.setSelectedTextColor(Color.GREEN);
start=s+1;
jta.replaceSelection(jt.getText());
}else {
JOptionPane.showMessageDialog(jf, "查找完毕!", "提示", 0, ic);
jf.dispose();
}
}else if("全部替换".equals(comm)){
String temp=jta.getText();
temp=temp.replaceAll(jtf.getText(), jt.getText());
jta.setText(temp);
}
}
public String read(){
String temp="";
try {
FileInputStream fis = new FileInputStream(f.getAbsolutePath());
byte[] b=new byte[1024];
while(true){
int num=fis.read(b);
if(num==-1)break;
temp=temp+new String(b,0,num);
}
fis.close();
} catch (Exception e1) {
e1.printStackTrace();
}
return temp;
}
public void write(){
try {
FileOutputStream fos=new FileOutputStream(f);
fos.write(jta.getText().getBytes());
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public void newNew(){
frame.dispose();
new MyNotepad();
flag=true;
}
public MyNotepad(){
JMenuBar jmb=new JMenuBar();
String[] menuLab={"文件","编辑","帮助"};
String[][] menuItemLab={{"新建","打开","保存","另存","退出"},
{"撤销","剪切","复制","粘贴","删除","全选","查找","替换"},
{"版本"}};
for(int i=0;imenuLab.length;i++){
JMenu menu=new JMenu(menuLab[i]);
jmb.add(menu);
for(int j=0;jmenuItemLab[i].length;j++){
JMenuItem jmi=new JMenuItem(menuItemLab[i][j]);
menu.add(jmi);
jmi.addActionListener(this);
}
}
frame.setJMenuBar(jmb);
jta.setLineWrap(true);//自动换行
JScrollPane jsp=new JScrollPane(jta);//滚动窗口面板
frame.add(jsp);
jb.addActionListener(this);
jbt.addActionListener(this);
jba.addActionListener(this);
frame.setLocation(200,50);
frame.setSize(620,660);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new MyNotepad();
}
}
求一套完整的JAVA WEB项目的网络购物网站源代码
/**
* @description:
* @author chenshiqiang E-mail:csqwyyx@163.com
* @date 2014年9月7日 下午2:51:50
* @version 1.0
*/
package com.example.baidumap;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.PagerTabStrip;
import android.support.v4.view.ViewPager;
import android.text.Editable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ExpandableListView;
import android.widget.ListView;
import com.baidu.mapapi.map.offline.MKOLSearchRecord;
import com.baidu.mapapi.map.offline.MKOLUpdateElement;
import com.baidu.mapapi.map.offline.MKOfflineMap;
import com.baidu.mapapi.map.offline.MKOfflineMapListener;
import com.example.baidumap.adapters.OfflineExpandableListAdapter;
import com.example.baidumap.adapters.OfflineMapAdapter;
import com.example.baidumap.adapters.OfflineMapManagerAdapter;
import com.example.baidumap.interfaces.OnOfflineItemStatusChangeListener;
import com.example.baidumap.models.OfflineMapItem;
import com.example.baidumap.utils.CsqBackgroundTask;
import com.example.baidumap.utils.ToastUtil;
import com.example.system.R;
public class BaiduOfflineMapActivity extends Activity implements MKOfflineMapListener, OnOfflineItemStatusChangeListener
{
// ------------------------ Constants ------------------------
// ------------------------- Fields --------------------------
private ViewPager viewpager;
private PagerTabStrip pagertab;
private MySearchView svDown;
private ListView lvDown;
private MySearchView svAll;
private ExpandableListView lvWholeCountry;
private ListView lvSearchResult;
private ListView views = new ArrayListView(2);
private ListString titles = new ArrayListString(2);
private MKOfflineMap mOffline = null;
private OfflineMapManagerAdapter downAdapter;
private OfflineMapAdapter allSearchAdapter;
private OfflineExpandableListAdapter allCountryAdapter;
private ListOfflineMapItem itemsDown; // 下载或下载中城市
private ListOfflineMapItem itemsAll; // 所有城市,与热门城市及下载管理对象相同
private ListOfflineMapItem itemsProvince;
private ListListOfflineMapItem itemsProvinceCity;
// ----------------------- Constructors ----------------------
// -------- Methods for/from SuperClass/Interfaces -----------
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_offline_map);
// final String packname = this.getPackageName();
// PackageInfo packageInfo;
// try
// {
// packageInfo = this.getPackageManager().getPackageInfo(packname, PackageManager.GET_SIGNATURES);
//
//
// if (code == -00)
// {
// 初始化离线地图管理
mOffline = new MKOfflineMap();
mOffline.init(this);
initViews();
viewpager.setCurrentItem(1);
// }
// }
// catch (NameNotFoundException e)
// {
// e.printStackTrace();
// }
}
private boolean isResumed = false;
@Override
protected void onResume()
{
super.onResume();
if (!isResumed)
{
isResumed = true;
loadData();
}
}
@Override
protected void onDestroy()
{
super.onDestroy();
mOffline.destroy();
}
/**
*
* @author chenshiqiang E-mail:csqwyyx@163.com
* @param type
* 事件类型: MKOfflineMap.TYPE_NEW_OFFLINE, MKOfflineMap.TYPE_DOWNLOAD_UPDATE, MKOfflineMap.TYPE_VER_UPDATE.
* @param state
* 事件状态: 当type为TYPE_NEW_OFFLINE时,表示新安装的离线地图数目. 当type为TYPE_DOWNLOAD_UPDATE时,表示更新的城市ID.
*/
@Override
public void onGetOfflineMapState(int type, int state)
{
switch (type)
{
case MKOfflineMap.TYPE_DOWNLOAD_UPDATE:
MKOLUpdateElement update = mOffline.getUpdateInfo(state);
if (setElement(update, true) != null)
{
if (itemsDown != null itemsDown.size() 1)
{
Collections.sort(itemsDown);
}
refreshDownList();
}
else
{
downAdapter.notifyDataSetChanged();
}
allSearchAdapter.notifyDataSetChanged();
allCountryAdapter.notifyDataSetChanged();
break;
case MKOfflineMap.TYPE_NEW_OFFLINE:
// 有新离线地图安装
Log.d("OfflineDemo", String.format("add offlinemap num:%d", state));
break;
case MKOfflineMap.TYPE_VER_UPDATE:
// 版本更新提示
break;
}
}
/**
* 百度下载状态改变(暂停--》恢复)居然不回调,所以改变状态时自己得增加接口监听状态改变刷新界面
*
* @author chenshiqiang E-mail:csqwyyx@163.com
* @param item
* 有状态改变的item
* @param removed
* item是否被删除
*/
@Override
public void statusChanged(OfflineMapItem item, boolean removed)
{
if (removed)
{
for (int i = itemsDown.size() - 1; i = 0; i--)
{
OfflineMapItem temp = itemsDown.get(i);
if (temp.getCityId() == item.getCityId())
{
itemsDown.remove(i);
}
}
refreshDownList();
}
else
{
loadData();
downAdapter.notifyDataSetChanged();
}
allSearchAdapter.notifyDataSetChanged();
allCountryAdapter.notifyDataSetChanged();
}
// --------------------- Methods public ----------------------
public void toDownloadPage()
{
viewpager.setCurrentItem(0);
}
// --------------------- Methods private ---------------------
private void initViews()
{
// TODO
viewpager = (ViewPager) findViewById(R.id.viewpager);
pagertab = (PagerTabStrip) findViewById(R.id.pagertab);
LayoutInflater inf = LayoutInflater.from(this);
View v1 = inf.inflate(R.layout.view_offline_download, null, false);
svDown = (MySearchView) v1.findViewById(R.id.svDown);
lvDown = (ListView) v1.findViewById(R.id.lvDown);
views.add(v1);
View v2 = inf.inflate(R.layout.view_offline_countrys, null, false);
svAll = (MySearchView) v2.findViewById(R.id.svAll);
lvWholeCountry = (ExpandableListView) v2.findViewById(R.id.lvWholeCountry);
lvSearchResult = (ListView) v2.findViewById(R.id.lvSearchResult);
views.add(v2);
titles.add("下载管理");
titles.add("城市列表");
pagertab.setTabIndicatorColor(0xff00cccc);
pagertab.setDrawFullUnderline(false);
pagertab.setBackgroundColor(0xFF38B0DE);
pagertab.setTextSpacing(50);
viewpager.setOffscreenPageLimit(2);
viewpager.setAdapter(new MyPagerAdapter());
svDown.setSearchListener(new MySearchView.SearchListener()
{
@Override
public void afterTextChanged(Editable text)
{
refreshDownList();
}
@Override
public void search(String text)
{
}
});
svAll.setSearchListener(new MySearchView.SearchListener()
{
@Override
public void afterTextChanged(Editable text)
{
refreshAllSearchList();
}
@Override
public void search(String text)
{
}
});
downAdapter = new OfflineMapManagerAdapter(this, mOffline, this);
lvDown.setAdapter(downAdapter);
allSearchAdapter = new OfflineMapAdapter(this, mOffline, this);
lvSearchResult.setAdapter(allSearchAdapter);
allCountryAdapter = new OfflineExpandableListAdapter(this, mOffline, this);
lvWholeCountry.setAdapter(allCountryAdapter);
lvWholeCountry.setGroupIndicator(null);
}
/**
* 刷新下载列表, 根据搜索关键字及itemsDown 下载管理数量变动时调用
*/
private void refreshDownList()
{
String key = svDown.getInputText();
if (key == null || key.length() 1)
{
downAdapter.setDatas(itemsDown);
}
else
{
ListOfflineMapItem filterList = new ArrayListOfflineMapItem();
if (itemsDown != null !itemsDown.isEmpty())
{
for (OfflineMapItem i : itemsDown)
{
if (i.getCityName().contains(key))
{
filterList.add(i);
}
}
}
downAdapter.setDatas(filterList);
}
}
/**
* 刷新所有城市搜索结果
*/
private void refreshAllSearchList()
{
String key = svAll.getInputText();
if (key == null || key.length() 1)
{
lvSearchResult.setVisibility(View.GONE);
lvWholeCountry.setVisibility(View.VISIBLE);
allSearchAdapter.setDatas(null);
}
else
{
lvSearchResult.setVisibility(View.VISIBLE);
lvWholeCountry.setVisibility(View.GONE);
ListOfflineMapItem filterList = new ArrayListOfflineMapItem();
if (itemsAll != null !itemsAll.isEmpty())
{
for (OfflineMapItem i : itemsAll)
{
if (i.getCityName().contains(key))
{
filterList.add(i);
}
}
}
allSearchAdapter.setDatas(filterList);
}
}
private void loadData()
{
new CsqBackgroundTaskVoid(this)
{
@Override
protected Void onRun()
{
// TODO Auto-generated method stub
// 导入离线地图包
// 将从官网下载的离线包解压,把vmp文件夹拷入SD卡根目录下的BaiduMapSdk文件夹内。
// 把网站上下载的文件解压,将\BaiduMap\vmp\l里面的.dat_svc文件,拷贝到手机BaiduMapSDK/vmp/h目录下
int num = mOffline.importOfflineData();
if (num 0)
{
ToastUtil.showToastInfo(BaiduOfflineMapActivity.this, "成功导入" + num + "个离线包", false);
}
ListMKOLSearchRecord all = null;
try
{
all = mOffline.getOfflineCityList();
}
catch (Exception e)
{
e.printStackTrace();
}
if (all == null || all.isEmpty())
{
ToastUtil.showToastInfo(BaiduOfflineMapActivity.this, "未获取到离线地图城市数据,可能有其他应用正在使用百度离线地图功能!", false);
return null;
}
ListMKOLSearchRecord hotCity = mOffline.getHotCityList();
HashSetInteger hotCityIds = new HashSetInteger();
if (!hotCity.isEmpty())
{
for (MKOLSearchRecord r : hotCity)
{
hotCityIds.add(r.cityID);
}
}
itemsAll = new ArrayListOfflineMapItem();
itemsDown = new ArrayListOfflineMapItem();
itemsProvince = new ArrayListOfflineMapItem();
itemsProvinceCity = new ArrayListListOfflineMapItem();
// cityType 0:全国;1:省份;2:城市,如果是省份,可以通过childCities得到子城市列表
// 全国概略图、直辖市、港澳 子城市列表
ArrayListMKOLSearchRecord childMunicipalities = new ArrayListMKOLSearchRecord();
proHot.cityName = "热门城市";
proHot.childCities = cs;
ListMKOLUpdateElement updates = mOffline.getAllUpdateInfo();
if (updates != null updates.size() 0)
{
}
@Override
protected void onResult(Void result)
{
// TODO Auto-generated method stub
refreshDownList();
refreshAllSearchList();
allCountryAdapter.setDatas(itemsProvince, itemsProvinceCity);
}
}.execute();
}
什么是java源代码 怎么查看
你说的java源代码是指编译成的class文件前的java文件。
当我们运行.java文件时,它会被系统编译成.class文件,例如Test.java编译之后就是Test.class,
源文件就是指Test.java文件,
一般部署项目时,有.class文件就可以发布运行了,但是如果想修改这个系统,.class是不能修改的,要有.java文件才能修改
也可以上网去下反编译软件,就是能把.class文件大部分还原成.java文件的工具,但不是100%还原,而且如果不是正版的,小心有毒啊,什么的。
一个完整的java源程序应该包括哪些内容
底层配置文件,jar包(maven 则是pom.xml 文件),源代码,jsp显示页面,数据库