java 線程 靜態鎖,對象鎖, synchronized 是鎖方法還是鎖對象?還是鎖類?如何實現?? 部分代碼如下, public static Object lock=new Object() //靜態鎖,鎖類,不是鎖對象了!!所以兩個線程同時 運行兩個 TestThread 的execute( ),也可以同步!??! public void execute(){ // synchronized(lock){ for(int i=0 i<20 i++){ try { Thread.sleep(30) } catch (InterruptedException e) { // todo Auto-generated catch block e.printStackTrace() } System.out.println(Thread.currentThread().getName()+Thread.currentThread ().getName()+" "+i) } } }
上傳時間: 2017-07-15
上傳用戶:lijianyu172
// 學生管理.cpp : Defines the entry point for the application. // #include "stdafx.h" #include "resource.h" #define MAX_LOADSTRING 100 // Global Variables: HINSTANCE hInst; // current instance TCHAR szTitle[MAX_LOADSTRING]; // The title bar text TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text // Foward declarations of functions included in this code module: ATOM MyRegisterClass(HINSTANCE hInstance); BOOL InitInstance(HINSTANCE, int); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM); struct person { char name[10]; int ID; int cj_yw; int cj_sx; struct person* next; struct person* pro; }per; int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // todo: Place code here. MSG msg; HACCEL hAccelTable; // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_MY, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // Perform application initialization: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_MY); // Main message loop: while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return msg.wParam; } // // FUNCTION: MyRegisterClass() // // PURPOSE: Registers the window class. // // COMMENTS: // // This function and its usage is only necessary if you want this code // to be compatible with Win32 systems prior to the 'RegisterClassEx' // function that was added to Windows 95. It is important to call this function // so that the application will get 'well formed' small icons associated // with it. // ATOM MyRegisterClass(HINSTANCE hInstance) { WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = (WNDPROC)WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_MY); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = (LPCSTR)IDC_MY; wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL); return RegisterClassEx(&wcex); } // // FUNCTION: InitInstance(HANDLE, int) // // PURPOSE: Saves instance handle and creates main window // // COMMENTS: // // In this function, we save the instance handle in a global variable and // create and display the main program window. // BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { HWND hWnd; hInst = hInstance; // Store instance handle in our global variable hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if (!hWnd) { return FALSE; } ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE; } // // FUNCTION: WndProc(HWND, unsigned, WORD, LONG) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; TCHAR szHello[MAX_LOADSTRING]; LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING); switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // todo: Add any drawing code here... RECT rt; GetClientRect(hWnd, &rt); DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER); EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } // Mesage handler for about box. LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: return TRUE; case WM_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { EndDialog(hDlg, LOWORD(wParam)); return TRUE; } break; } return FALSE; }
上傳時間: 2016-12-29
上傳用戶:767483511
// 學生管理.cpp : Defines the entry point for the application. // #include "stdafx.h" #include "resource.h" #define MAX_LOADSTRING 100 // Global Variables: HINSTANCE hInst; // current instance TCHAR szTitle[MAX_LOADSTRING]; // The title bar text TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text // Foward declarations of functions included in this code module: ATOM MyRegisterClass(HINSTANCE hInstance); BOOL InitInstance(HINSTANCE, int); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM); struct person { char name[10]; int ID; int cj_yw; int cj_sx; struct person* next; struct person* pro; }per; int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // todo: Place code here. MSG msg; HACCEL hAccelTable; // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_MY, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // Perform application initialization: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_MY); // Main message loop: while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return msg.wParam; } // // FUNCTION: MyRegisterClass() // // PURPOSE: Registers the window class. // // COMMENTS: // // This function and its usage is only necessary if you want this code // to be compatible with Win32 systems prior to the 'RegisterClassEx' // function that was added to Windows 95. It is important to call this function // so that the application will get 'well formed' small icons associated // with it. // ATOM MyRegisterClass(HINSTANCE hInstance) { WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = (WNDPROC)WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_MY); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = (LPCSTR)IDC_MY; wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL); return RegisterClassEx(&wcex); } // // FUNCTION: InitInstance(HANDLE, int) // // PURPOSE: Saves instance handle and creates main window // // COMMENTS: // // In this function, we save the instance handle in a global variable and // create and display the main program window. // BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { HWND hWnd; hInst = hInstance; // Store instance handle in our global variable hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if (!hWnd) { return FALSE; } ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE; } // // FUNCTION: WndProc(HWND, unsigned, WORD, LONG) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; TCHAR szHello[MAX_LOADSTRING]; LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING); switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // todo: Add any drawing code here... RECT rt; GetClientRect(hWnd, &rt); DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER); EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } // Mesage handler for about box. LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: return TRUE; case WM_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { EndDialog(hDlg, LOWORD(wParam)); return TRUE; } break; } return FALSE; }
標簽: 學生 計算器
上傳時間: 2016-12-29
上傳用戶:767483511
/*import java.util.Scanner; //主類 public class student122 { //主方法 public static void main(String[] args){ //定義7個元素的字符數組 String[] st = new String[7]; inputSt(st); //調用輸入方法 calculateSt(st); //調用計算方法 outputSt(st); //調用輸出方法 } //其他方法 //輸入方法 private static void inputSt(String st[]){ System.out.println("輸入學生的信息:"); System.out.println("學號 姓名 成績1,2,3"); //創建鍵盤輸入類 Scanner ss = new Scanner(System.in); for(int i=0; i<5; i++){ st[i] = ss.next(); //鍵盤輸入1個字符串 } } //計算方法 private static void calculateSt(String[] st){ int sum = 0; //總分賦初值 int ave = 0; //平均分賦初值 for(int i=2;i<5;i++) { /計總分,字符變換成整數后進行計算 sum += Integer.parseInt(st[i]); } ave = sum/3; //計算平均分 //整數變換成字符后保存到數組里 st[5] = String.valueOf(sum); st[6] = String.valueOf(ave); } //輸出方法 private static void outputSt(String[] st){ System.out.print("學號 姓名 "); //不換行 System.out.print("成績1 成績2 成績3 "); System.out.println("總分 平均分");//換行 //輸出學生信息 for(int i=0; i<7; i++){ //按格式輸出,小于6個字符,補充空格 System.out.printf("%6s", st[i]); } System.out.println(); //輸出換行 } }*/ import java.util.Scanner; public class student122 { public static void main(String[] args) { // todo 自動生成的方法存根 String[][] st = new String[3][8]; inputSt(st); calculateSt(st); outputSt(st); } //輸入方法 private static void inputSt(String st[][]) { System.out.println("輸入學生信息:"); System.out.println("班級 學號 姓名 成績:數學 物理 化學"); //創建鍵盤輸入類 Scanner ss = new Scanner(System.in); for(int j = 0; j < 3; j++) { for(int i = 0; i < 6; i++) { st[j][i] = ss.next(); } } } //輸出方法 private static void outputSt(String st[][]) { System.out.println("序號 班級 學號 姓名 成績:數學 物理 化學 總分 平均分"); //輸出學生信息 for(int j = 0; j < 3; j++) { System.out.print(j+1 + ":"); for(int i = 0; i < 8; i++) { System.out.printf("%6s", st[j][i]); } System.out.println(); } } //計算方法 private static void calculateSt(String[][] st) { int sum1 = 0; int sum2 = 0; int sum3 = 0; int ave1 = 0; int ave2 = 0; int ave3 = 0; for(int i = 3; i < 6; i++) { sum1 += Integer.parseInt(st[0][i]); } ave1 = sum1/3; for(int i = 3; i < 6; i++) { sum2 += Integer.parseInt(st[1][i]); } ave2 = sum2/3; for(int i = 3; i < 6; i++) { sum3 += Integer.parseInt(st[2][i]); } ave3 = sum3/3; st[0][6] = String.valueOf(sum1); st[1][6] = String.valueOf(sum2); st[2][6] = String.valueOf(sum3); st[0][7] = String.valueOf(ave1); st[1][7] = String.valueOf(ave2); st[2][7] = String.valueOf(ave3); } }
上傳時間: 2017-03-17
上傳用戶:simple
1.安裝好VS2010,網上很多人說使用VC6.0的mscomm32.ocx控件,下載并注冊,注冊過程看上去還很復雜。我是使用VS2010自帶的控件,因此沒有這些過程,只需要安裝好V52010就行了。2.建立“基于對話框”的MFC工程,命名為CommTest,應用程序類型選擇“基于對話框”3.刪除默認的“確定”,“取消”按鈕和靜態文本框“todo在此放置對話框控件”,添加如下對話框控件:①“打開串口”按鈕,添加方法為從右側“工具箱”拖放一個“Button”到對話框,并在右側“屬性”卡中修改“Caption”為“打開串口”,修改“I0”為“IDC_BUTTON_OPEN”。②“關閉串口”按鈕,添加方法為從右側“工具箱”拖放一個“Button”到對話框,并在右側“屬性”卡中修改“Caption”為“關閉串口”,修改“ID”為“IDC_BUTTON_CLOSE”。③“發送”按鈕,添加方法為從右側“工具箱”拖放一個“Button”到對話框,并在右側“屬性”卡中修改“Caption”為“發送”,修改“ID”為“IDC_BUTTON_SEND”。④“發送編輯框”。⑤“接受編輯框”
上傳時間: 2022-06-30
上傳用戶:shjgzh
AppleMusic - B站首頁界面設計:附詳細教程 - cnode社區版 - dribbble - FlexLayout布局 - gank - HIapp - IT-EBOOK - leantodu - LOL戰績查詢 - movecss效果 - Railay:整體框架 - redux綁定 - TCP,IP長連接 - todo list - v2ex - 一個(仿) - 一元奪寶主頁設計 - 萬年歷 - 下拉刷新,tab切換 - 東航訂機票 - 事項助手 - 二維碼生成器 - 云筆記 - 五十音圖 - 五險一金計算 - 人臉檢測 - 今日頭條 - 仿微信DEMO - 仿找事吧 - 仿網易云音樂 - 會議精靈 - 你畫我猜 - 側滑布局 - 健康菜譜 - 全屏動畫滾動 - 內容說明.txt 527B 分答小程序 - 創客+實現大量功能,推薦研究 - 剪刀石頭布 - 醫藥網 - 卡卡汽車 獲取用戶 設備信息 - 同樂居商城:購物車合算 - 商城 - 圖書管理系統 - 圖文信息;歡迎頁面,音樂控制 - 圖片自適應 ,富文本解析 - 圓形菜單 - 城市切換 - 備忘錄 - 外賣:實現類似錨點功能 - 大轉盤 - 天氣預報 - 媽媽課堂 - 家居電商 - 富文本解析,折線圖,MD5,bluebird - 小游戲-別踩白塊 - 小熊的日記 - 小程序地圖定位 - 小程序完整demo:飛翔的小鳥:canvas實現,java后端(適用1221) - 小程序官方Demo - 小程序版2048 - 小程序統計[只需一行代碼].url 132B 小程序頁面生成器 - 康愛多微商城:學習界面設計 - 微票 - 我廚 tab 界面設計 - 手勢解鎖 - 掘金首頁信息流 - 搖一搖換文章 - 教務系統 - 新浪讀書 - 新聞客戶端 - 易打卡 表單設計 - 星巴克中國 - 智能機器人 - 機器人兔兔 - 極客學院 - 果庫 - 查拼音 - 校內新聞大圖 - 框架 - 步步高字典 - 水滸傳 - 治療師 - 涂鴉 - 滑動選項卡 - 滴滴公交-查公交 - 瀑布流布局 - 用戶反饋組件 - 電商-拼團 倒計時 - 電影推薦 - 電影日歷 - 畫布:時鐘 - 番茄時鐘 - 百度小說 - 相冊;處理用戶信息 - 省市選擇控件 - 知乎 - 知乎日報 - 知乎日報1 - 科學計算器 - 移動小商城:基于node,包含前后臺 - 移動端商城 - 簡易計算器 - 網易云課堂 - 騰訊云小程序一站式解決方案 - 自定義tabbar - 芒果TV - 語音跟讀 - 豆瓣圖書 - 豆瓣電影 - 貨幣匯率 - 購物車 - 跑步 地理位置 計時器 - 身份證查詢 - 車源寶 - 輪播圖+菜單 - 輪播圖變換 - 辯論倒計時 - 重郵 - 題庫:選擇選項,切換至下一題 - 首字母排序選擇 - 高仿蘋果計算器
上傳時間: 2013-06-12
上傳用戶:eeworm