Gnustep Gorm is the first window program, the first graphic interface, and the first helloworld GUI)

Source: Internet
Author: User

[Tutorial] gnustep Gorm is the first window program, the first graphic interface, and the first helloworld GUI.

Gnustep is a platform developed by objective-C in the Apple system on Windows or Linux. It is convenient for us who do not have an Apple Computer but want to learn it, but after all, it is different. There are not many tutorials, so we have to explore them on our own.
There are many first helloworld about gnustep on the Internet, but it is a command line interface, the first windowProgramAlso, the gnustep tutorial on a page is in English and also has a traditional version. It is very difficult to understand how to import the feature in gnustep, after reading it for a long time, I realized what was going on. In fact, it was very simple. However, there was no corresponding GUI helloworld tutorial on the Internet. I will send one here!
Prerequisites: You must install the core and system of gnustep and install an application app. On the gnustep Windows Installer page, in addition to the required apps, select Gorm and download as follows!

· Systempreferences 1.1.0

· Gorm 1.2.10

Next let's start!
1. Don't use Gorm's first graphic interface, helloworld!
The helloworld program has five files: Main. M, appcontroller. H, appcontroller. M, helloworldinfo. plist, and gnumakefile. The graphic interface is designed inCodeIn, unlike the second program, the graphic interface of the second program is designed in. in the Gorm binary file, if it is. NIB files, not binary files, are in XML format. since it is developed under Gorm, it is used. gorm file,
Main. m

1. # include "appcontroller. H"

2. # include <appkit/appkit. h>

3.

4. Int main (INT argc, const char * argv [])

5 .{

6. NSAID utoreleasepool * pool;

7. appcontroller * delegate;

8.

9. Pool = [[NSAID utoreleasepool alloc] init];

10. Delegate = [[appcontroller alloc] init];

11.

12. [nsapplication sharedapplication];

13. [nsapp setdelegate: Delegate];

14.

15. Release (pool );

16. Return nsapplicationmain (argc, argv );

17 .}

Copy code

Appcontroller. h

1. # ifndef _ appcontroller_h _

2. # DEFINE _ appcontroller_h _

3.

4. # include <Foundation/nsobject. h>

5.

6. @ Class nswindow;

7. @ Class nstextfield;

8. @ Class nsnotification;

9.

10. @ interface appcontroller: nsobject

11 .{

12. nswindow * window;

13. nstextfield * label;

14 .}

15.

16.-(void) applicationwillfinishlaunching :( nsnotification *) not;

17.-(void) applicationdidfinishlaunching :( nsnotification *) not;

18.

19. @ end

20.

21. # endif/* _ appcontroller_h _*/

Copy code

Appcontroller. m

1. # include "appcontroller. H"

2. # include <appkit/appkit. h>

3.

4. @ implementation appcontroller

5.-(void) applicationwillfinishlaunching: (nsnotification *) Not

6 .{

7./* Create menu */

8. nsmenu * menu;

9. nsmenu * Info;

10.

11. Menu = [nsmenu new];

12. [menu additemwithtitle: @ "info"

13. Action: NULL

14. keyequivalent: @ ""];

15. [menu additemwithtitle: @ "hide"

16. Action: @ selector (hide :)

17. keyequivalent: @ "H"];

18. [menu additemwithtitle: @ "quit"

19. Action: @ selector (terminate :)

20. keyequivalent: @ "Q"];

21.

22. info = [nsmenu new];

23. [info additemwithtitle: @ "Info panel ..."

24. Action: @ selector (orderfrontstandardinfopanel :)

25. keyequivalent: @ ""];

26. [info additemwithtitle: @ "Preferences"

27. Action: NULL

28. keyequivalent: @ ""];

29. [info additemwithtitle: @ "help"

30. Action: @ selector (orderfronthelppanel :)

31. keyequivalent :@"? "];

32.

33. [menu setsubmenu: info

34. foritem: [menu itemwithtitle: @ "info"];

35. Release (Info );

36.

37. [nsapp setmainmenu: menu];

38. Release (menu );

39.

40./* Create window */

41. Window = [[nswindow alloc] initwithcontentrect: nsmakerect (300,300,200,100)

42. stylemask: (nstitledwindowmask |

43. nsminiaturizablewindowmask |

44. nsresizablewindowmask)

45. Backing: nsbackingstorebuffered

46. Defer: Yes];

47. [Window settitle: @ "Hello World"];

48.

49./* Create label */

50. Label = [[nstextfield alloc] initwithframe: nsmakerect (30, 30, 80, 30)];

51. [label setselectable: No];

52. [label setbezeled: No];

53. [label setdrawsbackground: No];

54. [label setstringvalue: @ "Hello World"];

55.

56. [[Window contentview] addsubview: Label];

57. Release (Label );

58 .}

59.

60.-(void) applicationdidfinishlaunching: (nsnotification *) Not

61 .{

62. [Window makekeyandorderfront: Self];

63 .}

64.

65.-(void) dealloc

66 .{

67. Release (window );

68. [Super dealloc];

69 .}

70.

71. @ end

Copy code

The following is the helloworldinfo. plist file:

1 .{

2. applicationdescription = "Hello World tutorial ";

3. applicationicon = "";

4. applicationname = helloworld;

5. applicationrelease = 0.1;

6. Authors = "";

7. Copyright = "Copyright (c) 200x ...";

8. copyrightdescription = "released under ...";

9. fullversionid = 0.1;

10. url = "";

11 .}

Copy code

Finally, gnumakefile is important:

1. gnustep_makefiles =/gnustep/system/library/makefiles

2.

3. include $ (gnustep_makefiles)/common. Make

4.

5. app_name = helloworld

6. helloworld_headers = appcontroller. h

7. helloworld_objc_files = Main. m appcontroller. m

8. helloworld_resource_files = helloworldinfo. plist

9.

10. include $ (gnustep_makefiles)/application. Make

Copy code

Note: In gnumakefile, the variables in the makefile folder of gnustep should be in the path, but these make files cannot be found during running, so I manually add them.
Next, put these files in a folder, such as helloworld1, and then run SH, or from the shell and CD of gnustep, run make !! If you have already run it, you will not do anything. You need to make clean; make will be OK!
Next, run./helloworld. APP/helloworld.exe to enjoy the helloworld program of your GUI.
Attachment: If you are too lazy to copy or write your own, I will upload an attachment: helloworld1
2. Use the first graphic interface of Gorm, helloworld!
Open Gorm, won't you? If you have installed Gorm, open SH, and run/gnustep/local/tools/gorm. Sh is in use, and CTRL + C closes gorm. in fact, this Gorm is a script, and the real program is in/gnustep/local/applications/gorm. APP/gorm.exe.

1 .#! /Bin/sh

2.

3. Exec openapp "Gorm" "$ @"

Copy code

Next let's start. After Gorm is opened, the main menu is usually located in the upper left corner. Click document-> new application and a simple window is displayed, which is called my window. Besides the menu, the important design window is untitled-7 (your program name, do not know how to call this window). In the palette window, general controls are dragged out from it; inspect window, set various attributes.

Upload

Download Attachment(113.16 KB)

Next, let's start designing.
1. change the size of my window and set the title. Drag the lower right corner of the window (the Mouse shape remains unchanged, causing me to crash) to make the window smaller. The title must be set manually in inspect, click my window first, and inspect will display the properties of my window. In the title text field, enter the title: Hello gnustep window, and the title will change, you can also change the window size in the inspect window. Click attributes and select size from the drop-down menu to change the window size.

Upload

Download Attachment(49.04 KB)

2. Add a title control. In the palettes window, drag the title to your window.

Upload

Download Attachment(48.47 KB)

Double-click the title and enter helloworld.
3. Add the info sub-menu in your window menu:
There is a wonderful bug of Mo min. After running, the menu Info-> Info panel sometimes cannot be displayed. Select twice and the app crashes.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.