import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
public class FormPadrao extends JFrame{
private JButton btProReg, btRegAnt, btUltReg, btPriReg, btNovo, btGrav, btExcluir, btAlterar, btLimpar;
private JTextField tfCod, tfNome, tfSearch;
private JLabel lbCod, lbNome;
private JPanel panel;
private JComboBox box;
private JTable table;
public JButton getBtProReg() {
return btProReg;
}
public JButton getBtRegAnt() {
return btRegAnt;
}
public JButton getBtUltReg() {
return btUltReg;
}
public JButton getBtPriReg() {
return btPriReg;
}
public JButton getBtNovo() {
return btNovo;
}
public JButton getBtGrav() {
return btGrav;
}
public JButton getBtExcluir() {
return btExcluir;
}
public JButton getBtAlterar() {
return btAlterar;
}
public JButton getBtClear() {
return btClear;
}
public JTextField getTfCod() {
return tfCod;
}
public JTextField getTfNome() {
return tfNome;
}
public JTextField getTfSearch() {
return tfSearch;
}
public JLabel getLbCod() {
return lbCod;
}
public JLabel getLbNome() {
return lbNome;
}
public JPanel getPanel() {
return panel;
}
public JComboBox getBox() {
return box;
}
public JTable getTable() {
return table;
}
public FormPadrao(){
setTitle("FormPadrao");
setSize(220,340);
setLocation(500, 200);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().setLayout(null);
instanciando();
posicaoNaTela();
adicionandoNaTela();
panel.add(tfSearch);
panel.add(box);
panel.setLayout(null);
table.setModel(new DefaultTableModel(new Object[][]
{
{null,null},
{null,null},
{null,null},
{null,null},
},
new String[]{"Codigo", "Nome"}
));
tfSearch.setText("Pesquisar:");
listeners();
}
public void instanciando(){
table = new JTable();
box = new JComboBox();
panel = new JPanel();
btProReg = new JButton(">");
btRegAnt = new JButton("<");
btUltReg = new JButton(">>");
btPriReg = new JButton("<<");
btNovo = new JButton("+");
btGrav = new JButton("Gravar");
btAlterar = new JButton("A");
btExcluir = new JButton("X");
btClear = new JButton("C");
tfCod = new JTextField();
tfNome = new JTextField();
tfSearch = new JTextField();
lbCod = new JLabel("Cod:");
lbNome = new JLabel("Nome:");
}
public void posicaoNaTela(){
btAlterar.setBounds(150, 85, 60, 35);
btClear.setBounds(150, 125, 60, 35);
btExcluir.setBounds(150, 165, 60, 35);
btNovo.setBounds(150, 45, 60, 35);
btGrav.setBounds(5, 205, 205, 35);
btPriReg.setBounds(5, 125,68, 35);
btRegAnt.setBounds(76, 125,68, 35);
btUltReg.setBounds(5, 165,68, 35);
btProReg.setBounds(76, 165,68, 35);
lbCod.setBounds(5, 45, 40, 35);
lbNome.setBounds(5, 85, 40, 35);
tfCod.setBounds(50, 45, 95, 35);
tfNome.setBounds(50, 85, 95, 35);
panel.setBounds(0, 0, 210, 40);
tfSearch.setBounds(5, 5, 160-20,35);
box.setBounds(175-25, 5, 60,35);
table.setBounds(5, 245, 205, 65);
}
public void adicionandoNaTela(){
getContentPane().add(btAlterar);
getContentPane().add(btClear);
getContentPane().add(btExcluir);
getContentPane().add(btGrav);
getContentPane().add(btNovo);
getContentPane().add(btPriReg);
getContentPane().add(btProReg);
getContentPane().add(btRegAnt);
getContentPane().add(btUltReg);
getContentPane().add(lbCod);
getContentPane().add(lbNome);
getContentPane().add(tfCod);
getContentPane().add(tfNome);
getContentPane().add(panel);
getContentPane().add(table);
}
public void listeners(){
btAlterar.addActionListener(new Eventos());
btClear.addActionListener(new Eventos());
btExcluir.addActionListener(new Eventos());
btGrav.addActionListener(new Eventos());
btNovo.addActionListener(new Eventos());
btPriReg.addActionListener(new Eventos());
btProReg.addActionListener(new Eventos());
btRegAnt.addActionListener(new Eventos());
btUltReg.addActionListener(new Eventos());
}
public class Eventos implements ActionListener{
public void actionPerformed(ActionEvent e) {
alterar(e);
limpar(e);
excluir(e);
gravar(e);
novo(e);
primeiroRegistro(e);
proximoRegistro(e);
registroAnterior(e);
ultimoRegistro(e);
}
public void alterar(ActionEvent e){
if(e.getSource() == btAlterar){
//acão
}
}
public void limpar(ActionEvent e){
if(e.getSource() == btLimpar{
//acão
}
}
public void excluir(ActionEvent e){
if(e.getSource() == btExcluir){
//acão
}
}
public void gravar(ActionEvent e){
if(e.getSource() == btGrav){
//acão
}
}
public void novo(ActionEvent e){
if(e.getSource() == btNovo){
//acão
}
}
public void primeiroRegistro(ActionEvent e){
if(e.getSource() == btPriReg){
//acão
}
}
public void proximoRegistro(ActionEvent e){
if(e.getSource() == btProReg){
//acão
}
}
public void registroAnterior(ActionEvent e){
if(e.getSource() == btRegAnt){
//acão
}
}
public void ultimoRegistro(ActionEvent e){
if(e.getSource() == btUltReg){
//acão
}
}
}
}
import javax.swing.*;
public class Cliente extends FormPadrao{
private JTextField tfSearch;
public Cliente(){
//super.
}
public static void main(String [] args){
FormPadrao padrao = new Cliente();
padrao.setVisible(true);
}
}