iSpectrum-2 with Java programs written iPhone

iSpectrum-written with the Java program an iPhone

Download the official demo available

iSpectrum-2 with Java programs written iPhone

First analysis of iSpectrum the framework of official demo

1 Launcher is the program entry, similar to the main.m, in fact the code is almost Deconstruction

  public void applicationDidFinishLaunching(UIApplication app)
        {
                UIWindow window = new UIWindow();
                window.initWithFrame(UIScreen.mainScreen().bounds());

                nav = new UINavigationController();

                UIViewController ctr = new UIViewController();
                ctr.init();
                ctr.setTitle("Action sheet");
                ctr.setView(new MainView(nav));

                nav.initWithRootViewController(ctr);

                window.addSubview(nav.view());
                window.makeKeyAndVisible();
        }

2 see mainview, no delloc really feel so cool, but absence of nib, so it can only initWithFrame added component of the original.

public class MainView extends UIView {
        /**
         * Fields
         */
        private UIActionSheet actionSheet;
        private UINavigationController nav;

        /**
         *
         * @param n             UINavigationController containing this view.
         */
        public MainView(UINavigationController n){
                super();
                init();
                nav = n;

                /*
                 * ActionSheet
                 */
                actionSheet = new UIActionSheet();
                actionSheet.init();
                actionSheet.setActionSheetStyle(UIActionSheetStyle.UIActionSheetStyleBlackOpaque);
                actionSheet.setDelegate(new ActionSheetDelegate(this));
                actionSheet.setTitle("How many items do you want to display ?");
                actionSheet.addButtonWithTitle("Cancel");
                actionSheet.setCancelButtonIndex(0);
                actionSheet.dismissWithClickedButtonIndexAnimated(0, true);
                actionSheet.addButtonWithTitle("One item");
                actionSheet.addButtonWithTitle("Two items");
                actionSheet.addButtonWithTitle("Three items");
                actionSheet.addButtonWithTitle("Four items");

                /*
                 * Button
                 * Being used to open the UIActionSheet.
                 */
                UIButton button = new UIButton(){
                        //@Override
                        public void controlEvent() {
                                // Display the UIActionSheet
                                actionSheet.showInView(this.superview());
                        }
                };
                button.initWithFrame(CGRect.CGRectMake(85, 30, 150, 31));
                button.setBackgroundImageForState(UIImage.imageNamed("buttonBackground.tiff"), 0);
                button.setTitleForState("Create view", 0);
                button.setTitleColorForState(UIColor.blackColor(), 0);
                button.addTargetActionForControlEvents(UIControlEvents.UIControlEventTouchUpInside);
                addSubview(button);
        }

        /**
         *
         * @return      nav             Current UINavigationController.
         */
        public UINavigationController getNavigationController(){
                return nav;
        }

}

Class 3 also have delegation

public class ActionSheetDelegate extends UIActionSheetDelegate {
        /**
         * Field
         */
        private MainView view;

        /**
         *
         * @param v             MainView that create this object.
         */
        public ActionSheetDelegate(MainView v){
                super();
                init();
                view = v;
        }

        /**
         * Method called by system when user select a button on action sheet.
         * @param actionSheet           ActionSheet calling this method.
         * @param buttonIndex           Index of selected button.
         *
         */
        //@Override
        public void actionSheetClickedButtonAtIndex(UIActionSheet actionSheet,
                        int buttonIndex) {
                if(buttonIndex == 0){
                        // Click on "cancel" button
                        return;
                }
                else {
                        UIView newView = new UIView().init();

                        // Add to the new UIView as many subviews as user wants.
                        for(int i=1; i<=buttonIndex; i++){
                                UIImageView imageView = new UIImageView();
                                imageView.initWithFrame(CGRect.CGRectMake(i*40, 100, 30, 30));
                                imageView.setImage(UIImage.imageNamed("img"+i+".tiff"));
                                newView.addSubview(imageView);
                        }

                        UIViewController viewController = new UIViewController().init();
                        if(buttonIndex == 1)
                                viewController.setTitle(buttonIndex + " added item");
                        else
                                viewController.setTitle(buttonIndex + " added items");
                        viewController.setView(newView);

                        // Push this new view into UINavigationController stack.
                        view.getNavigationController().pushViewControllerAnimated(viewController, false);
                }
        }

}

From simple demo seems useful to see the need java, since java completely unable to use, many features and open source code, but also by the plug-in developer's restrictions.

分类:Mobile 时间:2010-05-12 人气:178
分享到:
blog comments powered by Disqus

相关文章

  • Oracle Call JAVA program 2011-06-16

    Oracle call in a java program, helloWord A JAVA program written create or replace and compile java source named hello as public class Hello { static public String Message(String name) { return " Hello, " + name; } } / 2 JAVA program released cre

  • iSpectrum-written with the Java program an iPhone 2010-05-12

    Today, the Internet occasionally to see a claim that can be prepared using java eclipse plug-in iPhone programs, known as java can be developed in the non-mac os iPhone, very interested, so what you want: 1 Open http://www.flexycore.com/en/products/i

  • In the java program using comm port in the local management [Back Qinbo: Senior Software Engineer] 2010-08-23

    In the java program using comm port in the local management Recently did telecom project encountered a number of professional issues, to share with everyone here, under the comm package class and how to use the next issues: In java program, the local

  • java program to run linux 2010-10-08

    Recently made a timing module, the program's implementation is probably as follows, each packed into a regular task to achieve the Runnable class, that is, business logic written in the run method, finished to migrate to linux system after the proces

  • The use of Java Web Start release you use the java program 2010-03-29

    Preface: About JWS JWS is a JSR-56 as a part of creation, the purpose is to provide a way to distribute the JVM on the client running Java applications. JWS includes the following features: Run the JWS application deployment including the selection o

  • linux java program run time service crond 2010-03-24

    crontab to run java programs on your java program in the / root / example directory below named Test.java Test.java says: public class Test ( public static void main (String args []) ( System.out.println ("ok"); ) ) However, because the relevant

  • Java program to achieve through SMSLib library to send text messages 2010-04-10

    Java program to achieve through SMSLib library to send text messages SMS (Short Messaging Service) or Short Message Service, is set by the Etsi a specification (GSM 03.40 and GSM03.38). When using the 7-bits encoding, you can send up to 160 character

  • 1 Remove all files under specified directory and subdirectories of the Java program 2010-05-04

    Je on today wandering, I saw that many people share a delete all files under specified directory and subdirectories of the Java program is better, so copy this file over to borrow later. Originally posted address: recursive delete all files under spe

  • GBK character with java program will turn into a UTF-8 encoding format (change) 2010-05-12

    Original address: http://blog.csdn.net/wangjichen_1/archive/2006/08/04/1019830.aspx Java program to use the Internet to find what will turn into a GBK UTF-8 character encoding format code, find all written in C + +, and very cumbersome, Now write a j

  • java program in the exception handling experiences (2) log4j error logging 2010-05-12

    1.1 Related English Xiangjie log: log debug: debug error: error warn: warning info: news 1.2 What is log4j? Why should log4j? log4j Definition: log4j is a popular, good logging tool, it can output a variety of flexible methods of log information; Why

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.297 (s). 12 q(s)