java代码中文版 一段java代码的详细解说
Java 和 Python 有哪些区别?
1、Python比Java简单,学习成本低,开发效率高。
2、Java运行效率高于Python,尤其是纯Python开发的程序,效率极低。
3、Java相关资料多,尤其是中文资料。
4、Java版本比较稳定,Python2和3不兼容导致大量类库失效。
5、Java开发偏向于软件工程,团队协同,Python更适合小型开发。
6、Java偏向于商业开发,Python适合于数据分析。
7、Java是一种静态类型语言,Python是一种动态类型语言。
8、Java中的所有变量需要先声明(类型)才能使用,Python中的变量不需要声明类型。
求一个50行左右的JAVA代码,最好每行带注释,谢谢啦
/*这个相当详细了.
程序也不算太难.而且给老师看的时候效果比较好.因为有图形化界面,又实现一个比较实用的功能.老师会比较高兴的.
建立一个文件名为Change.java就可以编译了*/
/*
* 这个程序实现输入身高算出标准体重,输入体重,算出身高的功能
*/
import java.awt.*; //导入相关类包,这才样使用相应awt图形界面的类
import java.awt.event.*; //同上
public class Change extends Frame { //定义一个类Change, 父类是Frame(图形界面的)
Button b = new Button("互查"); //创建一个按钮的对象b,显示为"互查"
Label l1 = new Label("身高(cm)"); //创建一个lable.显示身高
Label l2 = new Label("体重(kg)"); //创建一个lable 显示体重
double heigth, weigth; //定义变量
double x, y; //定义变量
TextField tf1 = new TextField(null, 10); //添加Text框
TextField tf2 = new TextField(null, 10); //添加Text框
public Change() { //类的构造函数,完成初始化
super("互查表"); //创建窗口,标题为互查表
setLayout(new FlowLayout(FlowLayout.LEFT)); //设置布局
add(l1); //把lable 身高放到window里
add(tf1); //把Text 框 放到窗口上
add(l2); //把lable 体重放到window里
add(tf2); //Test放到窗口里
add(b); //把button放到窗口上
pack(); //自动放到窗口里排列上边的组件
setVisible(true); //可以让用户看到窗口
addWindowListener(new WindowAdapter() { //如果按 X, 关闭窗口
public void windowClosing(WindowEvent e) {
System.exit(0);
}
} );
b.addActionListener(new ButtonListener()); //添加button监听函数
}
class ButtonListener implements ActionListener { //实现click button时功能操作
public void actionPerformed(ActionEvent e) { //当click调用
if (tf1.getText()!=null) { //检查tf1 test 是否为空
try { //取异常
x = Double.parseDouble(tf1.getText()); //字符转为double型
weigth = (x - 100) * 0.9; //算重量
tf2.setText("" + weigth); //显示重量
} catch (NumberFormatException ex) {
tf1.setText(""); //如果输入不是数字,设为空
}
}
if (tf1.getText().equals("")==true){ //tf1是否为空
y = Double.parseDouble(tf2.getText()); //把tf2里的文本转为double 型 的
heigth = y / 0.9 + 100; //算身高根据重量
tf1.setText("" + heigth); } //显示身高
}
}
public static void main(String[] args) { //主函数,程序入口
new Change(); //建立类Change的对象,并调用他的构造函数Change().显示窗口
}
}
Effective Java中文版的内容简介
《Effective Java中文版(第2版)》主要内容:在Java编程中78条极具实用价值的经验规则,这些经验规则涵盖了大多数开发人员每天所面临的问题的解决方案。通过对Java平台设计专家所使用的技术的全面描述,揭示了应该做什么,不应该做什么才能产生清晰、健壮和高效的代码。第2版反映了Java 5中最重要的变化,并删去了过时的内容。
《Effective Java中文版(第2版)》中的每条规则都以简短、独立的小文章形式出现,并通过示例代码加以进一步说明。
《Effective Java中文版(第2版)》的内容包括:
全新的泛型、枚举、注解、自动装箱、for-each循环、可变参数、并发机制,等等。
经典主题的全新技术和最佳实践,包括对象.类、类库、方法和序列化。
如何避免Java编程语言中常被误解的细微之处:陷阱和缺陷。
点击链接进入Java程序设计:
《深入理解Java虚拟机:JVM高级特性与最佳实践》
《JAVA核心技术(卷1):基础知识(原书第8版)》
《JAVA核心技术卷2:高级特征》
《Java语言程序设计(基础篇)(原书第8版)》
《Java编程思想(第4版)》
《Effective Java中文版(第2版)》
《Java编程思想(英文版?第4版)》
《Java 实时编程》
《Java加密与解密的艺术》
《Eclipse插件开发(原书第3版)(畅销插件开发指南新版)》
《Java语言程序设计:进阶篇(原书第8版)》
《Maven实战》
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; } //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 { k=1; }
}
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 { k=1; }
}
if (k==1) {
rowPassOne();
}
}
if (xi) {
for (j=x+1; j=i; j++ ) {
if (grid[j][y]!=0) {
k=0;
break;
}
else { k=1; }
}
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; } //K=2说明通过了第二次验证
}
}
if (y0j){ //第一按钮同行空按钮在与第二按钮之间
for (i=y0+1; i=j ; i++){
if (grid[x0][i]!=0) {
k=0;
break;
}
else{ k=2; }
}
}
}
public void rowPassOne(){
if (x0i) {
for (j=x0-1; j=i ; j-- ) {
if (grid[j][y0]!=0) {
k=0;
break;
}
else { k=2; }
}
}
if (x0i) {
for (j=x0+1; j=i ; j++ ) {
if (grid[j][y0]!=0) {
k=0;
break;
}
else { k=2; }
}
}
}
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
求采纳为满意回答。
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: java代码中文版 一段java代码的详细解说
本文地址: https://pptw.com/jishu/2801.html