⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xuesheng.txt

📁 充分体现了学生的诸多功能
💻 TXT
📖 第 1 页 / 共 2 页
字号:
//: c11:ArraySize.java
// Initialization & re-assignment of arrays.
import com.bruceeckel.simpletest.*;

class Weeble {} // A small mythical creature

public class ArraySize {
  private static Test monitor = new Test();
  public static void main(String[] args) {
    // Arrays of objects:
    Weeble[] a; // Local uninitialized variable
    Weeble[] b = new Weeble[5]; // Null references
    Weeble[] c = new Weeble[4];
    for(int i = 0; i < c.length; i++)
      if(c[i] == null) // Can test for null reference
        c[i] = new Weeble();
    // Aggregate initialization:
    Weeble[] d = {
      new Weeble(), new Weeble(), new Weeble()
    };
    // Dynamic aggregate initialization:
    a = new Weeble[] {
      new Weeble(), new Weeble()
    };
    System.out.println("a.length=" + a.length);
    System.out.println("b.length = " + b.length);
    // The references inside the array are
    // automatically initialized to null:
    for(int i = 0; i < b.length; i++)
      System.out.println("b[" + i + "]=" + b[i]);
    System.out.println("c.length = " + c.length);
    System.out.println("d.length = " + d.length);
    a = d;
    System.out.println("a.length = " + a.length);

    // Arrays of primitives:
    int[] e; // Null reference
    int[] f = new int[5];
    int[] g = new int[4];
    for(int i = 0; i < g.length; i++)
      g[i] = i*i;
    int[] h = { 11, 47, 93 };
    // Compile error: variable e not initialized:
    //!System.out.println("e.length=" + e.length);
    System.out.println("f.length = " + f.length);
    // The primitives inside the array are
    // automatically initialized to zero:
    for(int i = 0; i < f.length; i++)
      System.out.println("f[" + i + "]=" + f[i]);
    System.out.println("g.length = " + g.length);
    System.out.println("h.length = " + h.length);
    e = h;
    System.out.println("e.length = " + e.length);
    e = new int[] { 1, 2 };
    System.out.println("e.length = " + e.length);
    monitor.expect(new String[] {
      "a.length=2",
      "b.length = 5",
      "b[0]=null",
      "b[1]=null",
      "b[2]=null",
      "b[3]=null",
      "b[4]=null",
      "c.length = 4",
      "d.length = 3",
      "a.length = 3",
      "f.length = 5",
      "f[0]=0",
      "f[1]=0",
      "f[2]=0",
      "f[3]=0",
      "f[4]=0",
      "g.length = 4",
      "h.length = 3",
      "e.length = 3",
      "e.length = 2"
    });
  }
} ///:~
ICONDEMO.C
        
/*--------------------------------------------------------------------------
        
    ICONDEMO.C --         Icon Demonstration Program
        
                                          (c) Charles Petzold, 1998
        
--------------------------------------------------------------------------*/
        
#include <windows.h>
        
#include "resource.h"
        

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
        
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
        
                                                         PSTR szCmdLine, int iCmdShow)
        
{
        
           TCHAR                         szAppName[]           = TEXT ("IconDemo") ;
        
           HWND                          hwnd ;
        
           MSG                           msg ;
        
           WNDCLASS              wndclass ;
        

           wndclass.style                               = CS_HREDRAW | CS_VREDRAW ;
        
           wndclass.lpfnWndProc                         = WndProc ;
        
           wndclass.cbClsExtra                          = 0 ;
        
          wndclass.cbWndExtra                          = 0 ;
        
           wndclass.hInstance                           = hInstance ;
        
           wndclass.hIcon                               = LoadIcon (hInstance, MAKEINTRESOURCE (IDI_ICON)) ;
        
           wndclass.hCursor                             = LoadCursor (NULL, IDC_ARROW) ;
        
           wndclass.hbrBackground               = GetStockObject (WHITE_BRUSH) ;
        
           wndclass.lpszMenuName                = NULL ;
        
           wndclass.lpszClassName               = szAppName ;
        
           if (!RegisterClass (&wndclass))
        
           {
        
                 MessageBox (  NULL, TEXT ("This program requires Windows NT!"),
        
                                                                       szAppName, MB_ICONERROR) ;
        
                  return 0 ;
        
    }
        
   
        
  hwnd = CreateWindow (szAppName, TEXT ("Icon Demo"),
        
                  WS_OVERLAPPEDWINDOW,
        
                  CW_USEDEFAULT, CW_USEDEFAULT,
        
                  CW_USEDEFAULT, CW_USEDEFAULT,
        
                 NULL, NULL, hInstance, NULL) ;
        
   
        
           ShowWindow (hwnd, iCmdShow) ;
        
           UpdateWindow (hwnd) ;
        
   
        
   while (GetMessage (&msg, NULL, 0, 0))
        
           {
        
                  TranslateMessage (&msg) ;
        
                  DispatchMessage (&msg) ;
        
  }
        
           return msg.wParam ;
        
}
        

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
        
{
        
           static HICON hIcon ;
        
           static int   cxIcon, cyIcon, cxClient, cyClient ;
        
           HDC          hdc ;
        
           HINSTANCE    hInstance ;
        
           PAINTSTRUCT  ps ;
        
           int          x, y ;
        
   
        
           switch (message)
        
           {
        
           case   WM_CREATE :
        
                  hInstance     = ((LPCREATESTRUCT) lParam)->hInstance ;
        
                  hIcon         = LoadIcon (hInstance, MAKEINTRESOURCE (IDI_ICON)) ;
        
                  cxIcon        = GetSystemMetrics (SM_CXICON) ;
        
                 cyIcon        = GetSystemMetrics (SM_CYICON) ;
        
                  return 0 ;
        
        
        
    case   WM_SIZE :
        
                 cxClient              = LOWORD (lParam) ;
        
                  cyClient              = HIWORD (lParam) ;
        
                  return 0 ;
        

    case   WM_PAINT :
        
                  hdc = BeginPaint (hwnd, &ps) ;
        
        
        
                 for (y = 0 ; y < cyClient ; y += cyIcon)
        
                                         for (x = 0 ; x < cxClient ; x += cxIcon)
        
                                                         DrawIcon (hdc, x, y, hIcon) ;
        
             
        
                                         EndPaint (hwnd, &ps) ;
        
                                         return 0 ;
        
             
        
           case   WM_DESTROY :
        
                  PostQuitMessage (0) ;
        
                  return 0 ;
        
           }
        
           return DefWindowProc (hwnd, message, wParam, lParam) ;
        
}
程序10-3  POEPOEM
        
POEPOEM.C
        
/*---------------------------------------------------------------------------
        
  POEPOEM.C -- Demonstrates Custom Resource
        
                                   (c) Charles Petzold, 1998
        
----------------------------------------------------------------------------*/
        
#include <windows.h>
        
#include "resource.h"
        

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
        
HINSTANCE hInst ;
        
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
        
                                          PSTR szCmdLine, int iCmdShow)
        
{
        
    TCHAR                 szAppName [16], szCaption [64], szErrMsg [64] ;
        
    HWND                  hwnd ;
        
    MSG                   msg ;
        
    WNDCLASS              wndclass ;
        
   
        
    LoadString (  hInstance, IDS_APPNAME, szAppName,
        
                                   sizeof (szAppName) / sizeof (TCHAR)) ;
        

    LoadString (  hInstance, IDS_CAPTION, szCaption,
        
                                   sizeof (szCaption) / sizeof (TCHAR)) ;
        
      
        
    wndclass.style                               = CS_HREDRAW | CS_VREDRAW ;
        
    wndclass.lpfnWndProc                         = WndProc ;
        
    wndclass.cbClsExtra                          = 0 ;
        
    wndclass.cbWndExtra                          = 0 ;
        
           wndclass.hInstance                   = hInstance ;
        
           wndclass.hIcon                       = LoadIcon (hInstance, szAppName) ;
        
           wndclass.hCursor                     = LoadCursor (NULL, IDC_ARROW) ;
        
           wndclass.hbrBackground              = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
        
           wndclass.lpszMenuName                = NULL ;
        
           wndclass.lpszClassName               = szAppName ;
        
 
        
           if (!RegisterClass (&wndclass))
        
           {
        
           LoadStringA (hInstance, IDS_APPNAME, (char *) szAppName,
        
                                                                sizeof (szAppName)) ;
        
           LoadStringA (hInstance, IDS_ERRMSG, (char *) szErrMsg,
        
                                                               sizeof (szErrMsg)) ;
        
           MessageBoxA (NULL, (char *) szErrMsg,
        
                                                                (char *) szAppName, MB_ICONERROR) ;
        
           return 0 ;
        
           }
        
   
        
           hwnd = CreateWindow (szAppName, szCaption,
        
                    WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
        
                    CW_USEDEFAULT, CW_USEDEFAULT,
        
                    CW_USEDEFAULT, CW_USEDEFAULT,
        
                    NULL, NULL, hInstance, NULL) ;
        
   
        
           ShowWindow (hwnd, iCmdShow) ;
        
           UpdateWindow (hwnd) ;
        
   
        
           while (GetMessage (&msg, NULL, 0, 0))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -