Pessoal, estou abrindo outra janela (JFrame) com,
TelaPrincipal telaprincipal = new TelaPrincipal();
telaprincipal.setVisible(true);
porém abre uma janela nova vazia
abaixo segue o codigo da janela a ser aberta!!
package views;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import modelos.Eventosped;
import modelos.Produtos;
import modelos.ProdutosGrupos;
import modelos.Vendas;
import javax.swing.JButton;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.awt.event.ActionEvent;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.border.BevelBorder;
import aplicacao.Util;
import java.awt.Color;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.SwingConstants;
public class TelaPrincipal extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private JFrame frmVendas;
JPanel panelGrupos = new JPanel();
private JPanel panelProdutos;
private JPanel panelTotal;
private JLabel lbTotal;
private JLabel lbControle;
private long idControle = 0;
private double total = 0;
List<Eventosped> pedido = new ArrayList<Eventosped>();
/**
* Launch the application.
*/
public static void main(String[] args) {
System.out.println("Entrei em Telaprincipal");
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
TelaPrincipal window = new TelaPrincipal();
window.frmVendas.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public TelaPrincipal() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frmVendas = new JFrame();
frmVendas.setTitle("Vendas");
frmVendas.setBounds(100, 100, 450, 300);
frmVendas.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frmVendas.setExtendedState(JFrame.MAXIMIZED_BOTH);
JMenuBar menubar = new JMenuBar();
frmVendas.setJMenuBar(menubar);
JMenu opcoes = new JMenu("Opções");
menubar.add(opcoes);
JMenuItem menuAbrirPdv = new JMenuItem("Abrir PDV");
opcoes.add(menuAbrirPdv);
opcoes.add(new JSeparator());
JMenuItem menuExibeProdutos = new JMenuItem("Exibir produtos por Controle");
opcoes.add(menuExibeProdutos);
opcoes.add(new JSeparator());
JMenuItem menuSangria = new JMenuItem("Sangria");
opcoes.add(menuSangria);
opcoes.add(new JSeparator());
JMenuItem menuAbreGaveta = new JMenuItem("Abrir Gaveta");
opcoes.add(menuAbreGaveta);
opcoes.add(new JSeparator());
JMenuItem menuBipaFicha = new JMenuItem("Bipar fichas devolvidas");
opcoes.add(menuBipaFicha);
opcoes.add(new JSeparator());
JMenuItem menuFecharPdv = new JMenuItem("Fechar PDV");
opcoes.add(menuFecharPdv);
opcoes.add(new JSeparator());
JMenuItem menuSair = new JMenuItem("Sair");
opcoes.add(menuSair);
JMenu menuEncerrar = new JMenu("Encerrar Venda");
menubar.add(menuEncerrar);
opcoes.setFont(new Font("Courier New", Font.BOLD, 20));;
menuEncerrar.setFont(new Font("Courier New", Font.BOLD, 20));;
menuExibeProdutos.setFont(new Font("Courier New", Font.PLAIN, 20));;
menuSair.setFont(new Font("Courier New", Font.PLAIN, 20));;
menuSangria.setFont(new Font("Courier New", Font.PLAIN, 20));;
menuAbrirPdv.setFont(new Font("Courier New", Font.PLAIN, 20));;
menuFecharPdv.setFont(new Font("Courier New", Font.PLAIN, 20));;
menuAbreGaveta.setFont(new Font("Courier New", Font.PLAIN, 20));;
menuBipaFicha.setFont(new Font("Courier New", Font.PLAIN, 20));;
menuSair.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
menuAbreGaveta.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
}
});
//FlowLayout fl_panelGrupos = (FlowLayout) panelGrupos.getLayout();
panelGrupos.setBorder(new BevelBorder(BevelBorder.LOWERED, Color.DARK_GRAY, Color.DARK_GRAY, Color.DARK_GRAY, Color.DARK_GRAY));
panelGrupos.setBackground(Color.LIGHT_GRAY);
frmVendas.getContentPane().add(panelGrupos, BorderLayout.NORTH);
panelTotal = new JPanel();
panelTotal.setBorder(new BevelBorder(BevelBorder.LOWERED, Color.DARK_GRAY, Color.DARK_GRAY, Color.DARK_GRAY, Color.DARK_GRAY));
panelTotal.setBackground(Color.GRAY);
frmVendas.getContentPane().add(panelTotal, BorderLayout.SOUTH);
lbControle = new JLabel();
lbControle.setHorizontalAlignment(SwingConstants.LEFT);
lbControle.setFont(new Font("Courier New", Font.BOLD, 40));
panelTotal.add(lbControle);
lbTotal = new JLabel();
lbTotal.setHorizontalAlignment(SwingConstants.RIGHT);
lbTotal.setFont(new Font("Courier New", Font.BOLD, 40));
panelTotal.add(lbTotal);
panelProdutos = new JPanel();
frmVendas.getContentPane().add(panelProdutos, BorderLayout.CENTER);
Util.idPdv = 109;
Util.idUsuario = 67;
//--- ADICIONAR BOTOES DOS GRUPOS!!
adicionarBotoesGrupos();
}
public void adicionarBotoesGrupos() {
ProdutosGrupos produtosgrupos = new ProdutosGrupos();
List<ProdutosGrupos> grupos = produtosgrupos.ListaGrupos(0);
for (ProdutosGrupos dadosgrupos : grupos) {
/**
* CRIA BOTÕES DE GRUPOS DE PRODUTOS!!
*/
JButton BotaoGrupo = new JButton(dadosgrupos.getNome());
BotaoGrupo.setName(String.valueOf(dadosgrupos.getId()));
BotaoGrupo.setPreferredSize(new Dimension(100, 100));
panelGrupos.add(BotaoGrupo);
BotaoGrupo.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//--- FILTRA PRODUTOS CODIGO RETORNO DO CODIGO DO GRUPO!!
adicionarBotoesProdutos(BotaoGrupo. getName());
}
});
}
}
public void adicionarBotoesProdutos(String codigoGrupo) {
Produtos produtos = new Produtos();
List<Produtos> produtoslist = produtos.ListaProdutosPorGrupo(Integer.parseInt(codigoGrupo));
//----ZERO BOTOES PRODUTOS!!!
panelProdutos.removeAll();
for (Produtos dadosprodutos : produtoslist) {
/**
* CRIA BOTÕES DE PRODUTOS!!
*/
String LabelBotao = dadosprodutos.getNome()+"#"+" R$ "+dadosprodutos.getValor();
JButton BotaoProduto = new JButton("<html>" + LabelBotao.replaceAll("#", "<br><br>") + "</html>" );
BotaoProduto.setName(String.valueOf(dadosprodutos.getId()));
BotaoProduto.setPreferredSize(new Dimension(150, 100));
panelProdutos.add(BotaoProduto);
BotaoProduto.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String quantidade = null;
while (quantidade == null || quantidade.equals("") ) {
quantidade = (String) JOptionPane.showInputDialog(null,
"Informe a quantidade", dadosprodutos.getNome(),
JOptionPane.QUESTION_MESSAGE, null, null, 1);
//-- BOTÃO CANCELAR
if (quantidade == null) {
break;
}
try {
Integer.parseInt(quantidade);
} catch (NumberFormatException e1) {
quantidade = "";
JOptionPane.showMessageDialog(null,"Informe somente números");
}
}
if (quantidade != null) {
Vendas vendas = new Vendas();
Eventosped eventosped = new Eventosped();
//--- ATRIBUI EventosPed
eventosped.setDevolvido("N");
eventosped.setProduto(Integer.parseInt(BotaoProduto.getName()));
eventosped.setUsuario(67);
eventosped.setValor(dadosprodutos.getValor());
eventosped.setQuantidade(Integer.parseInt(quantidade));
try {
idControle = vendas.incluir(eventosped,idControle, quantidade);
//--- ADICIONAR NA ARRAYLIST
pedido.add(eventosped);
} catch (SQLException e1) {
// TODO Auto-generated catch bloc
e1.printStackTrace();
}
lbControle.setText("CONTROLE: "+idControle);
lbTotal.setText(" - TOTAL: "+String.valueOf(totaldavenda()));
}
}
});
panelProdutos.revalidate();
panelProdutos.repaint();
}
}
public double totaldavenda() {
total = 0;
for (Eventosped dadospedido : pedido) {
total = total + dadospedido.getValor() * dadospedido.getQuantidade() ;
}
return total;
}
}
tem algo errado??
Obrigado!!!