Skip to content

Instantly share code, notes, and snippets.

@avh4
Created December 5, 2009 21:11
Show Gist options
  • Save avh4/249865 to your computer and use it in GitHub Desktop.
Save avh4/249865 to your computer and use it in GitHub Desktop.
package iphonedemo;
import org.xmlvm.iphone.CGRect;
import org.xmlvm.iphone.UIApplication;
import org.xmlvm.iphone.UILabel;
import org.xmlvm.iphone.UIScreen;
import org.xmlvm.iphone.UITextAlignment;
import org.xmlvm.iphone.UIView;
import org.xmlvm.iphone.UIWindow;
/**
*
* @author avh4
*/
public class DemoApplication extends UIApplication {
@Override
public void applicationDidFinishLaunching(UIApplication arg0) {
UIScreen screen = UIScreen.mainScreen();
CGRect rect = screen.getApplicationFrame();
UIWindow window = new UIWindow(rect);
rect.origin.x = rect.origin.y = 0;
UIView mainView = new UIView(rect);
window.addSubview(mainView);
UILabel title = new UILabel(rect);
title.setText("Hello World!");
title.setTextAlignment(UITextAlignment.Center);
mainView.addSubview(title);
window.makeKeyAndVisible();
}
}
package iphonedemo;
import org.xmlvm.iphone.UIApplication;
/**
*
* @author avh4
*/
public class Main {
public static void main(String args[])
{
UIApplication.main(args, DemoApplication.class);
}
}
package iphonedemo;
import java.util.Set;
import org.xmlvm.iphone.CGContext;
import org.xmlvm.iphone.CGRect;
import org.xmlvm.iphone.UITouch;
import org.xmlvm.iphone.UIView;
/**
*
* @author avh4
*/
public class Painter extends UIView {
public Painter(CGRect windowRect) {
super(windowRect);
}
boolean color = false;
@Override
public void drawRect(CGRect rect) {
float black[] = { 0, 0, 0, 1 };
float blue[] = { 0, 0, 1, 1 };
CGContext g = CGContext.UICurrentContext();
if (color)
{
g.setFillColor(blue);
}
else
{
g.setFillColor(black);
}
g.fillRect(rect);
}
@Override
public boolean touchedInsideView(Set<UITouch> touches) {
color = !color;
setNeedsDisplay();
return super.touchedInsideView(touches);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment