GWT 基本控件

public void onModuleLoad() {
	  /* 上传组件	*/
	  FileUpload fileUpload = new FileUpload();
	  RootPanel.get().add(fileUpload);
	  /* 添加超链接	*/
	  Hyperlink hyperlink = new Hyperlink();
	  hyperlink.setHTML("新浪");
	  hyperlink.setTargetHistoryToken("cao");
	  RootPanel.get().add(hyperlink);
	
	  /* 添加图片	*/
	  Image image = new Image("img.jpg");
	  RootPanel.get().add(image);
	  
	  /* Command 事件	*/
	  Command cmd = new Command() {
			public void execute() {
				Window.alert("click menu");
			}
	  };
	   /* 添加菜单	*/
	    MenuBar fooMenu = new MenuBar(true);
	    fooMenu.addItem("the", cmd);
	    fooMenu.addItem("foo", cmd);
	    fooMenu.addItem("menu", cmd);

	    MenuBar barMenu = new MenuBar(true);
	    barMenu.addItem("the", cmd);
	    barMenu.addItem("bar", cmd);
	    barMenu.addItem("menu", cmd);

	    MenuBar bazMenu = new MenuBar(true);
	    bazMenu.addItem("the", cmd);
	    bazMenu.addItem("baz", cmd);
	    bazMenu.addItem("menu", cmd);

	    // Make a new menu bar, adding a few cascading menus to it.
	    MenuBar menu = new MenuBar();
	    menu.addItem("foo", fooMenu);
	    menu.addItem("bar", barMenu);
	    menu.addItem("baz", bazMenu);

	    // Add it to the root panel.
	    RootPanel.get().add(menu);
	    
	    /* 树 */
	    TreeItem item = new TreeItem("MyTree");
	    item.addItem("item1");
	    item.addItem("item2");
	    item.addItem("item3");
	    item.addItem(new TreeItem(new CheckBox("item4")));
	    
	    Tree tree = new Tree();
	    tree.addItem(item);
	    
	    RootPanel.get().add(tree);

	    /* Label */
	    Label label = new Label("This is a label");
	    RootPanel.get().add(label);
	    
	    /* HTML代码 */
	    HTML html = new HTML();
	    html.setHTML("<a href='http://www.sina.com.cn'>新浪</a>");
	    RootPanel.get().add(html);
	    
	    /* iframe */
	    Frame frame = new Frame("http://www.baidu.com");
	    RootPanel.get().add(frame);
	    
	    /* select */
	    ListBox box = new ListBox();
	    box.addItem("item1");
	    box.addItem("item2");
	    box.addItem("item3");
	    box.addItem("item4");
	    box.addItem("item5");
	    box.addItem("item6");
	    box.setVisibleItemCount(5);
	    RootPanel.get().add(box);
	    
	    /* Checkbox */
	    CheckBox boxCheckBox = new CheckBox("choose");
	    RootPanel.get().add(boxCheckBox);
	    
	    /* input[type='radio']	*/
	    RadioButton radioButton = new RadioButton("choose");
	    radioButton.setText("choose");
	    RootPanel.get().add(radioButton);
	    
	    /* Button */
	    Button btn = new Button("Button");
	    btn.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				Window.alert("Clicked!");
			}
	    });
	    RootPanel.get().add(btn);
	    
	    /* input[type='text']	*/
	    TextBox textBox = new TextBox();
	    textBox.setValue("hello");
	    RootPanel.get().add(textBox);
	    
	    /* textarea	*/
	    TextArea area = new TextArea();
	    area.setValue("This is a textarea");
	    RootPanel.get().add(area);
	    
	    /* input[type='password'] */
	    PasswordTextBox passwordTextBox = new PasswordTextBox();
	    passwordTextBox.setValue("password");
	    RootPanel.get().add(passwordTextBox);
  }

 

你可能感兴趣的:(html,gwt)