RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
java带注释的源代码 java带注释的源代码有哪些

Java源代码注释

你的这段代码是获取配置文件中数据库配置信息

我们提供的服务有:网站设计制作、做网站、微信公众号开发、网站优化、网站认证、盘锦ssl等。为1000+企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的盘锦网站制作公司

配置内容都在DBConfig.txt 这个文件中了

package dda;

import java.sql.*;

import java.io.LineNumberReader;

import java.io.FileReader;

import java.util.StringTokenizer;

/**

*

* 读取配置文件DBConfig.txt中的配置信息

* @author xxx

* @version 1.0

*/

public class DbConnection {

Connection conn = null;

ResultSet rs = null;

boolean b;

public DbConnection() {

this.b = false;

this.getDBConfig();

}

/* 定义变量 */

String strSeparate = " ";

String strFileName = "DBConfig.txt";

String strUserID = null;

String strUserPWD = null;

String strDB = null;

public void getDBConfig() {

this.getDBConfig();

try {

LineNumberReader oLineNumberReader = new LineNumberReader(

new FileReader(this.strFileName)); // 从 DBConfig.txt 文件中读取数据库配置

String strLine = null;

while ((strLine = oLineNumberReader.readLine()) != null) {// 遍历配置文件中每一行数据

StringTokenizer token = new StringTokenizer(strLine,(new String(this.strSeparate).toString())); // 按空格拆分配置内容

/* 以下三行都是给属性设值,获取配置属性 */

this.strDB = token.nextToken();

this.strUserID = token.nextToken();

this.strUserPWD = token.nextToken();

}

} catch (Exception e) {

System.out.println("DB:"+strFileName);

}

}

}

java 源代码注释

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.*;

public class GameTest extends JFrame implements ActionListener{

/*

* 新建一个主面板(这个类可能是自定义的,本程序和API中没有)。

*/

MainPanel j=new MainPanel();

JButton jPreview;

JLabel label;

Container container;

JPanel panel;

/**

* 主函数

* @param args

*/

public static void main(String[] args) {

//运行程序

new GameTest();

}

/**

* 构造函数。

*

*/

public GameTest()

{

//新建一个标题为“拼图”的窗口

JFrame fr =new JFrame("拼图");

//获取窗口容器。

container=fr.getContentPane();

//创建菜单条

JMenuBar jMenuBar=new JMenuBar();

//以下初始化菜单,并且设置快捷键和添加监听器。

JMenu jMenuGame=new JMenu("游戏(G)");

jMenuGame.setMnemonic('g');

JMenuItem jMenuItemStart = new JMenuItem("开始(S)");

jMenuItemStart.setMnemonic('s');

jMenuItemStart.addActionListener(this);

JMenuItem jMenuItemExit=new JMenuItem("退出(E)");

jMenuItemExit.setMnemonic('e');

jMenuItemExit.addActionListener(this);

jMenuGame.add(jMenuItemStart);

jMenuGame.add(jMenuItemExit);

//初始化按钮并设置快捷键和添加监听器

JButton jChoice=new JButton("选图(X)");

jChoice.setMnemonic('x');

jChoice.addActionListener(this);

jPreview=new JButton("预览(P)");

jPreview.setMnemonic('p');

jPreview.addActionListener(this);

//将菜单和按钮添加到菜单条中

jMenuBar.add(jMenuGame);

jMenuBar.add(jChoice);

jMenuBar.add(jPreview);

//将菜单条设为该窗口的主菜单

fr.setJMenuBar(jMenuBar);

//将主面板添加到该窗口的容器中。

container.add(j);

//设置大小

fr.setSize(315,360 );

fr.setVisible(true);

//设置默认关闭方式。

fr.setDefaultCloseOperation(3);

}

/**

* 事件处理函数。

*/

public void actionPerformed(ActionEvent e) {

if(e.getActionCommand()=="开始(S)")

{

j.Start();

}

if(e.getActionCommand()=="预览(P)")

{

j.setVisible(false);

panel=new JPanel();

Icon icon=new ImageIcon("pictrue/pic"+"_"+MainPanel.pictureID+".jpg");

label=new JLabel(icon);

label.setBounds(300, 300, 0, 0);

panel.add(label);

panel.setSize(300, 300);

panel.setVisible(true);

this.container.add(panel);

jPreview.setText("返回(P)");

}

if(e.getActionCommand()=="返回(P)")

{

panel.setVisible(false);

j.setVisible(true);

j.repaint();

jPreview.setText("预览(P)");

}

if(e.getActionCommand()=="退出(E)")

{

System.exit(0);

}

if(e.getActionCommand()=="选图(X)")

{

//初始化选择框,并提供选择。

Choice pic = new Choice();

pic.add("七里香");

pic.add("依然范特西");

pic.add("八度空间");

pic.add("十一月的肖邦");

pic.add("魔杰座");

pic.add("叶惠美");

pic.add("我很忙");

int i=JOptionPane.showConfirmDialog(this, pic, "选择图片", JOptionPane.OK_CANCEL_OPTION);

if(i==JOptionPane.YES_OPTION)

{

//选择图片

MainPanel.pictureID=pic.getSelectedIndex()+1;

j.removeAll();

j.reLoadPicture();

j.repaint();

}

}

}

}

求将java源代码加详细的注释,程序已给出

package com.the2cities.servlet;

import java.awt.Color;

import java.awt.Graphics;

import java.awt.Graphics2D;

import java.awt.Rectangle;

import java.awt.TexturePaint;

import java.awt.event.KeyEvent;

import java.awt.event.KeyListener;

import java.awt.geom.GeneralPath;

import java.awt.geom.RoundRectangle2D;

import java.awt.image.BufferedImage;

import javax.swing.JFrame;

public class pentagram extends JFrame implements KeyListener {

int x=150,y=150;

public pentagram() {

//初始化

setSize(400, 400);//设置大小

setVisible(true);//显示

this.addKeyListener(this);//按键的监听事件

}

public void keyPressed(KeyEvent e) {

//方向键

if(e.getKeyCode()==37)

{

x-=10; //向左边移动10像素

repaint(); //刷新

}

if(e.getKeyCode()==38)

{

y-=10; //向上边移动10像素

repaint();//刷新

}

if(e.getKeyCode()==39)

{

x+=10;//向右边移动10像素

repaint();//刷新

}

if(e.getKeyCode()==40)

{

y+=10;//向下边移动10像素

repaint();//刷新

}

}

public void keyReleased(KeyEvent e) {

}

public void keyTyped(KeyEvent e) {

}

public void paint(Graphics g) {//重写了JFrame的paint,在上面刷新的方法可以调用到这个方法。

super.paint(g);

//A

int xPoint[]={55,67,109,73,83,55,27,37,1,43};

int yPoint[]={0,36,36,54,96,72,96,54,36,36};

Graphics2D g2d=(Graphics2D)g;//整个窗口就是一个画板

GeneralPath star=new GeneralPath();

star.moveTo(xPoint[0], yPoint[0]);

for(int count=1;countxPoint.length;count++)

{

star.lineTo(xPoint[count], yPoint[count]);

}

star.closePath();

//B

//A到B是画出一个星星。

g2d.translate(x, y);//设置星星位置,x,y就是上面,按方向键产生的数字。

g2d.setColor(new Color((int)(Math.random()*256),(int)(Math.random()*256),(int)(Math.random()*256)));//随机设置颜色

g2d.fill(star);//把星星放到画板里去。

}

public static void main(String[] arge) {

pentagram s = new pentagram();

s.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

}


当前名称:java带注释的源代码 java带注释的源代码有哪些
网站链接:http://scyingshan.cn/article/doseshj.html