网站首页 > 文章中心 > 其它

关于java源代码1000的信息

作者:小编 更新时间:2023-09-08 18:44:47 浏览量:115人看过

java 源代码 基础点的 谢谢

package com.regex;

关于java源代码1000的信息-图1

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

关于java源代码1000的信息-图2

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 {

} catch (Exception e) {

e.printStackTrace();

// TODO: handle exception

}

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);

LOGIC++;

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

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

}catch(IOException e){

*

* @return int

* @version check s

public int CheckChar(String s){

if(s!=null)

s1=s.trim();

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

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

return 1;

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

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

start=true;

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

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

start=false;

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

if(strCheck(s1)){

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

}//aeee

* @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++;

boo[i]=true;

}else{

boo[i]=false;

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

if(!boo[i])

return false;

return true;

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

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+"\"没有出现过");

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("开始");

boolean isGo = false;

//构造函数

public GoodLucky(){

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

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

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

p.add(b1);

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

//监听处理.

b1.addActionListener(this);

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

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

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

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(){

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

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

if(i 10){

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

/*

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

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

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

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

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

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

isGo = true; //设置isGo为true

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

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

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

public static void main(String[] args){

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

求java小游戏源代码

import java.applet.Applet;

import java.applet.AudioClip;

import java.awt.Dimension;

import java.awt.Font;

import java.awt.Toolkit;

import javax.sound.sampled.AudioFileFormat;

import javax.sound.sampled.AudioSystem;

import javax.swing.JFrame;

import javax.swing.JPanel;

import java.awt.Rectangle;

import javax.swing.BorderFactory;

import javax.swing.JButton;

import javax.swing.JOptionPane;

import javax.swing.JSlider;

import javax.swing.JLabel;

import javax.swing.SwingUtilities;

import javax.swing.UIManager;

import javax.swing.event.ChangeEvent;

import javax.swing.event.ChangeListener;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.KeyAdapter;

import java.awt.event.KeyEvent;

import java.io.File;

import java.util.Vector;

public class Frame extends JFrame implements Runnable {

JPanel contentPane;

JPanel jPanel1 = new JPanel();

JButton jButton1 = new JButton();

JSlider jSlider1 = new JSlider();

JLabel jLabel1 = new JLabel();

int zhengque = 0, cuowu = 0;

int rush_count = 0; //记录关数

char list[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',

'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y',

Vector number = new Vector();

String paiduan = "true";

AudioClip Musci_anjian, Music_shibai, Music_chenggong;

public Frame() {

setDefaultCloseOperation(EXIT_ON_CLOSE);

//-----------------声音文件---------------------

Musci_anjian = Applet.newAudioClip(new File("sounds//anjian.wav")

.toURL());

Music_shibai = Applet.newAudioClip(new File("sounds//shibai.wav")

Music_chenggong = Applet.newAudioClip(new File(

"sounds//chenggong.wav").toURL());

//---------------------------------------

jbInit();

} catch (Exception exception) {

exception.printStackTrace();

* Component initialization.

* @throws java.lang.Exception

private void jbInit() throws Exception {

contentPane = (JPanel) getContentPane();

contentPane.setLayout(null);

setTitle("Frame Title");

jPanel1.setBorder(BorderFactory.createEtchedBorder());

jPanel1.setLayout(null);

jButton1.setText("开始");

jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));

jSlider1.setMaximum(100);

jSlider1.setMinimum(1);

jLabel1.setText("速度");

contentPane.add(jPanel1);

contentPane.add(jButton1);

contentPane.add(jSlider1);

contentPane.add(jLabel1);

this.addKeyListener(new MyListener());

jButton1.addKeyListener(new MyListener());

jSlider1.addKeyListener(new MyListener());

jSlider1.addChangeListener(new ChangeListener() {

public void stateChanged(ChangeEvent e) {

rapidity = jSlider1.getValue();

});

public void run() {

number.clear();

zhengque = 0;

cuowu = 0;

paiduan = "true";

while (count = rush[rush_count]) {

Thread t = new Thread(new Tthread());

t.start();

count += 1;

} catch (InterruptedException e) {

while (true) { // 等待最后一个字符消失

if (number.size() == 0) {

break;

if (zhengque == 0) { // 为了以后相除..如果全部正确或者错误就会出现错误. 所以..

zhengque = 1;

if (cuowu == 0) {

cuowu = 1;

关于java源代码1000的信息-图3

if (paiduan.equals("true")) { // 判断是否是自然结束

JOptionPane.showMessageDialog(null, "恭喜你过关了");

rush_count += 1; // 自动加1关

if (rush_count rush.length) {

jSlider1.setValue(rapidity); // 选择位置

Thread t = new Thread(this);

} else {

JOptionPane.showMessageDialog(null, "牛B...你通关了..");

rush_count = 0;

count = 0;

JOptionPane.showMessageDialog(null, "请再接再励");

public void jButton1_actionPerformed(ActionEvent e) {

count = rush[rush_count] + 1;

paiduan = "flase";

class Tthread implements Runnable {

boolean fo = true;

int Y = 0, X = 0;

JLabel show = new JLabel();

jPanel1.add(show);

String parameter = list[(int) (Math.random() * list.length)] + "";

Bean bean = new Bean();

bean.setParameter(parameter);

bean.setShow(show);

number.add(bean);

show.setText(parameter);

while (fo) {

// ---------------------数字下移--------------------

Thread.sleep(rapidity);

fo = false;

for (int i = number.size() - 1; i = 0; i--) {

Bean bn = ((Bean) number.get(i));

if (parameter.equalsIgnoreCase(bn.getParameter())) {

cuowu += 1;

+ "个");

number.removeElementAt(i);

Music_shibai.play();

class MyListener extends KeyAdapter {

public void keyPressed(KeyEvent e) {

String uu = e.getKeyChar() + "";

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

Bean bean = ((Bean) number.get(i));

if (uu.equalsIgnoreCase(bean.getParameter())) {

zhengque += 1;

bean.getShow().setVisible(false);

Music_chenggong.play();

Musci_anjian.play();

public static void main(String[] args) {

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

Frame frame = new Frame();

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

Dimension frameSize = frame.getSize();

if (frameSize.height screenSize.height) {

frameSize.height = screenSize.height;

if (frameSize.width screenSize.width) {

frameSize.width = screenSize.width;

frame.setVisible(true);

private Frame adaptee;

this.adaptee = adaptee;

public void actionPerformed(ActionEvent e) {

class Frame1_jButton1_actionAdapter implements ActionListener {

Frame1_jButton1_actionAdapter(Frame adaptee) {

adaptee.jButton1_actionPerformed(e);

class Bean {

String parameter = null;

JLabel show = null;

public JLabel getShow() {

return show;

public void setShow(JLabel show) {

this.show = show;

public String getParameter() {

return parameter;

public void setParameter(String parameter) {

this.parameter = parameter;

java编写一个"猜数"程序:该程序随机在1到1000的范围中选择一个供用户猜测的整数

Java源程序附后.

本程序的特点是:

(1) 文本框只能输入纯数字;

import java.util.*;

public class GuessNumber {

private static final long serialVersionUID = 1L;

JFrame frame;

JTextField txtNum;//文本框

JButton btnStart;//按钮

JLabel lblPrompt;

JLabel lblMessage;

static int source = 0;

static Random rand = new Random();

public GuessNumber(){

frame = new JFrame("Guess Number");

pnl1 = new JPanel();

pnl1.setLayout(new FlowLayout(FlowLayout.LEFT));

txtNum = new JTextField(10);

btnStart = new JButton("开始");

lblPrompt = new JLabel("htmlbodyI have a number between 1 and 1000 can you guess my number?br/Please enter your first guess./body/html");

lblMessage = new JLabel();

pnl1.add(lblPrompt);

frame.add(pnl1);

txtNum.addActionListener(this.new TextAction());

txtNum.addKeyListener(this.new KeyAction());

btnStart.addActionListener(this.new ButtonAction());

frame.setLocationRelativeTo(null);

frame.setResizable(false);

new GuessNumber();

while((source=rand.nextInt(1000))==0);

//按钮单击后的事件处理

class ButtonAction implements ActionListener{

@Override

JButton btn = (JButton)e.getSource();

if(btn == btnStart){

txtNum.setEditable(true);

//文本框按回车后的事件处理

class TextAction implements ActionListener{

JTextField txt = (JTextField)e.getSource();

if(txt != txtNum){

return;

int num = Integer.parseInt(txtNum.getText());

if(num == source){

lblMessage.setText("Correct!");

txtNum.setEditable(false);

txtNum.setBackground(frame.getBackground());

else if(num source){

lblMessage.setText("Too High");

txtNum.setBackground(Color.red);

else{

lblMessage.setText("Too Low");

txtNum.setBackground(Color.blue);

//限制文本框只能输入数字

class KeyAction implements KeyListener{

public void keyReleased(KeyEvent e) {

public void keyTyped(KeyEvent e) {

int k = e.getKeyChar();

String text = ((JTextField)e.getSource()).getText();

e.setKeyChar((char)KeyEvent.VK_CLEAR);

一个数如果恰好等于它的因子之和,这个数就称为完数,编写一个JAVA程序1000内的所有完数

源代码如下:

#include stdio.h

main()

{

int i,j;

int sum;

for(i=1;i=1000;i++)

sum=0;

for(j=1;ji;j++)

if(i%j==0)

sum+=j;

if(sum==i)

printf("%d its factors are ",i);

printf("%d ",j);

printf("\n");

扩展资料

①.、完全数是一些特殊的自然数,它所有的真因子即除了自身以外的约数的和即因子函数,恰好等于它本身.

求用JAVA编写俄罗斯方块游戏的源代码

求Java源代码:用Java实现输出:1000之内能被7整除的数之和.不要用for循环做题.我还没学到.嘿嘿.谢过

int i=1;

while(true){

i++;

if(i1000)break;

以上就是土嘎嘎小编为大家整理的关于java源代码1000的信息相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!

版权声明:倡导尊重与保护知识产权。未经许可,任何人不得复制、转载、或以其他方式使用本站《原创》内容,违者将追究其法律责任。本站文章内容,部分图片来源于网络,如有侵权,请联系我们修改或者删除处理。

编辑推荐

热门文章