欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

java基礎(chǔ)入門源代碼,java基礎(chǔ)編程

求用java比較四個數(shù)大小源代碼 (初學(xué)者 希望朋友給的代碼是基礎(chǔ)的那種)

package mypackage.OrderInt4;

峨山縣網(wǎng)站制作公司哪家好,找成都創(chuàng)新互聯(lián)!從網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、響應(yīng)式網(wǎng)站等網(wǎng)站項目制作,到程序開發(fā),運營維護(hù)。成都創(chuàng)新互聯(lián)從2013年開始到現(xiàn)在10年的時間,我們擁有了豐富的建站經(jīng)驗和運維經(jīng)驗,來保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選成都創(chuàng)新互聯(lián)。

/*求用java比較四個數(shù)大小源代碼 (初學(xué)者 希望朋友給的代碼是基礎(chǔ)的那種) 老師說只要兩個類 其中一個類從另一個類里調(diào)用*/

public class TestOrder {

public static void main(String[] args) {

int[] array = { 11, 77, 22, 44 };

// 也可以從控制臺輸出

int[] newArray = Order.orderBy(array);

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

System.out.println(newArray[i] + " ");

}

}

}

class Order {

public static int[] orderBy(int[] intArray) {

int tempArray[] = intArray;

int length = tempArray.length;

int tempValue = 0;

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

for (int j = i + 1; j length; j++) {

if (tempArray[i] tempArray[j]) {

tempValue = tempArray[i];

tempArray[i] = tempArray[j];

tempArray[j] = tempValue;

}

}

}

return tempArray;

}

}

我是初學(xué)者,對Java了解甚少,請幫忙給點源代碼吧,越簡單越好。

class test

{

public static void main(String[] args)

{

System.out.println("Hello World!");

}

}

在C盤保存文件名為test

進(jìn)入cmd運行 javac test.java 進(jìn)行編譯

然后運行test.java看到輸出hello world

我的第一個程序就完成了

如果運行javac 報錯的話那可能是環(huán)境變量沒有配置好,在仔細(xì)看看重新配置一下

求編寫一個超級簡單的Java的程序源代碼

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

class ConstructFrame extends JFrame

{

private static final long serialVersionUID = 1L;

String value1="",result,value2="";

int flag=0,fix=0,sum=1;

Boolean happy;

JTextField text=new JTextField(30);

int flagsum=0;

Container c=getContentPane();

JButton buttonx;

ConstructFrame()

{ super("計算器");

c.setLayout(null);

c.setBackground(Color.blue);

this.setSize(400, 400);

c.add(text);

text.setHorizontalAlignment(JTextField.RIGHT);

final JButton buttonx=new JButton("BackSpace");

c.add(buttonx);

buttonx.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

int count=0;

String temp;

if(flag==0)

{

count=value1.length();

if(count!=1)

temp=value1.substring(0, count-1);

else

temp="0";

value1=temp;

}

else

{

count=value2.length();

if(count!=1)

temp=value2.substring(0, count-1);

else

temp="0";

value2=temp;

}

text.setText(temp);

}

});

final JButton buttony=new JButton("CE");

c.add(buttony);

buttony.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

value1="";

value2="";

flag=0;

text.setText("0");

}

});

final JButton button1=new JButton("1");

c.add(button1);

button1.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

String temp;

if(flag==0)

{

value1=value1+1;

temp=value1;

}

else

{

value2=value2+1;

temp=value2;

}

text.setText(temp);

}

});

final JButton button2=new JButton(" 2 ");

c.add(button2);

button2.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

String temp;

if(flag==0)

{

value1=value1+2;

temp=value1;

}

else

{

value2=value2+2;

temp=value2;

}

text.setText(temp);

}

});

final JButton button3=new JButton("3");

c.add(button3);

button3.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

String temp;

if(flag==0)

{

value1=value1+3;

temp=value1;

}

else

{

value2=value2+3;

temp=value2;

}

text.setText(temp);

}

});

final JButton button4=new JButton("4");

c.add(button4);

button4.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

String temp;

if(flag==0)

{

value1=value1+4;

temp=value1;

}

else

{

value2=value2+4;

temp=value2;

}

text.setText(temp);

}

});

final JButton button5=new JButton("5");

c.add(button5);

button5.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

String temp;

if(flag==0)

{

value1=value1+5;

temp=value1;

}

else

{

value2=value2+5;

temp=value2;

}

text.setText(temp);

}

});

final JButton button6=new JButton("6");

c.add(button6);

button6.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

String temp;

if(flag==0)

{

value1=value1+6;

temp=value1;

}

else

{

value2=value2+6;

temp=value2;

}

text.setText(temp);

}

});

final JButton button7=new JButton("7");

c.add(button7);

button7.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

String temp;

if(flag==0)

{

value1=value1+7;

temp=value1;

}

else

{

value2=value2+7;

temp=value2;

}

text.setText(temp);

}

});

final JButton button8=new JButton("8");

c.add(button8);

button8.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

String temp;

if(flag==0)

{

value1=value1+8;

temp=value1;

}

else

{

value2=value2+8;

temp=value2;

}

text.setText(temp);

}

});

final JButton button9=new JButton("9");

c.add(button9);

button9.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

String temp;

if(flag==0)

{

value1=value1+9;

temp=value1;

}

else

{

value2=value2+9;

temp=value2;

}

text.setText(temp);

}

});

final JButton button0=new JButton("0");

c.add(button0);

button0.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

String temp;

if(flag==0)

{

value1=value1+0;

temp=value1;

}

else

{

value2=value2+0;

temp=value2;

}

text.setText(temp);

}

});

final JButton buttonadd=new JButton(" + ");

c.add(buttonadd);

buttonadd.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

flag=1;

fix=1;

flagsum=0;

}

});

final JButton buttonsubtract=new JButton(" - ");

c.add(buttonsubtract);

buttonsubtract.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

flag=1;

fix=2;

flagsum=0;

}

});

final JButton buttoncheng=new JButton(" * ");

c.add(buttoncheng);

buttoncheng.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

flag=1;

fix=3;

flagsum=0;

}

});

final JButton buttonchu=new JButton(" / ");

c.add(buttonchu);

buttonchu.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

flag=1;

flagsum=0;

fix=4;

}

});

final JButton buttonequal=new JButton(" = ");

c.add(buttonequal);

buttonequal.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{

double temp1,temp2;

double temp=0;

flagsum=0;

temp1=Double.parseDouble(value1);

temp2=Double.parseDouble(value2);

flag=0;

switch(fix)

{

case 1: temp=temp1+temp2;break;

case 2: temp=temp1-temp2;break;

case 3: temp=temp1*temp2;break;

case 4: temp=temp1/temp2;break;

}

result=Double.valueOf(temp).toString();

value1=result;

value2="";

flag=1;

text.setText(result);

}

});

final JButton buttonpoint=new JButton(".");

c.add(buttonpoint);

buttonpoint.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{ if(flagsum==0)

{

String temp;

if(flag==0 )

{

value1=value1+".";

temp=value1;

}

else

{

value2=value2+".";

temp=value2;

}

flagsum=1;

text.setText(temp);

}

}

});

JButton buttonz=new JButton("Start");

c.add(buttonz);

buttonz.addMouseListener(new MouseAdapter()

{

public void mousePressed(MouseEvent e)

{ if(sum%2==1)

{

happy=true;

text.setText("0.");

flag=0;

}

else

{

happy=false;

value1="";

value2="";

text.setText("");

}

text.setEnabled(happy);

button1.setEnabled(happy);

button2.setEnabled(happy);

button3.setEnabled(happy);

button4.setEnabled(happy);

button5.setEnabled(happy);

button6.setEnabled(happy);

button7.setEnabled(happy);

button8.setEnabled(happy);

button9.setEnabled(happy);

button0.setEnabled(happy);

buttonx.setEnabled(happy);

buttony.setEnabled(happy);

buttonadd.setEnabled(happy);

buttonsubtract.setEnabled(happy);

buttonpoint.setEnabled(happy);

buttonequal.setEnabled(happy);

buttoncheng.setEnabled(happy);

buttonchu.setEnabled(happy);

sum++;

}

});

button1.setEnabled(false);

button2.setEnabled(false);

button3.setEnabled(false);

button4.setEnabled(false);

button5.setEnabled(false);

button6.setEnabled(false);

button7.setEnabled(false);

button8.setEnabled(false);

button9.setEnabled(false);

button0.setEnabled(false);

buttonx.setEnabled(false);

buttony.setEnabled(false);

buttonadd.setEnabled(false);

buttonsubtract.setEnabled(false);

buttonpoint.setEnabled(false);

buttonequal.setEnabled(false);

buttoncheng.setEnabled(false);

buttonchu.setEnabled(false);

text.setEnabled(false);

text.setBounds(20, 20, 200, 40);

buttonx.setBounds(20, 60,100, 40);

buttony.setBounds(140, 60,100, 40);

buttonz.setBounds(260, 60,80, 40);

button1.setBounds(20, 120,60, 40);

button2.setBounds(100, 120,60, 40);

button3.setBounds(180, 120,60, 40);

buttonadd.setBounds(260, 120,60, 40);

button4.setBounds(20, 180,60, 40);

button5.setBounds(100, 180,60, 40);

button6.setBounds(180, 180,60, 40);

buttonsubtract.setBounds(260, 180,60, 40);

button7.setBounds(20, 240,60, 40);

button8.setBounds(100, 240,60, 40);

button9.setBounds(180, 240,60, 40);

buttoncheng.setBounds(260,240,60,40);

button0.setBounds(20, 300,60, 40);

buttonpoint.setBounds(100, 300, 60, 40);

buttonequal.setBounds(180,300,60, 40);

buttonchu.setBounds(260, 300,60, 40);

setVisible(true);

}

class MYMouseEvent extends MouseAdapter

{

public void mousePressed(MouseEvent e)

{

value1=e.toString();

text.setText(value1);

}

}

}

class Calutator

{

public static void main(String[] args)

{

new ConstructFrame();

}

}

你自己慢慢的看吧!

初學(xué)者請求java源代碼

class Car

{

// 車輛屬性

private String brand; // 品牌

private double engineDisplacement;// 排氣量

private double speed;// 當(dāng)前速度

private boolean status;// 啟動狀態(tài)

private double maxSpeed;// 最大速度

public double getSpeed () {

return this.speed;

}

public Car(String brand, double engineDisplacement, double maxSpeed) {

this.brand = brand;

this.engineDisplacement = engineDisplacement;

this.maxSpeed = maxSpeed;

// 其他屬性也要有初始值,不然執(zhí)行出錯。

this.speed = 0;

this.status = false;

}

/** 啟動 */

public void start() {

this.status = true;

printNowStatus ();

}

/** 關(guān)閉(熄火) */

public void stop() {

// 只在速度為0時關(guān)閉(貌似樓上兩位沒仔細(xì)看題…)

if (this.speed == 0)

{

this.status = false;

}

printNowStatus ();

}

/** 加速 */

public void speedUp() {

// 只在啟動時可以加速

if (this.status)

{

this.speed = this.speed + 20;

if (this.speed this.maxSpeed)

{

this.speed = this.maxSpeed;

}

}

printNowStatus ();

}

/** 減速 */

public void slowDown() {

// 只在啟動時可以減速

if (this.status)

{

this.speed = this.speed - 10;

if (this.speed 0)

{

this.speed = 0;

}

}

printNowStatus ();

}

/** 狀態(tài)打印,在每次啟動,加減速,關(guān)閉時調(diào)用 */

private void printNowStatus () {

System.out.println("轎車【" + this.brand + "】現(xiàn)在的啟動狀態(tài)是:" + this.status + "速度是:" + this.speed +"。");

}

}

public class TestCar

{

public static void main(String[] args)

{

Car myCar = new Car ("紅旗", 2, 120);

//啟動

myCar.start();

// 循環(huán)加速到120

while (myCar.getSpeed() 120)

{

myCar.speedUp();

}

//循環(huán)減速

while (myCar.getSpeed() 0)

{

myCar.slowDown();

}

//關(guān)閉

myCar.stop();

}

}

/* 直接拿文本寫的,我用的電腦沒裝jdk,樓主自己到Java開發(fā)環(huán)境下調(diào)試,應(yīng)該沒什么問題… */

java新手,求完整的源代碼

//都是從新手過來的,以下代碼供參考

//1.

public?class?BankAccount?{

private?static?String?acctnum;

private?static?double?money;

private?static?void?showAcct()?{

System.out.println("賬號為:?"?+?acctnum);

}

private?static?void?showMoney()?{

System.out.println("余額為:?"?+?money);

}

public?BankAccount(String?acc,?double?m)?{

this.acctnum?=?acc;

this.money?=?m;

}

public?static?void?main(String[]?args)?{

BankAccount?ba?=?new?BankAccount("626600018888",?5000.00);

ba.showAcct();

ba.showMoney();

}

}

//2.

public?class?Triangle?{

private?static?float?a;

private?static?float?b;

private?static?float?c;

public?Triangle(float?a,?float?b,?float?c)?{

this.a?=?a;

this.b?=?b;

this.c?=?c;

}

public?static?boolean?judgeTriangle(float?a,?float?b,?float?c)?{

if?((a??Math.abs(b?-?c)??a??b?+?c)

?(b??Math.abs(a?-?c)??b??a?+?c)

?(c??Math.abs(a?-?b)??c??a?+?b))

return?true;

else

return?false;

}

public?float?getCircumference()?{

return?this.a?+?this.b?+?this.c;

}

}

//3.

public?class?TestTriangle?{

public?static?void?main(String[]?args)?{

Triangle?t?=?new?Triangle(5.3f,7.8f,9.3f);

if(t.judgeTriangle(5.3f,7.8f,9.3f)){

System.out.print("能夠成三角形,周長為:?");

System.out.printf("%9.2f",t.getCircumference());}

else

System.out.println("不能構(gòu)成三角形");

}

}

java 源代碼 基礎(chǔ)點的 謝謝

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,"(.* */*/)")){ //判斷*/結(jié)尾的純注釋行

start=false;

return 1;

}

if(regCheck(s1,"(.* */*/.*)")!strCheck(s1)){ //判斷不是*/結(jié)尾的非純注釋行

if(strCheck(s1)){

start=false;

return 2;

}

}

if(start==true) //狀態(tài)代碼,start即/*開始時start=true*/結(jié)束時為false

return 1;

return 3;//ssssllll

}//aeee

/**

*

* @param s

* @param re

* @return boolean

*/

public boolean regCheck(String s,String re){ //正則表達(dá)試判斷方法

return Pattern.matches(re,s);

}

public boolean strCheck(String s){ //中間有*/的字符判斷 此方法最關(guān)鍵

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){ //此方法為我前面寫的字符串出現(xiàn)次數(shù)統(tǒng)計方法,不懂的可以看我前面的文章

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+"\"沒有出現(xiàn)過");

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(); //實例化一個文本域

//設(shè)置兩個按鈕

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

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

boolean isGo = false;

//構(gòu)造函數(shù)

public GoodLucky(){

b1.setActionCommand("start");//在開始按鈕上設(shè)置一個動作監(jiān)聽 start

JPanel p = new JPanel(); //實例化一個可視化容器

//將兩個按鈕添加到可視化容器上面,用add方法

p.add(b1);

p.add(b2);

//在兩個按鈕上增加監(jiān)聽的屬性,自動調(diào)用下面的監(jiān)聽處理方法actionPerformed(ActionEvent e),如果要代碼有更好的可讀性,可用內(nèi)部類實現(xiàn)動作

//監(jiān)聽處理。

b1.addActionListener(this);

b2.addActionListener(this);

//將停止按鈕設(shè)置為不可編輯(即不可按的狀態(tài))

b2.setEnabled(false);

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

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

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //設(shè)置用戶在此窗體上發(fā)起 "close" 時默認(rèn)執(zhí)行的操作,參數(shù)EXIT_ON_CLOSE是使用 System exit 方法退出應(yīng)用程序。僅在應(yīng)用程序中使用

this.setSize(300,200); //設(shè)置面板大小,寬和高

this.setLocation(300,300); //設(shè)置面板剛開始的出現(xiàn)的位置

Cursor cu = new Cursor(Cursor.HAND_CURSOR); //用指定名稱創(chuàng)建一個新的定制光標(biāo)對象,參數(shù)表示手狀光標(biāo)類型

this.setCursor(cu); //為指定的光標(biāo)設(shè)置光標(biāo)圖像,即設(shè)置光標(biāo)圖像為上面所創(chuàng)建的手狀光標(biāo)類型

this.setVisible(true); //將面板可視化設(shè)置為true,即可視,如果為false,即程序運行時面板會隱藏

tf.setText("welcome you! "); //設(shè)置面板的標(biāo)題為歡迎

this.go(); //調(diào)用go方法

}

public void go(){

while(true){ //這里是死循環(huán),也就是說用戶不點擊停止按鈕的話他一直循環(huán)出現(xiàn)隨機(jī)數(shù),直到用戶點擊停止按鈕循環(huán)才能推出,具體流程在actionPerformed方法中控制。

if(isGo == true){ //上面所定義的isGo的初始值為false,所以程序第一次到此會跳過

String s = ""; //設(shè)置空字符串

for(int j = 1; j = 7;j++){ //產(chǎn)生7個隨機(jī)數(shù)

int i = (int)(Math.random() * 36) + 1;//每個隨機(jī)數(shù)產(chǎn)生方式,這里定義靈活,可以自由定義隨機(jī)數(shù)產(chǎn)生的方式

if(i 10){

s = s + " 0" + i; //如果產(chǎn)生的隨機(jī)數(shù)小于10的話做處理:這里就牽扯到一個重要的概念,簡單敘述一下:

/*

當(dāng)一個字符串與一個整型數(shù)項相加的意思是連接,上面的s = s + " 0" + i的意思是字符串s鏈接0再連接整型i值,而不會導(dǎo)致0和整型的i相加,

產(chǎn)生的效果為s0i,由于s為空字符串(上面定義過的),所以當(dāng)i小于零時,在個位數(shù)前面加上0,比如產(chǎn)生的隨機(jī)數(shù)i為7的話,顯示效果為 07.

*/

}else{

s = s + " " + i; //如果產(chǎn)生的隨機(jī)數(shù)比10打的話,那么加上空格顯示,即數(shù)字和數(shù)字之間有個空格

}

//以上循環(huán)循環(huán)七次,以保證能出現(xiàn)7個隨機(jī)數(shù)

}

tf.setText(s); //將產(chǎn)生的隨機(jī)數(shù)全部顯示在文本域上,用文本域?qū)ο髏f調(diào)用它的設(shè)置文本的方法setText(String)實現(xiàn)。

}

//以下為線程延遲

try{

Thread.sleep(10); //線程類同步方法sleep,睡眠方法,括號里的單位為ms。

}catch(java.lang.InterruptedException e){

e.printStackTrace(); //異常捕獲,不用多說。

}

}

}

//以下是上面設(shè)置的事件監(jiān)聽的具體處理辦法,即監(jiān)聽時間處理方法,自動調(diào)用

public void actionPerformed(ActionEvent e){ //傳入一個動作事件的參數(shù)e

String s = e.getActionCommand(); //設(shè)置字符串s來存儲獲得動作監(jiān)聽,上面的start

/*

以下這個條件語句塊的作用為:用戶點擊開始后(捕獲start,用方法getActionCommand()),將命令觸發(fā)設(shè)置為true,從而執(zhí)行上面的go方法中的循環(huán)體(因為循環(huán)體中要求isGo參數(shù)為true,而初始為false)。

執(zhí)行循環(huán)快產(chǎn)生隨機(jī)數(shù),并將開始按鈕不可編輯化,而用戶只可以使用停止按鈕去停止。如果用戶按下停止時,也就是沒有傳入?yún)?shù)“start”的時候,

執(zhí)行else語句塊中的語句,isGo設(shè)置為false,將不執(zhí)行上面go中的循環(huán)語句塊,從而停止產(chǎn)生隨機(jī)數(shù),并顯示,并且把開始按鈕設(shè)置為可用,而把

停止按鈕設(shè)置為不可用,等待用戶按下開始再去開始新一輪循環(huán)產(chǎn)生隨機(jī)數(shù)。

*/

if(s.equals("start")){ //如果捕獲到start,也就是用戶觸發(fā)了動作監(jiān)聽器,那么下面處理

isGo = true; //設(shè)置isGo為true

b1.setEnabled(false); //將開始按鈕設(shè)置為不可用

b2.setEnabled(true); //將停止按鈕設(shè)置為可用

}else{

isGo = false; //將isGo設(shè)置為false,isGo為循環(huán)標(biāo)志位

b2.setEnabled(false); //設(shè)置停止按鈕為不可用(注意看是b2,b2是停止按鈕)

b1.setEnabled(true); //設(shè)置開始按鈕為可用

}

}

public static void main(String[] args){

new GoodLucky(); //產(chǎn)生類的實例,執(zhí)行方法

}

}

本文標(biāo)題:java基礎(chǔ)入門源代碼,java基礎(chǔ)編程
鏈接分享:http://chinadenli.net/article42/heeohc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)建站、App設(shè)計關(guān)鍵詞優(yōu)化、外貿(mào)網(wǎng)站建設(shè)、移動網(wǎng)站建設(shè)、面包屑導(dǎo)航

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)