java写的小项目代码,编程小项目介绍

使用Java或者C#编写一个小项目,求源码或者思路,跪谢大佬

使用第三方库poi就可以实现excel的读取,读入内存后,编写一个函数,传入十进制然后转为十六进制即可。。

创新互联专业为企业提供南乐网站建设、南乐做网站、南乐网站设计、南乐网站制作等企业网站建设、网页设计与制作、南乐企业网站模板建站服务,十载南乐做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

求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帮我写下代码~

项目结构如下:

代码如下

package main;

public class Course {

private String classNum;

private String credit;

private String startClassDate;

private String endClassDate;

private String teacher;

private String assessment;

public String getClassNum() {

return classNum;

}

public void setClassNum(String classNum) {

this.classNum = classNum;

}

public String getCredit() {

return credit;

}

public void setCredit(String credit) {

this.credit = credit;

}

public String getStartClassDate() {

return startClassDate;

}

public void setStartClassDate(String startClassDate) {

this.startClassDate = startClassDate;

}

public String getEndClassDate() {

return endClassDate;

}

public void setEndClassDate(String endClassDate) {

this.endClassDate = endClassDate;

}

public String getTeacher() {

return teacher;

}

public void setTeacher(String teacher) {

this.teacher = teacher;

}

public String getAssessment() {

return assessment;

}

public void setAssessment(String assessment) {

this.assessment = assessment;

}

@Override

public String toString() {

return " 课程号:" + classNum + ", 学分:" + credit

+ ", 上课时间:" + startClassDate + ", 下课时间:"

+ endClassDate + ", 教师:" + teacher + ",  考核方式:"

+ assessment + "";

}

}

package main;

import java.io.BufferedInputStream;

import java.io.BufferedReader;

import java.io.File;

import java.io.FileInputStream;

import java.io.InputStreamReader;

import java.math.BigDecimal;

import java.util.ArrayList;

import java.util.Arrays;

import java.util.List;

import java.util.Scanner;

public class Main {

public static void main(String[] args) throws Exception {

Scanner sc = new Scanner(System.in);   

System.out.println("创建学生请输入姓名:");  

Student stu1 = new Student();

stu1.setName(sc.nextLine());

Scanner sc1 = new Scanner(System.in);   

System.out.println("创建学生请输入学号:");

stu1.setNumber(sc1.nextLine());

System.out.println("请选择课程,课程如下:");

ListCourse list2 = new ArrayListCourse();

stu1.setCourses(list2);

ListCourse list = readTxt();

for (Course course : list) {

System.out.println(course.toString());

}

for (int i = 1; i  5; i++) {

System.out.println("请输入第"+i+"个课程号:");

//输入第一个课程号

list2 = handleClass(list, list2);

System.err.println("已选择成功!");

list = notSelectClass(list, list2);

System.out.println("请选择课程,课程如下:");

if(i==4){

break;

}

for (Course course : list) {

System.out.println(course.toString());

}

}

System.out.println("课程已选完!结果如下:");

System.err.println("学生:"+stu1.getName()+":");

for (Course course : list2) {

System.err.println(course.toString());

}

}

/**

* 查看未选择可选课程

* @param list 全部可选课程

* @param list2 已选课程

* @return

*/

private static ListCourse notSelectClass(ListCourse list,ListCourse list2){

for (int i = 0; i  list.size(); i++) {

for (Course course : list2) {

//把已选课程剔除

if(course.getClassNum().equals(list.get(i).getClassNum())){

list.remove(i);

continue;

}

//把时间重合课程剔除  startdate1 =enddate2 and enddate1=startdate2

if(daYuDengYu(course.getEndClassDate(),list.get(i).getStartClassDate())daYuDengYu(list.get(i).getEndClassDate(), course.getStartClassDate())){

list.remove(i);

}

}

}

return list;

}

public static boolean daYuDengYu(String first, String second){

BigDecimal bd1 = new BigDecimal(first);

BigDecimal bd2 = new BigDecimal(second);

return bd1.compareTo(bd2)=0?true:false;

}

/**

* 处理选择课程

* @param list

* @param list2

* @return

*/

private static ListCourse handleClass(ListCourse list,ListCourse list2){

while (true) {

Scanner sssi = new Scanner(System.in);

String num = sssi.nextLine().trim();

for (Course course : list) {

if(num.equals(course.getClassNum())){

list2.add(course);

return list2;

}

}

System.out.println("课程号输入错误,请重新输入:");

}

}

/**

* 读取txt获取课程  每个课程按;分割每个属性按,分割

* @return

* @throws Exception

*/

private static ListCourse readTxt() throws Exception{

/* 读入TXT文件 */  

String pathname = Main.class.getResource("/").toString();

pathname = pathname.substring(6, pathname.length()-4)+"/src/classs/class.txt"; //获取绝对路径

File filename = new File(pathname); // 要读取以上路径的txt文件  

ListCourse list = new ArrayListCourse();

BufferedInputStream bis = new BufferedInputStream(new FileInputStream(filename));  

//读取文件内容  

byte[] b = new byte[bis.available()];  

bis.read(b);  

if(b!=null){

String [] strs= new String(b).split(";");

if (strs==null) {

return null;

}

for (String string : strs) {

String[] str = string.split(",");

Course course = new Course();

course.setAssessment(str[5].trim());

course.setClassNum(str[0].trim());

course.setCredit(str[1].trim());

course.setEndClassDate(str[3].trim());

course.setStartClassDate(str[2].trim());

course.setTeacher(str[4].trim());

list.add(course);

}

}

bis.close();//关闭流(关闭bis就可以了)  

return list;

}

}

package main;

import java.util.List;

public class Student {

private String name;

private String number;

private ListCourse courses;

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getNumber() {

return number;

}

public void setNumber(String number) {

this.number = number;

}

public ListCourse getCourses() {

return courses;

}

public void setCourses(ListCourse courses) {

this.courses = courses;

}

}

001,1,7,8,Joyce,assignment;

002,1,8,9,Joyce,assignment;

003,1,12,15,Joyce,assignment;

004,1,18,19,Joyce,assignment;

005,1,7,8,LI,assignment;

006,1,8,9,LI,assignment;

007,1,12,15,LI,assignment;

008,1,18,19,LI,assignment;

跪求java小项目,经典小游戏代码

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.util.*;

public class GreedSnake implements KeyListener{

JFrame mainFrame;

Canvas paintCanvas;

JLabel labelScore;

SnakeModel snakeModel = null;

public static final int canvasWidth = 200;

public static final int canvasHeight = 300;

public static final int nodeWidth = 10;

public static final int nodeHeight = 10;

public GreedSnake() {

mainFrame = new JFrame("GreedSnake");

Container cp = mainFrame.getContentPane();

labelScore = new JLabel("Score:");

cp.add(labelScore, BorderLayout.NORTH);

paintCanvas = new Canvas();

paintCanvas.setSize(canvasWidth+1,canvasHeight+1);

paintCanvas.addKeyListener(this);

cp.add(paintCanvas, BorderLayout.CENTER);

JPanel panelButtom = new JPanel();

panelButtom.setLayout(new BorderLayout());

JLabel labelHelp;

labelHelp = new JLabel("PageUp, PageDown for speed;", JLabel.CENTER);

panelButtom.add(labelHelp, BorderLayout.NORTH);

labelHelp = new JLabel("ENTER or R or S for start;", JLabel.CENTER);

panelButtom.add(labelHelp, BorderLayout.CENTER);

labelHelp = new JLabel("SPACE or P for pause",JLabel.CENTER);

panelButtom.add(labelHelp, BorderLayout.SOUTH);

cp.add(panelButtom,BorderLayout.SOUTH);

mainFrame.addKeyListener(this);

mainFrame.pack();

mainFrame.setResizable(false);

mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

mainFrame.setVisible(true);

begin();

}

public void keyPressed(KeyEvent e){

int keyCode = e.getKeyCode();

if (snakeModel.running)

switch(keyCode){

case KeyEvent.VK_UP:

snakeModel.changeDirection(SnakeModel.UP);

break;

case KeyEvent.VK_DOWN:

snakeModel.changeDirection(SnakeModel.DOWN);

break;

case KeyEvent.VK_LEFT:

snakeModel.changeDirection(SnakeModel.LEFT);

break;

case KeyEvent.VK_RIGHT:

snakeModel.changeDirection(SnakeModel.RIGHT);

break;

case KeyEvent.VK_ADD:

case KeyEvent.VK_PAGE_UP:

snakeModel.speedUp();

break;

case KeyEvent.VK_SUBTRACT:

case KeyEvent.VK_PAGE_DOWN:

snakeModel.speedDown();

break;

case KeyEvent.VK_SPACE:

case KeyEvent.VK_P:

snakeModel.changePauseState();

break;

default:

}

if (keyCode == KeyEvent.VK_R ||

keyCode == KeyEvent.VK_S ||

keyCode == KeyEvent.VK_ENTER){

snakeModel.running = false;

begin();

}

}

public void keyReleased(KeyEvent e){

}

public void keyTyped(KeyEvent e){

}

void repaint(){

Graphics g = paintCanvas.getGraphics();

//draw background

g.setColor(Color.WHITE);

g.fillRect(0,0,canvasWidth,canvasHeight);

// draw the snake

g.setColor(Color.BLACK);

LinkedList na = snakeModel.nodeArray;

Iterator it = na.iterator();

while(it.hasNext()){

Node n = (Node)it.next();

drawNode(g,n);

}

// draw the food

g.setColor(Color.RED);

Node n = snakeModel.food;

drawNode(g,n);

updateScore();

}

private void drawNode(Graphics g, Node n){

g.fillRect(n.x*nodeWidth,

n.y*nodeHeight,

nodeWidth-1,

nodeHeight-1);

}

public void updateScore(){

String s = "Score: " + snakeModel.score;

labelScore.setText(s);

}

void begin(){

if (snakeModel == null || !snakeModel.running){

snakeModel = new SnakeModel(this,

canvasWidth/nodeWidth,

canvasHeight/nodeHeight);

(new Thread(snakeModel)).start();

}

}

public static void main(String[] args){

GreedSnake gs = new GreedSnake();

}

}

///////////////////////////////////////////////////

// 文件2

///////////////////////////////////////////////////

import java.util.*;

import javax.swing.*;

class SnakeModel implements Runnable{

GreedSnake gs;

boolean[][] matrix;

LinkedList nodeArray = new LinkedList();

Node food;

int maxX;

int maxY;

int direction = 2;

boolean running = false;

int timeInterval = 200;

double speedChangeRate = 0.75;

boolean paused = false;

int score = 0;

int countMove = 0;

// UP and DOWN should be even

// RIGHT and LEFT should be odd

public static final int UP = 2;

public static final int DOWN = 4;

public static final int LEFT = 1;

public static final int RIGHT = 3;

public SnakeModel(GreedSnake gs, int maxX, int maxY){

this.gs = gs;

this.maxX = maxX;

this.maxY = maxY;

// initial matirx

matrix = new boolean[maxX][];

for(int i=0; imaxX; ++i){

matrix = new boolean[maxY];

Arrays.fill(matrix,false);

}

// initial the snake

int initArrayLength = maxX 20 ? 10 : maxX/2;

for(int i = 0; i initArrayLength; ++i){

int x = maxX/2+i;

int y = maxY/2;

nodeArray.addLast(new Node(x, y));

matrix[x][y] = true;

}

food = createFood();

matrix[food.x][food.y] = true;

}

public void changeDirection(int newDirection){

if (direction % 2 != newDirection % 2){

direction = newDirection;

}

}

public boolean moveOn(){

Node n = (Node)nodeArray.getFirst();

int x = n.x;

int y = n.y;

switch(direction){

case UP:

y--;

break;

case DOWN:

y++;

break;

case LEFT:

x--;

break;

case RIGHT:

x++;

break;

}

if ((0 = x x maxX) (0 = y y maxY)){

if (matrix[x][y]){

if(x == food.x y == food.y){

nodeArray.addFirst(food);

int scoreGet = (10000 - 200 * countMove) / timeInterval;

score += scoreGet 0? scoreGet : 10;

countMove = 0;

food = createFood();

matrix[food.x][food.y] = true;

return true;

}

else

return false;

}

else{

nodeArray.addFirst(new Node(x,y));

matrix[x][y] = true;

n = (Node)nodeArray.removeLast();

matrix[n.x][n.y] = false;

countMove++;

return true;

}

}


本文名称:java写的小项目代码,编程小项目介绍
网址分享:http://abwzjs.com/article/hdpecg.html