以太坊java源代碼
『壹』 求編寫一個超級簡單的Java的程序源代碼
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class Login {
public static void main(String args[]) {
LoginFrm frame = new LoginFrm();
}
}
class LoginFrm extends JFrame implements ActionListener{
JLabel nameLabel=new JLabel("用戶名:");
JLabel pwdLabel=new JLabel("密碼:");
JTextField name=new JTextField(10);
JPasswordField password=new JPasswordField(10);
JButton butnSure=new JButton("確定");
JButton butnCancel=new JButton("取消");
public LoginFrm() {
super("登陸");
setBounds(500, 200, 280, 220);
setVisible(true);
setLayout(null);
nameLabel.setBounds(45, 20, 100, 25);
add(nameLabel);
add(name);
name.setBounds(105, 20, 110, 25);
add(pwdLabel);
pwdLabel.setBounds(45, 60, 100, 25);
add(password);
password.setBounds(105, 60, 110, 25);
add(butnSure);
butnSure.setBounds(45, 100, 80, 25);
add(butnCancel);
butnCancel.setBounds(135, 100, 80, 25);
butnSure.addActionListener(this);
butnCancel.addActionListener(this);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
validate();//刷新
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() ==butnSure){
System.out.println("用戶名:"+name.getText());
System.out.println("密碼:"+name.getText());
if("admin".equals(name.getText().trim())&&"123".equals(password.getText().trim())){
this.dispose();
new MainFrm("用戶界面",name.getText().trim(),password.getText().trim());
}else {
JOptionPane.showMessageDialog(this, "用戶不存在");
}
}else if(e.getSource()==butnCancel){
System.exit(1);
}
}
class MainFrm extends JFrame{
private JLabel info;
public MainFrm(String s,String name,String password) {
super(s);
setBounds(400, 200, 500, 400);
setLayout(new FlowLayout());
info=new JLabel("登陸成功,用戶名:"+name+",密碼:"+password);
add(info);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
validate();
}
}
}
『貳』 java開發的網盤源代碼
傻啊,上面那種你也去下載!
『叄』 誰能給我個java源代碼
import javax.swing.*;
import java.awt.*;
import javax.swing.border.LineBorder;
import java.awt.event.*;public class TicTacToe extends JApplet
{
private char whoseTurn='X';
private Cell[][] cell=new Cell[3][3];
private JLabel jlblStatus=new JLabel("X's turn to play");
public void init()
{
JPanel p=new JPanel();
p.setLayout(new GridLayout(3,3,0,0));
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
p.add(cell[i][j]=new Cell()); p.setBorder(new LineBorder(Color.red,1));
jlblStatus.setBorder(new LineBorder(Color.yellow,1));
this.getContentPane().add(p,BorderLayout.CENTER);
this.getContentPane().add(jlblStatus,BorderLayout.SOUTH);
}
public void start()
{}
public static void main(String[] args)
{
JFrame frame=new JFrame("TicTacToe");
TicTacToe applet=new TicTacToe();
frame.getContentPane().add(applet,BorderLayout.CENTER);
applet.init();
applet.start();
//Center the window
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.setLocation(
(screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2); frame.setSize(300,300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public boolean isFull()
{
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
if(cell[i][j].getToken()==' ')
return false;
return true;
}
public boolean isWin(char token)
{
for(int i=0;i<3;i++)
if((cell[i][0].getToken()==token)
&&(cell[i][1].getToken()==token)
&&(cell[i][2].getToken()==token))
{
return true;
}
for(int j=0;j<3;j++)
if((cell[0][j].getToken()==token)
&&(cell[1][j].getToken()==token)
&&(cell[2][j].getToken()==token))
{
return true;
}
if((cell[0][0].getToken()==token)
&&(cell[1][1].getToken()==token)
&&(cell[2][2].getToken()==token))
{
return true;
}
if((cell[0][2].getToken()==token)
&&(cell[1][1].getToken()==token)
&&(cell[2][0].getToken()==token))
{
return true;
}
return false;
}
public class Cell extends JPanel implements MouseListener
{
private char token=' ';
public Cell()
{
setBorder(new LineBorder(Color.black,1));
addMouseListener(this);
}
public char getToken()
{
return token;
}
public void setToken(char c)
{
token=c;
repaint();
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
if(token=='X')
{
g.drawLine(10,10,getSize().width-10,getSize().height-10);
g.drawLine(getSize().width-10,10,10,getSize().height-10);
}
else if(token=='O')
{
g.drawOval(10,10,getSize().width-20,getSize().height-20);
}
}
public void mouseClicked(MouseEvent e)
{
if(token==' ')
{
if(whoseTurn=='X')
{
setToken('X');
whoseTurn='O';
jlblStatus.setText("O's turn");
if(isWin('X'))
{
JOptionPane.showMessageDialog(this,"X won! ","提示",
JOptionPane.YES_NO_CANCEL_OPTION);
jlblStatus.setText("X won! The game is over");
}
else if(isFull())
{
JOptionPane.showMessageDialog(this,"The game is over","提示",
JOptionPane.INFORMATION_MESSAGE);
jlblStatus.setText("Draw! The game is over");
}
}
else if(whoseTurn=='O')
{
setToken('O');
whoseTurn='X';
jlblStatus.setText("X's turn");
if(isWin('O'))
{
JOptionPane.showMessageDialog(this, "Y won! ","提示",
JOptionPane.INFORMATION_MESSAGE);
jlblStatus.setText("O won! The game is over");
}
else if(isFull())
{
JOptionPane.showMessageDialog(this,"The game is over","提示",
JOptionPane.INFORMATION_MESSAGE);
jlblStatus.setText("Draw! The game is over");
}
}
}
}
public void mousePressed(MouseEvent e)
{}
public void mouseReleased(MouseEvent e)
{}
public void mouseEntered(MouseEvent e)
{}
public void mouseExited(MouseEvent e)
{}
}
}//一個簡單JAVA #字三關 的游戲代碼
『肆』 求JAVA的一些源代碼
這是一個實體類.
import java.util.Date;
/**
* UserInfo generated by MyEclipse Persistence Tools
*/
public class UserInfo implements java.io.Serializable {
// Fields
private Integer id;
private String name;
private String password;
private String realname;
private String gender;
private String orgDept;
private Integer eDegree;
private Integer country;
private Integer district;
private Integer phone;
private String email;
private String userRight;
private Date registerTime;
private String registerStatus;
private Date admitTime;
private String adminOper;
private Integer loginNum;
private Date loginLasttime;
private String loginLastIp;
// Constructors
/** default constructor */
public UserInfo() {
}
/** minimal constructor */
public UserInfo(String name, String password, String realname,
String orgDept, Integer phone, String email) {
this.name = name;
this.password = password;
this.realname = realname;
this.orgDept = orgDept;
this.phone = phone;
this.email = email;
}
/** full constructor */
public UserInfo(String name, String password, String realname,
String gender, String orgDept, Integer eDegree, Integer country,
Integer district, Integer phone, String email, String userRight,
Date registerTime, String registerStatus, Date admitTime,
String adminOper, Integer loginNum, Date loginLasttime,
String loginLastIp) {
this.name = name;
this.password = password;
this.realname = realname;
this.gender = gender;
this.orgDept = orgDept;
this.eDegree = eDegree;
this.country = country;
this.district = district;
this.phone = phone;
this.email = email;
this.userRight = userRight;
this.registerTime = registerTime;
this.registerStatus = registerStatus;
this.admitTime = admitTime;
this.adminOper = adminOper;
this.loginNum = loginNum;
this.loginLasttime = loginLasttime;
this.loginLastIp = loginLastIp;
}
// Property accessors
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
public String getRealname() {
return this.realname;
}
public void setRealname(String realname) {
this.realname = realname;
}
public String getGender() {
return this.gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getOrgDept() {
return this.orgDept;
}
public void setOrgDept(String orgDept) {
this.orgDept = orgDept;
}
public Integer getEDegree() {
return this.eDegree;
}
public void setEDegree(Integer eDegree) {
this.eDegree = eDegree;
}
public Integer getCountry() {
return this.country;
}
public void setCountry(Integer country) {
this.country = country;
}
public Integer getDistrict() {
return this.district;
}
public void setDistrict(Integer district) {
this.district = district;
}
public Integer getPhone() {
return this.phone;
}
public void setPhone(Integer phone) {
this.phone = phone;
}
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
public String getUserRight() {
return this.userRight;
}
public void setUserRight(String userRight) {
this.userRight = userRight;
}
public Date getRegisterTime() {
return this.registerTime;
}
public void setRegisterTime(Date registerTime) {
this.registerTime = registerTime;
}
public String getRegisterStatus() {
return this.registerStatus;
}
public void setRegisterStatus(String registerStatus) {
this.registerStatus = registerStatus;
}
public Date getAdmitTime() {
return this.admitTime;
}
public void setAdmitTime(Date admitTime) {
this.admitTime = admitTime;
}
public String getAdminOper() {
return this.adminOper;
}
public void setAdminOper(String adminOper) {
this.adminOper = adminOper;
}
public Integer getLoginNum() {
return this.loginNum;
}
public void setLoginNum(Integer loginNum) {
this.loginNum = loginNum;
}
public Date getLoginLasttime() {
return this.loginLasttime;
}
public void setLoginLasttime(Date loginLasttime) {
this.loginLasttime = loginLasttime;
}
public String getLoginLastIp() {
return this.loginLastIp;
}
public void setLoginLastIp(String loginLastIp) {
this.loginLastIp = loginLastIp;
}
}
『伍』 為什麼大多數區塊鏈項目不使用java開發
區塊鏈項目對效率的要求比較高,所以大多數核心源碼的開發都是使用c/c++。但是如果是做都區塊鏈項目,除非要對源代碼進行大量的調整,否則也不見得就不選擇使用java。一般的dapp應用,使用java開發應該也是不錯的選擇。比如以太坊區塊鏈的話,針對java的有web3j的類庫,十分方便;比特幣的話有bitcoinj類庫,也很好用。還是要看還是什麼級別的應用,要做什麼,以及團隊的情況吧。
分享兩個java區塊鏈教程:
java比特幣詳解
java以太坊開發
『陸』 求java案例源代碼 越多越好!
importjava.awt.*;
importjava.awt.event.*;
importjava.lang.*;
importjavax.swing.*;
{
//聲明三個面板的布局
GridLayoutgl1,gl2,gl3;
Panelp0,p1,p2,p3;
JTextFieldtf1;
TextFieldtf2;
Buttonb0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18,b19,b20,b21,b22,b23,b24,b25,b26;
StringBufferstr;//顯示屏所顯示的字元串
doublex,y;//x和y都是運算數
intz;//Z表示單擊了那一個運算符.0表示"+",1表示"-",2表示"*",3表示"/"
staticdoublem;//記憶的數字
publicCounter()
{
gl1=newGridLayout(1,4,10,0);//實例化三個面板的布局
gl2=newGridLayout(4,1,0,15);
gl3=newGridLayout(4,5,10,15);
tf1=newJTextField(27);//顯示屏
tf1.setHorizontalAlignment(JTextField.RIGHT);
tf1.setEnabled(false);
tf1.setText("0");
tf2=newTextField(10);//顯示記憶的索引值
tf2.setEditable(false);
//實例化所有按鈕、設置其前景色並注冊監聽器
b0=newButton("Backspace");
b0.setForeground(Color.red);
b0.addActionListener(newBt());
b1=newButton("CE");
b1.setForeground(Color.red);
b1.addActionListener(newBt());
b2=newButton("C");
b2.setForeground(Color.red);
b2.addActionListener(newBt());
b3=newButton("MC");
b3.setForeground(Color.red);
b3.addActionListener(newBt());
b4=newButton("MR");
b4.setForeground(Color.red);
b4.addActionListener(newBt());
b5=newButton("MS");
b5.setForeground(Color.red);
b5.addActionListener(newBt());
b6=newButton("M+");
b6.setForeground(Color.red);
b6.addActionListener(newBt());
b7=newButton("7");
b7.setForeground(Color.blue);
b7.addActionListener(newBt());
b8=newButton("8");
b8.setForeground(Color.blue);
b8.addActionListener(newBt());
b9=newButton("9");
b9.setForeground(Color.blue);
b9.addActionListener(newBt());
b10=newButton("/");
b10.setForeground(Color.red);
b10.addActionListener(newBt());
b11=newButton("sqrt");
b11.setForeground(Color.blue);
b11.addActionListener(newBt());
b12=newButton("4");
b12.setForeground(Color.blue);
b12.addActionListener(newBt());
b13=newButton("5");
b13.setForeground(Color.blue);
b13.addActionListener(newBt());
b14=newButton("6");
b14.setForeground(Color.blue);
b14.addActionListener(newBt());
b15=newButton("*");
b15.setForeground(Color.red);
b15.addActionListener(newBt());
b16=newButton("%");
b16.setForeground(Color.blue);
b16.addActionListener(newBt());
b17=newButton("1");
b17.setForeground(Color.blue);
b17.addActionListener(newBt());
b18=newButton("2");
b18.setForeground(Color.blue);
b18.addActionListener(newBt());
b19=newButton("3");
b19.setForeground(Color.blue);
b19.addActionListener(newBt());
b20=newButton("-");
b20.setForeground(Color.red);
b20.addActionListener(newBt());
b21=newButton("1/X");
b21.setForeground(Color.blue);
b21.addActionListener(newBt());
b22=newButton("0");
b22.setForeground(Color.blue);
b22.addActionListener(newBt());
b23=newButton("+/-");
b23.setForeground(Color.blue);
b23.addActionListener(newBt());
b24=newButton(".");
b24.setForeground(Color.blue);
b24.addActionListener(newBt());
b25=newButton("+");
b25.setForeground(Color.red);
b25.addActionListener(newBt());
b26=newButton("=");
b26.setForeground(Color.red);
b26.addActionListener(newBt());
//實例化四個面板
p0=newPanel();
p1=newPanel();
p2=newPanel();
p3=newPanel();
//創建一個空字元串緩沖區
str=newStringBuffer();
//添加面板p0中的組件和設置其在框架中的位置和大小
p0.add(tf1);
p0.setBounds(10,25,300,40);
//添加面板p1中的組件和設置其在框架中的位置和大小
p1.setLayout(gl1);
p1.add(tf2);
p1.add(b0);
p1.add(b1);
p1.add(b2);
p1.setBounds(10,65,300,25);
//添加面板p2中的組件並設置其的框架中的位置和大小
p2.setLayout(gl2);
p2.add(b3);
p2.add(b4);
p2.add(b5);
p2.add(b6);
p2.setBounds(10,110,40,150);
//添加面板p3中的組件並設置其在框架中的位置和大小
p3.setLayout(gl3);//設置p3的布局
p3.add(b7);
p3.add(b8);
p3.add(b9);
p3.add(b10);
p3.add(b11);
p3.add(b12);
p3.add(b13);
p3.add(b14);
p3.add(b15);
p3.add(b16);
p3.add(b17);
p3.add(b18);
p3.add(b19);
p3.add(b20);
p3.add(b21);
p3.add(b22);
p3.add(b23);
p3.add(b24);
p3.add(b25);
p3.add(b26);
p3.setBounds(60,110,250,150);
//設置框架中的布局為空布局並添加4個面板
setLayout(null);
add(p0);
add(p1);
add(p2);
add(p3);
setResizable(false);//禁止調整框架的大小
//匿名類關閉窗口
addWindowListener(newWindowAdapter(){
publicvoidwindowClosing(WindowEvente1)
{
System.exit(0);
}
});
setBackground(Color.lightGray);
setBounds(100,100,320,280);
setVisible(true);
}
//構造監聽器
{
publicvoidactionPerformed(ActionEvente2)
{
try{
if(e2.getSource()==b1)//選擇"CE"清零
{
tf1.setText("0");//把顯示屏清零
str.setLength(0);//清空字元串緩沖區以准備接收新的輸入運算數
}
elseif(e2.getSource()==b2)//選擇"C"清零
{
tf1.setText("0");//把顯示屏清零
str.setLength(0);
}
elseif(e2.getSource()==b23)//單擊"+/-"選擇輸入的運算數是正數還是負數
{
x=Double.parseDouble(tf1.getText().trim());
tf1.setText(""+(-x));
}
elseif(e2.getSource()==b25)//單擊加號按鈕獲得x的值和z的值並清空y的值
{
x=Double.parseDouble(tf1.getText().trim());
str.setLength(0);//清空緩沖區以便接收新的另一個運算數
y=0d;
z=0;
}
elseif(e2.getSource()==b20)//單擊減號按鈕獲得x的值和z的值並清空y的值
{
x=Double.parseDouble(tf1.getText().trim());
str.setLength(0);
y=0d;
z=1;
}
elseif(e2.getSource()==b15)//單擊乘號按鈕獲得x的值和z的值並清空y的值
{
x=Double.parseDouble(tf1.getText().trim());
str.setLength(0);
y=0d;
z=2;
}
elseif(e2.getSource()==b10)//單擊除號按鈕獲得x的值和z的值並空y的值
{
x=Double.parseDouble(tf1.getText().trim());
str.setLength(0);
y=0d;
z=3;
}
elseif(e2.getSource()==b26)//單擊等號按鈕輸出計算結果
{
str.setLength(0);
switch(z)
{
case0:tf1.setText(""+(x+y));break;
case1:tf1.setText(""+(x-y));break;
case2:tf1.setText(""+(x*y));break;
case3:tf1.setText(""+(x/y));break;
}
}
elseif(e2.getSource()==b24)//單擊"."按鈕輸入小數
{
if(tf1.getText().trim().indexOf(′.′)!=-1)//判斷字元串中是否已經包含了小數點
{
}
else//如果沒數點有小
{
if(tf1.getText().trim().equals("0"))//如果初時顯示為0
{
str.setLength(0);
tf1.setText((str.append("0"+e2.getActionCommand())).toString());
}
elseif(tf1.getText().trim().equals(""))//如果初時顯示為空則不做任何操作
{
}
else
{
tf1.setText(str.append(e2.getActionCommand()).toString());
}
}
y=0d;
}
elseif(e2.getSource()==b11)//求平方根
{
x=Double.parseDouble(tf1.getText().trim());
tf1.setText("數字格式異常");
if(x<0)
tf1.setText("負數沒有平方根");
else
tf1.setText(""+Math.sqrt(x));
str.setLength(0);
y=0d;
}
elseif(e2.getSource()==b16)//單擊了"%"按鈕
{
x=Double.parseDouble(tf1.getText().trim());
tf1.setText(""+(0.01*x));
str.setLength(0);
y=0d;
}
elseif(e2.getSource()==b21)//單擊了"1/X"按鈕
{
x=Double.parseDouble(tf1.getText().trim());
if(x==0)
{
tf1.setText("除數不能為零");
}
else
{
tf1.setText(""+(1/x));
}
str.setLength(0);
y=0d;
}
elseif(e2.getSource()==b3)//MC為清除內存
{
m=0d;
tf2.setText("");
str.setLength(0);
}
elseif(e2.getSource()==b4)//MR為重新調用存儲的數據
{
if(tf2.getText().trim()!="")//有記憶數字
{
tf1.setText(""+m);
}
}
elseif(e2.getSource()==b5)//MS為存儲顯示的數據
{
m=Double.parseDouble(tf1.getText().trim());
tf2.setText("M");
tf1.setText("0");
str.setLength(0);
}
elseif(e2.getSource()==b6)//M+為將顯示的數字與已經存儲的數據相加要查看新的數字單擊MR
{
m=m+Double.parseDouble(tf1.getText().trim());
}
else//選擇的是其他的按鈕
{
if(e2.getSource()==b22)//如果選擇的是"0"這個數字鍵
{
if(tf1.getText().trim().equals("0"))//如果顯示屏顯示的為零不做操作
{
}
else
{
tf1.setText(str.append(e2.getActionCommand()).toString());
y=Double.parseDouble(tf1.getText().trim());
}
}
elseif(e2.getSource()==b0)//選擇的是「BackSpace」按鈕
{
if(!tf1.getText().trim().equals("0"))//如果顯示屏顯示的不是零
{
if(str.length()!=1)
{
tf1.setText(str.delete(str.length()-1,str.length()).toString());//可能拋出字元串越界異常
}
else
{
tf1.setText("0");
str.setLength(0);
}
}
y=Double.parseDouble(tf1.getText().trim());
}
else//其他的數字鍵
{
tf1.setText(str.append(e2.getActionCommand()).toString());
y=Double.parseDouble(tf1.getText().trim());
}
}
}
catch(NumberFormatExceptione){
tf1.setText("數字格式異常");
}
catch(){
tf1.setText("字元串索引越界");
}
}
}
publicstaticvoidmain(Stringargs[])
{
newCounter();
}
}
『柒』 求java一個簡單點的源代碼,要完整可運行的
商品社會拒絕白乾,第一,沒有人會給你這個程序。第二,就算有人給你,他也不會耐心告訴你怎麼配置,怎麼裝資料庫。怎麼運行。 隨隨便便來這里就想白要,你覺得可能嗎。我說話可能不好聽,但是這是事實。
『捌』 求Java源程序代碼,一整套的就可以,不限制類型
//Threader.java
import java.awt.Graphics;
import java.awt.Color;
public class Threader extends java.awt.Canvas implements Runnable {
int myPosition =0;
String myName;
int numberofSteps=600;
boolean keepRunning = true;
//構造函數
public Threader (String inName){
myName=new String (inName);
}
public synchronized void paint(Graphics g){
//為線程競賽畫一條直線
g.setColor (Color.black);
g.drawLine (0,getSize().height/2,getSize().width,getSize().height/2);
//畫競賽者.
g.setColor (Color.yellow);
g.fillOval((myPosition*getSize().width/numberofSteps),0,15,getSize().height);
}
public void stop(){
keepRunning = false;
}
public void run(){
//循環直到競賽停止
while ((myPosition <numberofSteps)&& keepRunning){
myPosition++;
repaint();
//將當前線程睡眠,畫屏函數工作.
try{
Thread.currentThread().sleep(10);
}catch (Exception e){System.out.println("Exception on sleep");}
}
System.out.println("Threader:"+myName+" has finished the race");
}
}//end class Threader.
//GreatRace.java
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Frame;
public class GreatRace extends java.applet.Applet implements Runnable{
Threader theRacers[];
static int racerCount = 3;
Thread theThreads[];
Thread thisThread;
static boolean inApplet=true;
int numberofThreadsAtStart;
public void init(){
//計算工作線程的個數
numberofThreadsAtStart = Thread.activeCount();
//確定界面的顯示風格
setLayout(new GridLayout(racerCount,1));
//確定競賽者的數量
theRacers = new Threader [racerCount];
theThreads = new Thread[racerCount];
//為每一個競賽者創建一個線程
for (int x=0;x<racerCount;x++){
theRacers[x]=new Threader ("Racer #"+x);
theRacers[x].setSize(getSize().width,getSize().height/racerCount);
add (theRacers[x]);
theThreads[x]=new Thread(theRacers[x]);
}
}
public void start(){
//啟動所有的線程
for (int x=0;x<racerCount;x++)
theThreads[x].start();
//創建一個對照線程
thisThread= new Thread (this);
thisThread.start();
}
public void stop(){
for (int x= 0;x<theRacers.length;x++){
theRacers[x].stop();
}
}
public void run(){
//循環直到結束
while(Thread.activeCount()>numberofThreadsAtStart+2){
try{
thisThread.sleep(100);
} catch (InterruptedException e){
System.out.println("thisThread was interrupted");
}
}
//停止競賽
if (inApplet){
stop();
destroy();
}
else
System.exit(0);
}
public static void main (String argv[]){
inApplet=false;
//監測在線競賽者的數量.
if (argv.length>0)
racerCount = Integer.parseInt(argv[0]);
//創建一個新的界面
Frame theFrame = new Frame("The Great Thread Race");
GreatRace theRace = new GreatRace();
theFrame.setSize(400,200);
theFrame.add ("Center",theRace);
theFrame.show();
theRace.init();
theFrame.pack();
theRace.start();
}
}//end class GreatRace.
『玖』 求JAVA源代碼
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class GradeStatistic {
public static void main(String[] args) {
GradeStatistic gs = new GradeStatistic();
List<Mark> list = new ArrayList<Mark>();
float sum = 0;
while(true){
Scanner sc = new Scanner(System.in);
System.out.print("Please input student name: ");
String name = sc.nextLine();
if(name.equals("end")){
break;
}
System.out.print("Please input student score: ");
float score = sc.nextFloat();
sum += score;
list.add(gs.new Mark(name, score));
}
float max = list.get(0).getScore();
float min = list.get(0).getScore();
for(Mark mark: list){
if(max < mark.getScore()){
max = mark.getScore();
}
if(min > mark.getScore()){
min = mark.getScore();
}
}
float average = sum / list.size();
System.out.println("Average is: " + average);
System.out.println("Max is: " + max);
System.out.println("Min is: " + min);
}
private class Mark{
private String name;
private float score;
public Mark(String name, float score){
this.name = name;
this.score = score;
}
public String getName() {
return name;
}
public float getScore() {
return score;
}
}
}
----------------------
Please input student name: Zhang san
Please input student score: 100
Please input student name: Li Si
Please input student score: 91
Please input student name: Ec
Please input student score: 35
Please input student name: ma qi
Please input student score: 67
Please input student name: end
Average is: 73.25
Max is: 100.0
Min is: 35.0
『拾』 再哪可以看到java開發項目的整個源代碼
打開項目不久看到了嘛
