Java共享代碼 java代碼分享

Java里如何做到一個(gè)變量成為共享數(shù)據(jù)

可以通過(guò)這個(gè)類的全局變量和定義一個(gè)減法的方法來(lái)實(shí)現(xiàn)呀.

成都創(chuàng)新互聯(lián)堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的銀州網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!

按你說(shuō)的例子我們可以這么寫

首先,定義一個(gè)要被共享變量的類:

public?class?Share?{

static?int?a?=?100;//?定義一個(gè)值為100的靜態(tài)全局變量

public?static?void?minus(int?value){//定義一個(gè)靜態(tài)方法

a?=?a?-value;

}

}

創(chuàng)建一個(gè)測(cè)試類

public?class?Test?{

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

Share.minus(10);?//比如我們要給上面的a變量減10

System.out.println(Share.a);//輸出之前定義的變量的結(jié)果為:90

}

}

JAVA中怎么讓兩個(gè)類共享數(shù)據(jù)?

你可以這樣,在A類中定義一個(gè)C類的引用:\x0d\x0aClass A{\x0d\x0a private C c = null;\x0d\x0a public C getC(){\x0d\x0a return this.c;\x0d\x0a }\x0d\x0a public void setC(C cc){\x0d\x0a this.c = cc;\x0d\x0a }\x0d\x0a}\x0d\x0a然后A a = new A();\x0d\x0aa.getC();就可以得到C類的實(shí)例了。

java中Thread類與Runnable接口實(shí)現(xiàn)資源共享的疑問(wèn)

public

class

ThreadNotShare

extends

Thread{

private

int

share

=

5;

public

void

run(){

for(int

i

=

;

i

50

;

i++)

if(this.share

0){

System.out.println("shar

=

"

+

this.share--);

}

}

public

static

void

main(String

args[])

{

ThreadNotShare

t1

=

new

ThreadNotShare();

ThreadNotShare

t2

=

new

ThreadNotShare();

ThreadNotShare

t3

=

new

ThreadNotShare();

t1.start();

t2.start();

t3.start();

}

}

上面是一個(gè)繼承Thread之后,因?yàn)橛梢粋€(gè)線程類分別構(gòu)造了3個(gè)對(duì)象,所以各自有各自的數(shù)據(jù),對(duì)象之間是數(shù)據(jù)不共享的

至于樓主的問(wèn)題

例二表面看是繼承了一個(gè)Thread類,但是調(diào)用的方法依舊是把一個(gè)線程類的對(duì)象交給Thread去構(gòu)造,和實(shí)現(xiàn)Runnable接口在本質(zhì)上沒(méi)有任何區(qū)別不是嗎,都是由一個(gè)對(duì)象構(gòu)造出的線程,當(dāng)然是共享同一份數(shù)據(jù)了

在Java中,庫(kù)代碼共享是什么意思?有什么含義?

庫(kù)代碼共享就是將多個(gè)開發(fā)人員的代碼集合使用,及時(shí)更新。比如A人員負(fù)責(zé)登陸模塊,B負(fù)責(zé)驗(yàn)證碼模塊,庫(kù)代碼共享可以將A和B所做的模塊進(jìn)行整合。同時(shí)又可以分工合作

求Java做的共享畫板代碼

function table1(stat_array,table_left,table_top,all_width,all_height,table_title,X_unit,Y_unit)

dim bg_color(10)

bg_color(1)="#ff1919"

bg_color(2)="#ffff19"

bg_color(3)="#1919ff"

bg_color(4)="#19ff19"

bg_color(5)="#fc0"

bg_color(6)="#3cc"

bg_color(7)="#ff19ff"

bg_color(8)="#993300"

bg_color(9)="#f60"

bg_color(10)="#ff8c19"

if X_unit "" then

X_unit = X_unit

end if

if Y_unit "" then

Y_unit = Y_unit

end if

num1 = ubound(stat_array,1)

line_temp=split(stat_array(0,1),",")

num2 = ubound(line_temp,1)+1

dim line_code

redim line_code(num1,num2)

for j=1 to num2

line_code(0,j) = line_temp(j-1)

next

for i=1 to num1

line_temp = split(stat_array(i,1),",")

line_code(i,0) = stat_array(i,2)

for j=1 to num2

line_code(i,j) = cdbl(line_temp(j-1))

next

next

value_Max=0

for i=1 to num1

for j=1 to num2

if value_Maxline_code(i,j) then value_Max=line_code(i,j)

next

next

value_Max = cint(value_Max)

value_Max_str =cstr(value_Max)

if value_Max9 then

temp=mid(value_Max_str,2,1)

if temp4 then

temp2=(int(value_Max/(10^(len(value_Max_str)-1)))+1)*10^(len(value_Max_str)-1)

else

temp2=(int(value_Max/(10^(len(value_Max_str)-1)))+0.5)*10^(len(value_Max_str)-1)

end if

else

if value_Max4 then temp2=10 else temp2=5

end if

item_hight = temp2/5

item_width = 20000/(num2-1)

response.Write "v:rect id='background' style='position:absolute;left:"table_left"px;top:"table_top"px;WIDTH:"all_width"px;HEIGHT:"all_height"px;' fillcolor='#EFEFEF' strokecolor='gray'"

response.Write " v:shadow on='t' type='single' color='silver' offset='4pt,4pt'/"

response.Write "/v:rect"

response.Write "v:group ID='table' style='position:absolute;left:"table_left"px;top:"table_top"px;WIDTH:"all_width"px;HEIGHT:"all_height"px;' coordsize = '27500,12800'"

response.Write " v:Rect style='position:relative;left:1500;top:200;width:23000;height:800'filled='false' stroked='f'"

response.Write " v:TextBox inset='0pt,0pt,0pt,0pt'"

response.Write " table width='100%' border='0' align='center' cellspacing='0'"

response.Write " tr"

response.Write " td align='center' valign='middle'div style='font-size:15pt; font-family:黑體;'B"table_title"/B/div/td"

response.Write " /tr"

response.Write " /table"

response.Write " /v:TextBox"

response.Write " /v:Rect "

response.Write " v:rect id='back' style='position:relative;left:1700;top:1200;width:20500; height:10500;' fillcolor='#9cf' strokecolor='#DFDFDF'"

response.Write " v:fill rotate='t' angle='-45' focus='100%' type='gradient'/"

response.Write " /v:rect"

response.Write " v:rect id='back2' style='position:relative;left:23000;top:1200;width:4000; height:"(10500)";' fillcolor='#9cf' stroked='t' strokecolor='#0099ff'"

response.Write " v:fill rotate='t' angle='-175' focus='100%' type='gradient'/"

response.Write " v:shadow on='t' type='single' color='silver' offset='3pt,3pt'/"

response.Write " /v:rect"

for i=1 to num1

if i=1 then

displaystr=""

else

displaystr="none"

end if

response.Write " div style='cursor:hand;' onmouseover='moveon(rec"i",line_"i")' onmouseout='moveout(rec"i",line_"i","i")' onclick='clickit("i")'"

response.Write " v:Rect id='rec"i"' style='position:relative;left:23100;top:"(i-1)*10200/10+1450";width:3800;height:800;display:"displaystr";' fillcolor='#efefef' strokecolor='"bg_color(i)"'"

response.Write " v:fill opacity='.6' color2='fill darken(118)' o:opacity2='.6' rotate='t' method='linear sigma' focus='100%' type='gradient'/"

response.Write " /v:Rect"

response.Write " v:Rect style='position:relative;left:23200;top:"(i-1)*10200/10+1500";width:600;height:700' fillcolor='"bg_color(i)"' stroked='f'/"

response.Write " v:Rect style='position:relative;left:24000;top:"(i-1)*10200/10+1500";width:3400;height:700' filled='f' stroked='f'"

response.Write " v:TextBox inset='0pt,4pt,0pt,0pt' style='font-size:9pt;'div align='left'"stat_array(i,2)"/div/v:TextBox"

response.Write " /v:Rect "

response.Write " /div "

next

response.Write " v:line ID='X' from='1700,11700' to='22700,11700' style='z-index:2' strokecolor='#000000' strokeWeight=1ptv:stroke EndArrow='Classic'//v:line"

response.Write " v:line ID='Y' from='1700,900' to='1700,11700' style='z-index:2' strokecolor='#000000' strokeWeight=1ptv:stroke StartArrow='Classic'//v:line"

response.Write " v:Rect style='position:relative;left:100;top:700;width:1500;height:500' filled='false' stroked='false'"

response.Write " v:TextBox inset='0pt,0pt,0pt,0pt' style='font-size:9pt;'div align='right'"Y_unit"/div/v:TextBox"

response.Write " /v:Rect "

response.Write " v:Rect style='position:relative;left:22200;top:11900;width:2000;height:500' filled='false' stroked='false'"

response.Write " v:TextBox inset='0pt,0pt,0pt,0pt' style='font-size:9pt;'div align='left'"X_unit"/div/v:TextBox"

response.Write " /v:Rect "

for i=0 to 4

response.Write " v:line from='1300,"i*2000+1700"' to='1700,"i*2000+1700"' style='z-index:2' strokecolor='#000000'/v:line"

response.Write " v:line from='1700,"i*2000+1700"' to='2200,"i*2000+1200"' style='z-index:2' strokecolor='#0099FF'/v:line"

response.Write " v:line from='2200,"i*2000+1200"' to='22200,"i*2000+1200"' style='z-index:2' strokecolor='#0099FF'/v:line"

response.Write " v:line from='2200,"i*2000+2200"' to='22200,"i*2000+2200"' style='z-index:2' strokecolor='#0099FF'"

response.Write " v:stroke dashstyle='Dot'/"

response.Write " /v:line"

response.Write " v:Rect style='position:relative;left:100;top:"i*2000+1250";width:1500;height:500' filled='false' stroked='false'"

response.Write " v:TextBox inset='0pt,0pt,0pt,0pt' style='font-size:9pt;'div align='right'"item_hight*(5-i)"/div/v:TextBox"

response.Write " /v:Rect "

next

response.Write " v:line from='2200,11200' to='22200,11200' style='z-index:2' strokecolor='#0099FF'/v:line"

response.Write " v:line from='2200,1200' to='2200,11200' style='z-index:2' strokecolor='#0099FF'/v:line"

response.Write " v:line from='1700,11700' to='2200,11200' style='z-index:2' strokecolor='#0099FF'/v:line"

for j=0 to num2-1

response.Write " v:line from='"j*item_width+1700",11700' to='"j*item_width+1700",12000' style='z-index:2' strokecolor='#000000'/v:line"

response.Write " v:line from='"j*item_width+1700",11700' to='"j*item_width+2200",11200' style='z-index:2' strokecolor='#0099FF'v:stroke dashstyle='ShortDot'//v:line"

response.Write " v:line from='"j*item_width+2200",1200' to='"j*item_width+2200",11200' style='z-index:2' strokecolor='#0099FF'v:stroke dashstyle='ShortDot'//v:line"

response.Write " v:Rect style='position:relative;left:"j*item_width+1700-item_width/2";top:12100;width:"item_width";height:500' filled='false' stroked='false'"

response.Write " v:TextBox inset='0pt,0pt,0pt,0pt' style='font-size:9pt;'div align='center'"line_code(0,j+1)"/div/v:TextBox"

response.Write " /v:Rect "

next

for i=1 to num1

if i=1 then

displaystr=""

else

displaystr="none"

end if

response.Write " div id='line_"i"' style='display:"displaystr";'"

for j=0 to num2-2

this_hight1 = cint(line_code(i,j+1)/(5*item_hight)*10000)

this_hight2 = cint(line_code(i,j+2)/(5*item_hight)*10000)

response.Write " v:line from='"j*item_width+1850","(10000-this_hight1+1550)"' to='"(j+1)*item_width+1850","(10000-this_hight2+1550)"'style='z-index:"i*10";' strokeweight='0.1pt' strokecolor='"bg_color(i)"'"

response.Write " o:extrusion v:ext='view' backdepth='12pt' on='t' lightposition='-50000,-50000' lightposition2='50000'/"

response.Write " /v:line"

next

response.Write " /div"

next

response.Write "/v:group"

end function

%

html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"

meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /

head

title/title

STYLE

v\:* { Behavior: url(#default#VML) }

o\:* { behavior: url(#default#VML) }

/STYLE

SCRIPT LANGUAGE="JavaScript"

!--

var showit = new Array(10);

function moveon(iteam,lineit){

temp=eval(iteam)

templine=eval(lineit)

if(showit[1]){

rec1.style.display = "";

line_1.style.display = "";

}else{

rec1.style.display = "none";

line_1.style.display = "none";

}

temp.style.display = "";

templine.style.display = "";

}

function moveout(iteam,lineit,i){

temp=eval(iteam)

templine=eval(lineit)

if (showit[i]){

temp.style.display = "";

templine.style.display = "";

}else{

temp.style.display = "none";

templine.style.display = "none";

}

}

function clickit(i){

if (showit[i]){

showit[i]=false

}else{

showit[i]=true

}

}

--

/script

/head

body

%

dim total(10,2)

total(0,1)="1月,2月,3月,4月,5月,6月,7月,8月,9月,10月,11月,12月"

total(1,1)="200,158,982,0,369,100,595,895,652,25,245,951"

total(2,1)="984,58,495,36,158,486,952,258,653,415,485,14"

total(3,1)="850,988,958,145,369,745,265,158,856,145,425,352"

total(4,1)="600,525,235,485,258,265,158,365,35,148,658,475"

total(5,1)="62,525,635,215,0,465,258,305,66,547,54,148"

total(6,1)="560,625,645,329,158,665,358,95,120,358,42,253"

total(7,1)="950,725,635,435,258,865,458,955,152,845,425,421"

total(8,1)="600,825,155,455,458,265,558,365,352,245,853,122"

total(9,1)="360,925,215,545,658,465,658,845,400,421,541,125"

total(10,1)="50,225,355,655,858,665,758,35,584,214,54,651"

total(1,2)="項(xiàng)目1"

total(2,2)="項(xiàng)目2"

total(3,2)="項(xiàng)目3"

total(4,2)="項(xiàng)目4"

total(5,2)="項(xiàng)目5"

total(6,2)="項(xiàng)目6"

total(7,2)="項(xiàng)目7"

total(8,2)="項(xiàng)目8"

total(9,2)="項(xiàng)目9"

total(10,2)="項(xiàng)目10"

call table1(total,50,50,700,350,"曲 線 統(tǒng) 計(jì) 圖","時(shí)間","元")

%

/body

/html

Java如何在幾個(gè)Java文件中共享數(shù)據(jù)

java實(shí)現(xiàn)共享數(shù)據(jù)可以將這些要共享的數(shù)據(jù)封裝到一個(gè)類里并且用靜態(tài)static修飾,當(dāng)其他類要使用這些變量時(shí),只需用這個(gè)類的類名.變量名即可。

事例代碼如下:

變量類:

public class Demo1 {

public static int a = 1;

public static int b = 2;

public static int c = 3;

}

使用變量的類:

public class Demo2 {

public static void main(String[] args) {

System.out.println(Demo1.a);

System.out.println(Demo1.b);

System.out.println(Demo1.c);

}

}

這里使用static的好處是變量經(jīng)過(guò)static的修飾,在使用這些變量時(shí)不用再創(chuàng)建這個(gè)類出來(lái),只需使用類名.變量名即可使用,節(jié)省了空間;還有需要注意的是變量名需要用public來(lái)修飾,保證再不同包下的類也能使用該類下的變量。

分享題目:Java共享代碼 java代碼分享
分享地址:http://m.kartarina.com/article32/hgghpc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)建站網(wǎng)站排名虛擬主機(jī)微信公眾號(hào)做網(wǎng)站

廣告

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

搜索引擎優(yōu)化
主站蜘蛛池模板: 亚洲中文字幕无码久久综合网| 亚洲?V无码乱码国产精品 | 亚洲av成人中文无码专区| 亚洲AV无码一区二区三区系列| 亚洲AV综合色区无码二区爱AV| 免费a级毛片无码av| 日韩人妻精品无码一区二区三区| 亚洲av无码成人精品国产| 熟妇人妻系列av无码一区二区| 中日韩精品无码一区二区三区| 中文无码日韩欧免费视频| 伊人久久一区二区三区无码| 久久精品岛国av一区二区无码| 黑人巨大无码中文字幕无码| 午夜不卡久久精品无码免费| 久久久久成人精品无码| 亚洲AV无码一区二区三区久久精品| 国产成人无码综合亚洲日韩 | 亚洲AV无码久久久久网站蜜桃 | 无码精品人妻一区二区三区中| 免费无码午夜福利片| 中文字幕无码不卡一区二区三区| 黑人无码精品又粗又大又长| 在线精品自偷自拍无码中文| 久久久无码精品国产一区| 嫩草影院无码av| 国产成人无码av在线播放不卡| 日韩人妻无码精品久久免费一| 亚洲AV无码久久精品成人| 亚洲一区二区三区AV无码| 丰满日韩放荡少妇无码视频| 久久无码一区二区三区少妇| 免费无码又爽又刺激高潮的视频| 亚洲人成无码网站在线观看 | 国产精品亚洲专区无码WEB | 毛片亚洲AV无码精品国产午夜 | 免费VA在线观看无码| 免费人成无码大片在线观看 | 亚洲真人无码永久在线| 国产午夜无码片免费| 国产成人亚洲综合无码|