Escolar Documentos
Profissional Documentos
Cultura Documentos
• Label
new Label(String texto, int alinhamento);
Label rotulo = new Label(“label1”, Label.left);
• Button
new Button(String titulo);
Button meuBotao = new Button(“Botao1”);
Componentes Visuais
• Checkbox
new Checkbox(String rotulo, boolean estado);
• Radio
CheckboxGroup cbg = new CheckboxGroup();
Checkbox cb1 = new Checkbox(“caixabox1”, false, cbg);
Checkbox cb2 = new Checkbox(“caixabox2”, false, cbg);
Checkbox cb3 = new Checkbox(“caixabox3”, true, cbg);
Componentes Visuais
• Choice
Choice ch = new Choice();
ch.addItem(“Primeiro”);
ch.addItem(“Segundo”);
ch.addItem(“Terceiro”);
Componentes Visuais
• List
new List( int numLinhasVisiveis, boolean
multSelecao);
List ls = new List(7, true);
ls.add(“Uno”);
ls.add(“Due”);
ls.add(“Tre”);
...
...
Componentes Visuais
• TextField
new TextField(int numCarac);
TextField tf = new TextField(20);
tf.setText(“”);
String str = tf.getText();
• TextArea
new TextArea(int linhas, int colunas)
TextArea ta = new TextArea(5, 20);
String conteudo = ta.getText();
Containers
• Panel
– new Panel();
– FlowLayout=> gerenciador de layout default
• Applet
– new Applet()
– FlowLayout=> gerenciador de layout default
Containers
• Frame
– new Frame(String titulo) BorderLayout=> gerenciador de
layout default
• Dialog
– New Dialog(Frame pai, String titulo, boolean modal)
• FileDialog
– New FileDialog(Frame pai, String titulo, boolean modo)
Gerenciadores de layout
• BorderLayout
– Divide container em cinco regiões (“North”, “Lest”,
“East”, “South”, “Center”) com apenas um
componente por região
Frame f = new Frame(“BorderLayout”);
Button bn = new Button(“b1”);
f.add(bn, BorderLayout.NORTH);
Gerenciadores de layout
• FlowLayout
– Componentes posicionados da esquerda para
direita, de cima para baixo, com seus tamanhos
preferenciais e na ordem em que foram adicionados
b1 = new Button(“....”);
b2 = new Button(“....”);
f.setLayout(new FlowLayout());
f.add(b1);
f.add(b2);
Gerenciadores de layout
• CardLayout
– Implementa painéis que podem ser sobrepostos
na mesma área. Não fornece as abas para
seleção
f.setLayout(new CardLayout());
Panel painel = new Panel();
f.add(painel, “Painel1”);
Gerenciadores de layout
• GridLayout
– Posiciona os componentes segundo uma
grade. Aceita um componente por célula da
grade
Frame f = new Frame(“Programa”);
f.setLayout (new GridLayout(3,2,5,5));
f.add(b1);
f.add(b2);
import java.awt.*;
class programa03 {
public static void main(String args[]) {
Frame f = new Frame("GridLayout");
f.setLayout(new GridLayout(5,2,10,10));
Button b1 = new Button("Botao1");
Label l1 = new Label("Label1");
Checkbox caixa1 = new Checkbox("Caixa1", null, false);
CheckboxGroup GrupoBotoes = new CheckboxGroup();
Checkbox caixabox1 = new Checkbox("caixabox1", GrupoBotoes, false);
Checkbox caixabox2 = new Checkbox("caixabox2", GrupoBotoes, false);
Checkbox caixabox3 = new Checkbox("caixabox3", GrupoBotoes, false);
Choice ListaSelecao = new Choice();
ListaSelecao.addItem("Primeiro");
ListaSelecao.addItem("Segundo");
ListaSelecao.addItem("Terceiro");
TextField campotexto = new TextField();
TextArea campoarea = new TextArea();
campoarea.reshape(0,0,50,100);
f.add(b1); f.add(l1); f.add(caixa1); f.add(caixabox1);
f.add(caixabox2); f.add(caixabox3); f.add(ListaSelecao); f.add(campotexto);
f.add(campoarea); f.pack(); f.setVisible(true);
}}
import java.awt.*;
import java.applet.*;
public class programaTudo extends Applet{
Button b1 = new Button("Botao1");
Label l1 = new Label("Label1");
Checkbox caixa1 = new Checkbox("Caixa1", null, false);
CheckboxGroup GrupoBotoes = new CheckboxGroup();
Checkbox caixabox1 = new Checkbox("caixabox1", GrupoBotoes, false);
Checkbox caixabox2 = new Checkbox("caixabox2", GrupoBotoes, false);
Checkbox caixabox3 = new Checkbox("caixabox3", GrupoBotoes, false);
Choice ListaSelecao = new Choice();
TextField campotexto = new TextField();
TextArea campoarea = new TextArea();
public void init() {
ListaSelecao.addItem("Primeiro");
ListaSelecao.addItem("Segundo");
ListaSelecao.addItem("Terceiro");
setLayout(new GridLayout(5,2,10,10));
add(b1); add(l1); add(caixa1); add(caixabox1); add(caixabox2);
add(caixabox3); add(ListaSelecao); add(campotexto); add(campoarea);
campoarea.reshape(0,0,50,100); setVisible(true);
}
}
Componentes Visuais + Containers +
Gerenciador de Layout: Applets
Componentes Visuais + Containers +
Gerenciador de Layout: Applets