[code]package trab2;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.JTextField;
import javax.swing.JLabel;
import java.awt.FlowLayout;
import org.eclipse.wb.swing.FocusTraversalOnArray;
import java.awt.Component;
import java.awt.Font;
import javax.swing.JTextPane;
import javax.swing.BoxLayout;
import java.awt.GridLayout;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class cadastros extends JPanel {
private JTextField textField;
private JTextField textField_1;
private JTextField textField_2;
/**
* Create the panel.
*/
public cadastros() {
setToolTipText("");
setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
JLabel lblNome = new JLabel("Nome: ");
lblNome.setFont(new Font("Tahoma", Font.PLAIN, 16));
add(lblNome);
textField = new JTextField();
add(textField);
textField.setColumns(10);
setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{lblNome, textField, lblAnoContrato, textField_1, lblValorMensalidade, textField_2}));
JLabel lblAnoContrato = new JLabel("Ano Contrato:");
lblAnoContrato.setFont(new Font("Tahoma", Font.PLAIN, 15));
add(lblAnoContrato);
textField_1 = new JTextField();
add(textField_1);
textField_1.setColumns(10);
JLabel lblValorMensalidade = new JLabel("Valor Mensalidade:\r\n");
lblValorMensalidade.setFont(new Font("Tahoma", Font.PLAIN, 15));
add(lblValorMensalidade);
textField_2 = new JTextField();
add(textField_2);
textField_2.setColumns(10);
JButton btnOk = new JButton("OK");
btnOk.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//criar ação;
}
});
add(btnOk);
JButton btnLimpar = new JButton("Limpar");
add(btnLimpar);
}
}
/* JFrame teste = new JFrame(“Formulário”);
teste.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
teste.setResizable(false);
teste.setSize(315,180);
JLabel label1;
JLabel label2;
JTextField textField1;
JTextField textField2;
JButton button1;
label1 = new JLabel();
label2 = new JLabel();
textField1 = new JTextField();
textField2 = new JTextField();
button1 = new JButton();
Container contentPane = teste.getContentPane();
contentPane.setLayout(null);
label1.setText(“Nome:”);
contentPane.add(label1);
label1.setBounds(new Rectangle(new Point(10, 15), label1.getPreferredSize()));
label2.setText(“Idade:”);
contentPane.add(label2);
label2.setBounds(new Rectangle(new Point(10, 45), label2.getPreferredSize()));
contentPane.add(textField1);
textField1.setBounds(45, 15, 245, textField1.getPreferredSize().height);
contentPane.add(textField2);
textField2.setBounds(45, 45, 45, 20);
button1.setText(“Cadastrar”);
contentPane.add(button1);
button1.setBounds(new Rectangle(new Point(10, 105), button1.getPreferredSize())); {
Dimension preferredSize = new Dimension();
for(int i = 0; i < contentPane.getComponentCount(); i++) {
Rectangle bounds = contentPane.getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
}
//Insets insets = contentPane.getInsets();
//preferredSize.width += insets.right;
//preferredSize.height += insets.bottom;
contentPane.setMinimumSize(preferredSize);
contentPane.setPreferredSize(preferredSize);
}
teste.setVisible(true);
} */[/code]