包含java300级源代码的词条

java 源代码 基础点的 谢谢

package com.regex;

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:主机域名、虚拟空间、营销软件、网站建设、大通网站维护、网站推广。

import java.io.*;

import java.net.URLDecoder;

import java.util.regex.*;

public class Regex {

private int REMARK=0;

private int LOGIC=0;

private int PHYSIC=0;

boolean start=false;

/**

* @param args

*/

public static void main(String[] args) { //测试方法

// TODO Auto-generated method stub

Regex re=new Regex();

re.regCount("Regex.java");

System.out.println("remark Line: "+re.REMARK);

System.out.println("logic Line: "+re.LOGIC);

System.out.println("physic Line: "+re.PHYSIC);

}/**

* @author BlueDance

* @param s

* @deprecated count

*/

public void regCount(String s){

String url=null;

try {

url=URLDecoder.decode(this.getClass().getResource(s).getPath(),"UTF-8");

} catch (Exception e) {

e.printStackTrace();

// TODO: handle exception

}

try {

BufferedReader br=new BufferedReader(new FileReader(new File(url)));

String s1=null;

while((s1=br.readLine())!=null){

PHYSIC++;

if(CheckChar(s1)==1){

REMARK++;

System.out.println("纯注释行:"+s1);

}

if(CheckChar(s1)==2){

LOGIC++;

REMARK++;

System.out.println("非纯注释行:"+s1);

}

if(CheckChar(s1)==3)

LOGIC++;

}

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}catch(IOException e){

e.printStackTrace();

}

}

/**

*

* @param s

* @return int

* @version check s

*/

public int CheckChar(String s){

String s1=null;

if(s!=null)

s1=s.trim();

//System.out.println(regCheck(s1,re));

if(regCheck(s1,"(//.*)")) //判断//开头的为纯注释行

return 1;

if(regCheck(s1,"(.*[;{})] *//.*)")) //判断不是//开头的非纯注释行

return 2;

if(regCheck(s1,"(//*.*)")){ //判断/*开头的纯注释行

start=true;

return 1;

}

if(regCheck(s1,"(.*[;{})]//*.*)")){ //判断不是/*开头的非纯注释行

start=true;

return 2;

}

if(regCheck(s1,"(.* */*/)")){ //判断*/结尾的纯注释行

start=false;

return 1;

}

if(regCheck(s1,"(.* */*/.*)")!strCheck(s1)){ //判断不是*/结尾的非纯注释行

if(strCheck(s1)){

start=false;

return 2;

}

}

if(start==true) //状态代码,start即/*开始时start=true*/结束时为false

return 1;

return 3;//ssssllll

}//aeee

/**

*

* @param s

* @param re

* @return boolean

*/

public boolean regCheck(String s,String re){ //正则表达试判断方法

return Pattern.matches(re,s);

}

public boolean strCheck(String s){ //中间有*/的字符判断 此方法最关键

if(s.indexOf("*/")0){

int count=0;

String y[]=s.split("/*/");

boolean boo[]=new boolean[y.length];

for (int i = 0; i y.length-1; i++) {

char c[]=y[i].toCharArray();

for (int j = 0; j c.length; j++) {

if(c[j]=='\\'c[j+1]=='"'){

count++;

}

}

if(count%2==0){

if(countNumber("\"",y[i])%2!=0){

boo[i]=true;

}else{

boo[i]=false;

}

}else{

if(countNumber("\"",y[i])%2==0){

boo[i]=true;

}else{

boo[i]=false;

}

}

}

for(int i=0;iboo.length;i++){

if(!boo[i])

return false;

}

return true;

}

return false;

}

public int countNumber(String s,String y){ //此方法为我前面写的字符串出现次数统计方法,不懂的可以看我前面的文章

int count=0;

String [] k=y.split(s);

if(y.lastIndexOf(s)==(y.length()-s.length()))

count=k.length;

else

count=k.length-1;

if(count==0)

System.out.println ("字符串\""+s+"\"在字符串\""+y+"\"没有出现过");

else

return count;

return -1;

}

}

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class GoodLucky extends JFrame implements ActionListener{

JTextField tf = new JTextField(); //实例化一个文本域

//设置两个按钮

JButton b1 = new JButton("开始");

JButton b2 = new JButton("停止");

boolean isGo = false;

//构造函数

public GoodLucky(){

b1.setActionCommand("start");//在开始按钮上设置一个动作监听 start

JPanel p = new JPanel(); //实例化一个可视化容器

//将两个按钮添加到可视化容器上面,用add方法

p.add(b1);

p.add(b2);

//在两个按钮上增加监听的属性,自动调用下面的监听处理方法actionPerformed(ActionEvent e),如果要代码有更好的可读性,可用内部类实现动作

//监听处理。

b1.addActionListener(this);

b2.addActionListener(this);

//将停止按钮设置为不可编辑(即不可按的状态)

b2.setEnabled(false);

this.getContentPane().add(tf,"North"); //将上面的文本域放在面板的北方,也就是上面(上北下南左西右东)

this.getContentPane().add(p,"South"); //将可视化容器pannel放在南边,也就是下面

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //设置用户在此窗体上发起 "close" 时默认执行的操作,参数EXIT_ON_CLOSE是使用 System exit 方法退出应用程序。仅在应用程序中使用

this.setSize(300,200); //设置面板大小,宽和高

this.setLocation(300,300); //设置面板刚开始的出现的位置

Cursor cu = new Cursor(Cursor.HAND_CURSOR); //用指定名称创建一个新的定制光标对象,参数表示手状光标类型

this.setCursor(cu); //为指定的光标设置光标图像,即设置光标图像为上面所创建的手状光标类型

this.setVisible(true); //将面板可视化设置为true,即可视,如果为false,即程序运行时面板会隐藏

tf.setText("welcome you! "); //设置面板的标题为欢迎

this.go(); //调用go方法

}

public void go(){

while(true){ //这里是死循环,也就是说用户不点击停止按钮的话他一直循环出现随机数,直到用户点击停止按钮循环才能推出,具体流程在actionPerformed方法中控制。

if(isGo == true){ //上面所定义的isGo的初始值为false,所以程序第一次到此会跳过

String s = ""; //设置空字符串

for(int j = 1; j = 7;j++){ //产生7个随机数

int i = (int)(Math.random() * 36) + 1;//每个随机数产生方式,这里定义灵活,可以自由定义随机数产生的方式

if(i 10){

s = s + " 0" + i; //如果产生的随机数小于10的话做处理:这里就牵扯到一个重要的概念,简单叙述一下:

/*

当一个字符串与一个整型数项相加的意思是连接,上面的s = s + " 0" + i的意思是字符串s链接0再连接整型i值,而不会导致0和整型的i相加,

产生的效果为s0i,由于s为空字符串(上面定义过的),所以当i小于零时,在个位数前面加上0,比如产生的随机数i为7的话,显示效果为 07.

*/

}else{

s = s + " " + i; //如果产生的随机数比10打的话,那么加上空格显示,即数字和数字之间有个空格

}

//以上循环循环七次,以保证能出现7个随机数

}

tf.setText(s); //将产生的随机数全部显示在文本域上,用文本域对象tf调用它的设置文本的方法setText(String)实现。

}

//以下为线程延迟

try{

Thread.sleep(10); //线程类同步方法sleep,睡眠方法,括号里的单位为ms。

}catch(java.lang.InterruptedException e){

e.printStackTrace(); //异常捕获,不用多说。

}

}

}

//以下是上面设置的事件监听的具体处理办法,即监听时间处理方法,自动调用

public void actionPerformed(ActionEvent e){ //传入一个动作事件的参数e

String s = e.getActionCommand(); //设置字符串s来存储获得动作监听,上面的start

/*

以下这个条件语句块的作用为:用户点击开始后(捕获start,用方法getActionCommand()),将命令触发设置为true,从而执行上面的go方法中的循环体(因为循环体中要求isGo参数为true,而初始为false)。

执行循环快产生随机数,并将开始按钮不可编辑化,而用户只可以使用停止按钮去停止。如果用户按下停止时,也就是没有传入参数“start”的时候,

执行else语句块中的语句,isGo设置为false,将不执行上面go中的循环语句块,从而停止产生随机数,并显示,并且把开始按钮设置为可用,而把

停止按钮设置为不可用,等待用户按下开始再去开始新一轮循环产生随机数。

*/

if(s.equals("start")){ //如果捕获到start,也就是用户触发了动作监听器,那么下面处理

isGo = true; //设置isGo为true

b1.setEnabled(false); //将开始按钮设置为不可用

b2.setEnabled(true); //将停止按钮设置为可用

}else{

isGo = false; //将isGo设置为false,isGo为循环标志位

b2.setEnabled(false); //设置停止按钮为不可用(注意看是b2,b2是停止按钮)

b1.setEnabled(true); //设置开始按钮为可用

}

}

public static void main(String[] args){

new GoodLucky(); //产生类的实例,执行方法

}

}

急求大神发几个java 300行代码的小程序 简单点的

/**

* 文件名:Operation.java 2014-1-2 下午3:06:37

* @author Administrator

*/

package cc.icoc.javaxu.action;

import java.util.ArrayList;

import java.util.Scanner;

import cc.icoc.javaxu.datas.StudentInfo;

/**

* @author 许仕永

* 创建时间: 2014 2014-1-2 下午3:06:37

*/

public class Operation

{

int stuNo,stuAge;

String stuName,stuClass,stuSex;

ArrayListStudentInfo list;

/**程序入口

* @param args

*/

public static void main(String[] args)

{

// TODO Auto-generated method stub

new Operation().operation();

}

private int inputInt()

{

Scanner scanner = new Scanner(System.in);

return scanner.nextInt();

}

private String inputStr()

{

Scanner scanner = new Scanner(System.in);

return scanner.nextLine();

}

private void operation()

{

// TODO Auto-generated method stub

if(list == null)

{

list = new ArrayListStudentInfo();

}

while(true)

{

System.out.println("\t\t\t学生信息管理系统\n");

System.out.println("1.信息查阅");

System.out.println("2.信息查询");

System.out.println("3.信息录入");

System.out.println("4.退出系统");

int what = inputInt();

if ( what == 1 )

{

getInfo();

} else if ( what == 2 )

{

allSerach();

} else if ( what == 3 )

{

inputInfo();

} else if( what == 4 )

{

System.out.println("已经退出系统");

System.exit(0);

}

}

}

/**

* 获取全部学生的信息列表

*/

private void getInfo()

{

if(!list.isEmpty())

{

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

{

System.out.println(list.get(i));

}

}

}

/**

* 执行查找

*/

private void allSerach()

{

System.out.println("1.输入学号进行查询");

System.out.println("2.输入姓名进行查询");

int what = inputInt();

if(what == 1)

{

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

search(inputInt());

}

else

{

System.out.println("请输入姓名:");

search(inputStr());

}

}

/**

* 按学生姓名查询学生信息

* @param name 学生姓名

*/

private StudentInfo search(String name)

{

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

{

if(list.get(i).getStuName().equals(name))

{

System.out.println(list.get(i));

return list.get(i);

}

}

System.out.println("未查询到该名字的学生");

return null;

}

/**

* 按学号查询学生信息

* @param id 学号

*/

private StudentInfo search(int id)

{

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

{

if(list.get(i).getStuNo()==id)

{

System.out.println(list.get(i));

return list.get(i);

}

}

System.out.println("未查询到该学号的学生");

return null;

}

/**

* 录入学生信息

*/

private void inputInfo()

{

try

{

System.out.print("请输入学生学号:\n");

stuNo = inputInt();

System.out.print("请输入学生姓名:\n");

stuName = inputStr();

System.out.print("请输入学生性别:\n");

stuSex = inputStr();

System.out.print("请输入学生年龄:\n");

stuAge = inputInt();

System.out.print("请输入学生班级:\n");

stuClass = inputStr();

list.add(new StudentInfo(stuNo, stuAge, stuName, stuSex, stuClass));

} catch (Exception e)

{

// TODO: handle exception

System.out.println("不允许为空,请重新输入");

}

}

}

package cc.icoc.javaxu.action;

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;

public class Stu

{

int countStu = 0;

int sum = 0;

int avg = 0;

ListStuBean list = new ArrayListStu.StuBean();

public static void main(String[] args)

{

new Stu().go();

}

private void go()

{

A:while(true)

{

//构造实体Bean来存储学生成绩

StuBean bean = new StuBean();

System.out.println("请输入成绩:");

System.out.println("语文:");

bean.setYuwen(scanner());

System.out.println("数学:");

bean.setMath(scanner());

//获取英语成绩

System.out.println("英语:");

bean.setEnglish(scanner());

//存入容器

list.add(bean);

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

{

sum += list.get(i).english+list.get(i).math+list.get(i).yuwen;

}

avg = sum / (3*list.size());

System.out.println("当前有"+list.size()+"条学生记录,所有学生总分="+sum+"平均分为"+avg);

//输入y继续录入学生信息,输入x退出

System.out.println("\n已成功录入一个学生的数据,是否继续/退出(y/x)");

if("x".equals(scannerString()))

break A;

}

}

/**输入*/

private int scanner()

{

Scanner scanner = new Scanner(System.in);

return scanner.nextInt();

}

/**输入*/

private String scannerString()

{

Scanner scanner = new Scanner(System.in);

return scanner.nextLine();

}

class StuBean

{

int math;

int yuwen;

int english;

public int getMath()

{

return math;

}

public void setMath(int math)

{

this.math = math;

}

public int getYuwen()

{

return yuwen;

}

public void setYuwen(int yuwen)

{

this.yuwen = yuwen;

}

public int getEnglish()

{

return english;

}

public void setEnglish(int english)

{

this.english = english;

}

}

}

/**

* 文件名:StudentInfo.java 2014-1-2 下午3:07:29

* @author Administrator

*/

package cc.icoc.javaxu.datas;

/**

* @author 许仕永

* 创建时间: 2014 2014-1-2 下午3:07:29

*/

public class StudentInfo

{

int stuNo,stuAge;

String stuName,stuSex,stuClass;

public StudentInfo(int stuNo, int stuAge, String stuName, String stuSex, String stuClass)

{

super();

this.stuNo = stuNo;

this.stuAge = stuAge;

this.stuName = stuName;

this.stuSex = stuSex;

this.stuClass = stuClass;

}

public int getStuNo()

{

return stuNo;

}

public void setStuNo(int stuNo)

{

this.stuNo = stuNo;

}

public int getStuAge()

{

return stuAge;

}

public void setStuAge(int stuAge)

{

this.stuAge = stuAge;

}

public String getStuName()

{

return stuName;

}

public void setStuName(String stuName)

{

this.stuName = stuName;

}

public String getStuSex()

{

return stuSex;

}

public void setStuSex(String stuSex)

{

this.stuSex = stuSex;

}

public String getStuClass()

{

return stuClass;

}

public void setStuClass(String stuClass)

{

this.stuClass = stuClass;

}

@Override

public String toString()

{

// TODO Auto-generated method stub

String s = "学号:"+getStuNo()+"\t姓名:"+getStuName()+" \t性别:"+getStuSex()+"\t年龄:"+getStuAge()+"\t班级:"+getStuClass();

return s;

}

}

JAVA代码

连连看java源代码

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class lianliankan implements ActionListener

{

JFrame mainFrame; //主面板

Container thisContainer;

JPanel centerPanel,southPanel,northPanel; //子面板

JButton diamondsButton[][] = new JButton[6][5];//游戏按钮数组

JButton exitButton,resetButton,newlyButton; //退出,重列,重新开始按钮

JLabel fractionLable=new JLabel("0"); //分数标签

JButton firstButton,secondButton; //分别记录两次被选中的按钮

int grid[][] = new int[8][7];//储存游戏按钮位置

static boolean pressInformation=false; //判断是否有按钮被选中

int x0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV; //游戏按钮的位置坐标

int i,j,k,n;//消除方法控制

public void init(){

mainFrame=new JFrame("JKJ连连看");

thisContainer = mainFrame.getContentPane();

thisContainer.setLayout(new BorderLayout());

centerPanel=new JPanel();

southPanel=new JPanel();

northPanel=new JPanel();

thisContainer.add(centerPanel,"Center");

thisContainer.add(southPanel,"South");

thisContainer.add(northPanel,"North");

centerPanel.setLayout(new GridLayout(6,5));

for(int cols = 0;cols 6;cols++){

for(int rows = 0;rows 5;rows++ ){

diamondsButton[cols][rows]=new JButton(String.valueOf(grid[cols+1][rows+1]));

diamondsButton[cols][rows].addActionListener(this);

centerPanel.add(diamondsButton[cols][rows]);

}

}

exitButton=new JButton("退出");

exitButton.addActionListener(this);

resetButton=new JButton("重列");

resetButton.addActionListener(this);

newlyButton=new JButton("再来一局");

newlyButton.addActionListener(this);

southPanel.add(exitButton);

southPanel.add(resetButton);

southPanel.add(newlyButton);

fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText())));

northPanel.add(fractionLable);

mainFrame.setBounds(280,100,500,450);

mainFrame.setVisible(true);

}

public void randomBuild() {

int randoms,cols,rows;

for(int twins=1;twins=15;twins++) {

randoms=(int)(Math.random()*25+1);

for(int alike=1;alike=2;alike++) {

cols=(int)(Math.random()*6+1);

rows=(int)(Math.random()*5+1);

while(grid[cols][rows]!=0) {

cols=(int)(Math.random()*6+1);

rows=(int)(Math.random()*5+1);

}

this.grid[cols][rows]=randoms;

}

}

}

public void fraction(){

fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText())+100));

}

public void reload() {

int save[] = new int[30];

int n=0,cols,rows;

int grid[][]= new int[8][7];

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

for(int j=0;j=5;j++) {

if(this.grid[i][j]!=0) {

save[n]=this.grid[i][j];

n++;

}

}

}

n=n-1;

this.grid=grid;

while(n=0) {

cols=(int)(Math.random()*6+1);

rows=(int)(Math.random()*5+1);

while(grid[cols][rows]!=0) {

cols=(int)(Math.random()*6+1);

rows=(int)(Math.random()*5+1);

}

this.grid[cols][rows]=save[n];

n--;

}

mainFrame.setVisible(false);

pressInformation=false; //这里一定要将按钮点击信息归为初始

init();

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

for(int j = 0;j 5;j++ ){

if(grid[i+1][j+1]==0)

diamondsButton[i][j].setVisible(false);

}

}

}

public void estimateEven(int placeX,int placeY,JButton bz) {

if(pressInformation==false) {

x=placeX;

y=placeY;

secondMsg=grid[x][y];

secondButton=bz;

pressInformation=true;

}

else {

x0=x;

y0=y;

fristMsg=secondMsg;

firstButton=secondButton;

x=placeX;

y=placeY;

secondMsg=grid[x][y];

secondButton=bz;

if(fristMsg==secondMsg secondButton!=firstButton){

xiao();

}

}

}

public void xiao() { //相同的情况下能不能消去。仔细分析,不一条条注释

if((x0==x (y0==y+1||y0==y-1)) || ((x0==x+1||x0==x-1)(y0==y))){ //判断是否相邻

remove();

}

else{

for (j=0;j7;j++ ) {

if (grid[x0][j]==0){ //判断第一个按钮同行哪个按钮为空

if (yj) { //如果第二个按钮的Y坐标大于空按钮的Y坐标说明第一按钮在第二按钮左边

for (i=y-1;i=j;i-- ){ //判断第二按钮左侧直到第一按钮中间有没有按钮

if (grid[x][i]!=0) {

k=0;

break;

}

else //K=1说明通过了第一次验证

}

if (k==1) {

linePassOne();

}

}

if (yj){ //如果第二个按钮的Y坐标小于空按钮的Y坐标说明第一按钮在第二按钮右边

for (i=y+1;i=j ;i++ ){ //判断第二按钮左侧直到第一按钮中间有没有按钮

if (grid[x][i]!=0){

k=0;

break;

}

else

}

if (k==1){

linePassOne();

}

}

if (y==j ) {

linePassOne();

}

}

if (k==2) {

if (x0==x) {

remove();

}

if (x0x) {

for (n=x0;n=x-1;n++ ) {

if (grid[n][j]!=0) {

k=0;

break;

}

if(grid[n][j]==0 n==x-1) {

remove();

}

}

}

if (x0x) {

for (n=x0;n=x+1 ;n-- ) {

if (grid[n][j]!=0) {

k=0;

break;

}

if(grid[n][j]==0 n==x+1) {

remove();

}

}

}

}

}

for (i=0;i8;i++ ) { //列

if (grid[i][y0]==0) {

if (xi) {

for (j=x-1;j=i ;j-- ) {

if (grid[j][y]!=0) {

k=0;

break;

}

else

}

if (k==1) {

rowPassOne();

}

}

if (xi) {

for (j=x+1;j=i;j++ ) {

if (grid[j][y]!=0) {

k=0;

break;

}

else

}

if (k==1) {

rowPassOne();

}

}

if (x==i) {

rowPassOne();

}

}

if (k==2){

if (y0==y) {

remove();

}

if (y0y) {

for (n=y0;n=y-1 ;n++ ) {

if (grid[i][n]!=0) {

k=0;

break;

}

if(grid[i][n]==0 n==y-1) {

remove();

}

}

}

if (y0y) {

for (n=y0;n=y+1 ;n--) {

if (grid[i][n]!=0) {

k=0;

break;

}

if(grid[i][n]==0 n==y+1) {

remove();

}

}

}

}

}

}

}

public void linePassOne(){

if (y0j){ //第一按钮同行空按钮在左边

for (i=y0-1;i=j ;i-- ){ //判断第一按钮同左侧空按钮之间有没按钮

if (grid[x0][i]!=0) {

k=0;

break;

}

else //K=2说明通过了第二次验证

}

}

if (y0j){ //第一按钮同行空按钮在与第二按钮之间

for (i=y0+1;i=j ;i++){

if (grid[x0][i]!=0) {

k=0;

break;

}

else

}

}

}

public void rowPassOne(){

if (x0i) {

for (j=x0-1;j=i ;j-- ) {

if (grid[j][y0]!=0) {

k=0;

break;

}

else

}

}

if (x0i) {

for (j=x0+1;j=i ;j++ ) {

if (grid[j][y0]!=0) {

k=0;

break;

}

else

}

}

}

public void remove(){

firstButton.setVisible(false);

secondButton.setVisible(false);

fraction();

pressInformation=false;

k=0;

grid[x0][y0]=0;

grid[x][y]=0;

}

public void actionPerformed(ActionEvent e) {

if(e.getSource()==newlyButton){

int grid[][] = new int[8][7];

this.grid = grid;

randomBuild();

mainFrame.setVisible(false);

pressInformation=false;

init();

}

if(e.getSource()==exitButton)

System.exit(0);

if(e.getSource()==resetButton)

reload();

for(int cols = 0;cols 6;cols++){

for(int rows = 0;rows 5;rows++ ){

if(e.getSource()==diamondsButton[cols][rows])

estimateEven(cols+1,rows+1,diamondsButton[cols][rows]);

}

}

}

public static void main(String[] args) {

lianliankan llk = new lianliankan();

llk.randomBuild();

llk.init();

}

}

//old 998 lines

//new 318 lines

分享文章:包含java300级源代码的词条
网站地址:https://www.cdcxhl.com/article14/doegcge.html

成都网站建设公司_创新互联,为您提供云服务器服务器托管微信小程序静态网站网站维护商城网站

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

商城网站建设