ok:
package br.com.warhjr.view;
import java.awt.Color;
import java.awt.Container;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.InputStream;
import java.sql.SQLException;
import java.text.DecimalFormat;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.EmptyBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import br.com.warhjr.controller.ArquivoController;
import br.com.warhjr.dao.ArquivoDAO;
import br.com.warhjr.model.Arquivo;
import java.awt.Button;
public class CadastroArquivo extends JFrame {
private JPanel contentPane;
private JButton btnCarregar;
private JLabel labelExtencao;
private JTextField textFieldTamanho;
private JTextField textFieldexten;
private JTextField linha;
private JTextArea textAreaNome;
private Container contentor;
private JTextField textFieldArquivoNome;
private JTextField textFieldCodInc;
private JTextField textFieldEndereco;
private InputStream inputStrean;
private File file;
private JPanel panel_sucesso;
private JLabel lbLabelGif;
public JProgressBar progressBar;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
CadastroArquivo frame = new CadastroArquivo();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public CadastroArquivo() {
setTitle("Cadastro de Arquivos - Treina desktop - java swing");
setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE);
setBounds(100, 100, 851, 477);
contentPane = new JPanel();
contentPane.setBackground(SystemColor.menu);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
JPanel panel = new JPanel();
panel.setBackground(SystemColor.activeCaption);
JPanel panel_1 = new JPanel();
panel_1.setBackground(Color.WHITE);
JPanel panel_2 = new JPanel();
panel_2.setBackground(Color.WHITE);
JButton button = new JButton("Inserir");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if ((progressBar.isVisible()) == false)
{
progressBar.setVisible(true);
}
try {
ArquivoDAO auxCodInc = new ArquivoDAO();
textFieldCodInc.setText(String.valueOf(auxCodInc.incrementa()));
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
button.setFont(new Font("Tahoma", Font.BOLD, 11));
JButton button_1 = new JButton("Gravar");
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (progressBar.isVisible == false)
{
progressBar.setVisible(true)
} else{
progressBar.setVisible(false);
}
ArquivoController auxSave = new ArquivoController();
Arquivo auxArquivo = new Arquivo();
auxArquivo.setID(Integer.parseInt(textFieldCodInc.getText()));
auxArquivo.setNome(textFieldArquivoNome.getText());
auxArquivo.setExtencao(textFieldexten.getText());
auxArquivo.setTamanho(textFieldTamanho.getText());
auxArquivo.setEndereco(textFieldEndereco.getText());
try {
auxSave.SalvarArq(auxArquivo,textFieldEndereco.getText());
} catch (Exception e1) {
JOptionPane.showMessageDialog(null, e1.getMessage());
}
}
});
button_1.setFont(new Font("Tahoma", Font.BOLD, 11));
JButton button_2 = new JButton("Editar");
button_2.setFont(new Font("Tahoma", Font.BOLD, 11));
JButton button_3 = new JButton("Deletar");
button_3.setFont(new Font("Tahoma", Font.BOLD, 11));
JButton button_4 = new JButton("Cancelar");
button_4.setFont(new Font("Tahoma", Font.BOLD, 11));
JButton button_5 = new JButton("Consultar");
button_5.setFont(new Font("Tahoma", Font.BOLD, 11));
JButton button_6 = new JButton("Fechar ...");
button_6.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose(); }
});
button_6.setFont(new Font("Tahoma", Font.BOLD, 11));
GroupLayout gl_panel_2 = new GroupLayout(panel_2);
gl_panel_2.setHorizontalGroup(
gl_panel_2.createParallelGroup(Alignment.LEADING)
.addGap(0, 688, Short.MAX_VALUE)
.addGroup(gl_panel_2.createSequentialGroup()
.addContainerGap()
.addComponent(button, GroupLayout.PREFERRED_SIZE, 83, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(button_1, GroupLayout.PREFERRED_SIZE, 89, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(button_2, GroupLayout.PREFERRED_SIZE, 89, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(button_3, GroupLayout.PREFERRED_SIZE, 89, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(button_4, GroupLayout.PREFERRED_SIZE, 89, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(button_5, GroupLayout.PREFERRED_SIZE, 97, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(button_6, GroupLayout.PREFERRED_SIZE, 94, GroupLayout.PREFERRED_SIZE)
.addGap(320))
);
gl_panel_2.setVerticalGroup(
gl_panel_2.createParallelGroup(Alignment.TRAILING)
.addGap(0, 55, Short.MAX_VALUE)
.addGroup(gl_panel_2.createSequentialGroup()
.addGap(11)
.addGroup(gl_panel_2.createParallelGroup(Alignment.BASELINE)
.addComponent(button, GroupLayout.DEFAULT_SIZE, 33, Short.MAX_VALUE)
.addComponent(button_1, GroupLayout.DEFAULT_SIZE, 33, Short.MAX_VALUE)
.addComponent(button_2, GroupLayout.DEFAULT_SIZE, 35, Short.MAX_VALUE)
.addComponent(button_3, GroupLayout.DEFAULT_SIZE, 35, Short.MAX_VALUE)
.addComponent(button_4, GroupLayout.DEFAULT_SIZE, 35, Short.MAX_VALUE)
.addComponent(button_5, GroupLayout.DEFAULT_SIZE, 35, Short.MAX_VALUE)
.addComponent(button_6, GroupLayout.DEFAULT_SIZE, 35, Short.MAX_VALUE))
.addGap(9))
);
panel_2.setLayout(gl_panel_2);
GroupLayout gl_contentPane = new GroupLayout(contentPane);
gl_contentPane.setHorizontalGroup(
gl_contentPane.createParallelGroup(Alignment.TRAILING)
.addGroup(gl_contentPane.createSequentialGroup()
.addContainerGap()
.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
.addComponent(panel_1, Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 807, Short.MAX_VALUE)
.addComponent(panel, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 807, Short.MAX_VALUE)
.addComponent(panel_2, Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 807, Short.MAX_VALUE))
.addContainerGap())
);
gl_contentPane.setVerticalGroup(
gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(panel, GroupLayout.PREFERRED_SIZE, 61, GroupLayout.PREFERRED_SIZE)
.addGap(11)
.addComponent(panel_1, GroupLayout.PREFERRED_SIZE, 286, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(panel_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addContainerGap(95, Short.MAX_VALUE))
);
JButton btnCarregar = new JButton("Carregar...");
btnCarregar.addActionListener(new ActionListener() {
@Override
@SuppressWarnings("static-access")
public void actionPerformed(ActionEvent e){
JFileChooser fileChooser = new JFileChooser();
if (fileChooser.showOpenDialog(btnCarregar) == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
ArquivoController auxController = new ArquivoController();
//textField.setText(file.getName());
textFieldArquivoNome.setText((file.getName()));
DecimalFormat df = new DecimalFormat("######################################");
String novonumero = df.format((file.length()));
// textFieldTamanho.setText(String.valueOf((float)file.length())+" bytes");
textFieldTamanho.setText(novonumero);
textFieldexten.setText(ArquivoController.getExtensao(file.getName()));
textFieldEndereco.setText(file.getAbsolutePath());
}
}
});
JLabel lblTamanho = new JLabel("Tamanho:");
JPanel panelAlerta = new JPanel();
panelAlerta.setVisible(false);
panelAlerta.setBackground(new Color(238, 232, 170));
textFieldTamanho = new JTextField();
textFieldTamanho.setEditable(false);
textFieldTamanho.setForeground(Color.BLUE);
textFieldTamanho.setColumns(10);
JLabel labelMessage = new JLabel("xxxxxx");
labelMessage.setFont(new Font("Tahoma", Font.BOLD, 13));
labelMessage.setForeground(SystemColor.textHighlight);
GroupLayout gl_panelAlerta = new GroupLayout(panelAlerta);
gl_panelAlerta.setHorizontalGroup(
gl_panelAlerta.createParallelGroup(Alignment.LEADING)
.addGroup(gl_panelAlerta.createSequentialGroup()
.addContainerGap()
.addComponent(labelMessage, GroupLayout.PREFERRED_SIZE, 205, GroupLayout.PREFERRED_SIZE)
.addContainerGap(426, Short.MAX_VALUE))
);
gl_panelAlerta.setVerticalGroup(
gl_panelAlerta.createParallelGroup(Alignment.LEADING)
.addGroup(Alignment.TRAILING, gl_panelAlerta.createSequentialGroup()
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(labelMessage)
.addContainerGap())
);
panelAlerta.setLayout(gl_panelAlerta);
textFieldexten = new JTextField();
textFieldexten.setEditable(false);
textFieldexten.setForeground(Color.BLUE);
textFieldexten.setColumns(10);
JLabel lblNewLabel_2 = new JLabel("Exten\u00E7\u00E3o:");
textFieldArquivoNome = new JTextField();
textFieldArquivoNome.setBackground(new Color(250, 250, 210));
textFieldArquivoNome.setEditable(false);
textFieldArquivoNome.setForeground(Color.BLUE);
textFieldArquivoNome.setColumns(10);
textFieldCodInc = new JTextField();
textFieldCodInc.setBackground(SystemColor.control);
textFieldCodInc.setFont(new Font("Tahoma", Font.BOLD, 17));
textFieldCodInc.setForeground(Color.RED);
textFieldCodInc.setEditable(false);
textFieldCodInc.setColumns(10);
textFieldEndereco = new JTextField();
textFieldEndereco.setEditable(false);
textFieldEndereco.setBackground(new Color(250, 250, 210));
textFieldEndereco.setColumns(10);
JLabel labelEndereco = new JLabel("Endere\u00E7o:");
JProgressBar progressBar = new JProgressBar();
progressBar.setStringPainted(true);
progressBar.setVisible(false);
JButton btnNewButtonSalvar = new JButton("Salvar Arquivo");
GroupLayout gl_panel_1 = new GroupLayout(panel_1);
gl_panel_1.setHorizontalGroup(
gl_panel_1.createParallelGroup(Alignment.LEADING)
.addGroup(gl_panel_1.createSequentialGroup()
.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING)
.addGroup(gl_panel_1.createSequentialGroup()
.addGap(10)
.addComponent(panelAlerta, GroupLayout.PREFERRED_SIZE, 697, GroupLayout.PREFERRED_SIZE))
.addGroup(gl_panel_1.createSequentialGroup()
.addGap(10)
.addComponent(textFieldCodInc, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE))
.addGroup(gl_panel_1.createSequentialGroup()
.addGap(10)
.addComponent(textFieldArquivoNome, GroupLayout.PREFERRED_SIZE, 557, GroupLayout.PREFERRED_SIZE)
.addGap(18)
.addComponent(btnCarregar, GroupLayout.PREFERRED_SIZE, 136, GroupLayout.PREFERRED_SIZE))
.addGroup(gl_panel_1.createSequentialGroup()
.addGap(10)
.addComponent(lblNewLabel_2)
.addGap(18)
.addComponent(textFieldexten, GroupLayout.PREFERRED_SIZE, 69, GroupLayout.PREFERRED_SIZE)
.addGap(70)
.addComponent(lblTamanho)
.addGap(4)
.addComponent(textFieldTamanho, GroupLayout.PREFERRED_SIZE, 223, GroupLayout.PREFERRED_SIZE))
.addGroup(gl_panel_1.createSequentialGroup()
.addGap(585)
.addComponent(btnNewButtonSalvar, GroupLayout.PREFERRED_SIZE, 136, GroupLayout.PREFERRED_SIZE))
.addGroup(gl_panel_1.createParallelGroup(Alignment.TRAILING, false)
.addGroup(Alignment.LEADING, gl_panel_1.createSequentialGroup()
.addGap(24)
.addComponent(progressBar, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(Alignment.LEADING, gl_panel_1.createSequentialGroup()
.addGap(10)
.addComponent(labelEndereco)
.addGap(18)
.addComponent(textFieldEndereco, GroupLayout.PREFERRED_SIZE, 490, GroupLayout.PREFERRED_SIZE))))
.addContainerGap(672, Short.MAX_VALUE))
);
gl_panel_1.setVerticalGroup(
gl_panel_1.createParallelGroup(Alignment.LEADING)
.addGroup(gl_panel_1.createSequentialGroup()
.addGap(4)
.addComponent(panelAlerta, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addGap(6)
.addComponent(textFieldCodInc, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addGap(6)
.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING)
.addComponent(textFieldArquivoNome, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE)
.addComponent(btnCarregar, GroupLayout.PREFERRED_SIZE, 31, GroupLayout.PREFERRED_SIZE))
.addGap(12)
.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING)
.addGroup(gl_panel_1.createSequentialGroup()
.addGap(3)
.addComponent(labelEndereco))
.addComponent(textFieldEndereco, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(9)
.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING)
.addGroup(gl_panel_1.createSequentialGroup()
.addGap(6)
.addComponent(lblNewLabel_2))
.addComponent(textFieldexten, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addGroup(gl_panel_1.createSequentialGroup()
.addGap(3)
.addComponent(lblTamanho))
.addComponent(textFieldTamanho, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(6)
.addComponent(btnNewButtonSalvar)
.addGap(18)
.addComponent(progressBar, GroupLayout.PREFERRED_SIZE, 33, GroupLayout.PREFERRED_SIZE)
.addGap(33))
);
panel_1.setLayout(gl_panel_1);
JLabel lblCadastroDeArquivos = new JLabel("Cadastro de Arquivos");
lblCadastroDeArquivos.setFont(new Font("Tahoma", Font.BOLD, 16));
lblCadastroDeArquivos.setForeground(SystemColor.text);
JLabel lblWarhjr = new JLabel("warhjr - 2015");
lblWarhjr.setFont(new Font("Tahoma", Font.BOLD, 11));
lblWarhjr.setForeground(Color.BLUE);
GroupLayout gl_panel = new GroupLayout(panel);
gl_panel.setHorizontalGroup(
gl_panel.createParallelGroup(Alignment.LEADING)
.addGroup(gl_panel.createSequentialGroup()
.addGap(24)
.addComponent(lblCadastroDeArquivos)
.addPreferredGap(ComponentPlacement.RELATED, 384, Short.MAX_VALUE)
.addComponent(lblWarhjr, GroupLayout.PREFERRED_SIZE, 94, GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
gl_panel.setVerticalGroup(
gl_panel.createParallelGroup(Alignment.LEADING)
.addGroup(Alignment.TRAILING, gl_panel.createSequentialGroup()
.addContainerGap(24, Short.MAX_VALUE)
.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
.addComponent(lblCadastroDeArquivos)
.addComponent(lblWarhjr))
.addGap(23))
);
panel.setLayout(gl_panel);
contentPane.setLayout(gl_contentPane);
}
}