Classe Principal
public class Principal {
public static void main(String[] args) {
SegundaGui gui = new SegundaGui ();
gui.abrir();
}
}
Segunda Gui
import java.awt.Color;
import java.awt.Rectangle;
import java.awt.event.ActionListener;
import javax.swing.*;
public class SegundaGui extends JFrame {
public void abrir (){
JPanel painel = new JPanel();
this.getContentPane().setLayout(null);
this.setSize(500,500);
this.setTitle(“Minha SegundaGui”);
//Label Nome
JLabel label = new JLabel(“Nome”);
label.setBounds(new Rectangle(10,17,250,25));
painel.add(label);
//Campo de texto
final JTextField texto = new JTextField(10);
texto.setBackground(Color.white);
texto.setBounds(new Rectangle(10,17,150,150));
painel.add(texto);
//Botão Enviar
JButton botao = new [...]
Setembro 27, 2008
Categorias: Sem Categoria . . Autor: wagnerperes . Comentários: Deixe um comentário
Classe Pessoa
public class ClassePessoa {
private String nome;
private String endereco;
public String getEndereco() {
return endereco;
}
public String getNome() {
return nome;
}
public void setEndereco(String endereco) {
this.endereco = endereco;
}
public void setNome(String nome) {
this.nome = nome;
}
public ClassePessoa() {
this.nome = “”;
}
}
Classe PessoaFisica
public class PessoaFisica extends ClassePessoa{
private String cpf;
public String getCpf (){
return cpf;
}
public void setCpf (String c){
this.cpf = c;
}
public PessoaFisica() {
this.cpf = “”;
}
}
Classe PessoaJuridica
public [...]
Setembro 26, 2008
Categorias: Sem Categoria . . Autor: wagnerperes . Comentários: Deixe um comentário
TRY – CATCH
import javax.swing.JOptionPane;
public class Potencia {
public static void main(String[] args) {
int base=0;
int exp=0;
int result = 0;
int i=0;
result = 1;
String str = “”;
str=JOptionPane.showInputDialog (“Digite a base”);
try{
base = Integer.parseInt(str);
}catch (Exception e){
JOptionPane.showMessageDialog(null, “numero inválido”);
}
str=JOptionPane.showInputDialog (“Digite o expoente”);
try{
exp = Integer.parseInt(str);
}catch (Exception e){
JOptionPane.showMessageDialog(null, “numero inválido”);
}
do{
result = result * base;
i++;
}while(i<exp);
JOptionPane.showMessageDialog(null, result);
}
}
Setembro 20, 2008
Categorias: Sem Categoria . . Autor: adrielbrites . Comentários: Deixe um comentário
Programação orientada a objeto
1. Exemplo Array
import javax.swing.JOptionPane;
public class Matriz {
public static void main(String[] args){
int a, b = 0;
String str = “”;
str = JOptionPane.showInputDialog(“informe o primeiro valor”);
a = Integer.parseInt(str);
b = Integer.parseInt(str);
int soma = a + b ;
JOptionPane.showMessageDialog(null, soma);
}
}
- Convertendo para Array ->
import javax.swing.JOptionPane;
public class ExemploArray {
public static [...]
Setembro 6, 2008
Categorias: Java . . Autor: wagnerperes . Comentários: Deixe um comentário