Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package bravox.sistema.mensagens; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import java.math.BigDecimal; import java.text.NumberFormat; import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.ActionMap; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.InputMap; import javax.swing.JComponent; import javax.swing.KeyStroke; import org.joda.time.LocalTime; import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; /** * * @author jorgeb */ public class MensagemQtdMaiorProduzida extends javax.swing.JDialog { private String tipoProblemaQtd; /** * Creates new form MensagemTempoMaiorProducao */ public MensagemQtdMaiorProduzida(java.awt.Frame parent, boolean modal, String tipoProblemaQtd) { super(parent, modal); initComponents(); this.tipoProblemaQtd = tipoProblemaQtd; setLocationRelativeTo(null); Icon icone = new ImageIcon(System.getProperty("user.dir") + "/imagens/interrogacao.jpg"); jLImagem.setIcon(icone); setTitle("Ateno!"); atalhosTeclas(); String texto = jLabelMensagem.getText().trim(); texto = texto.replace("(texto)", tipoProblemaQtd); jLabelMensagem.setText(texto); } public double formataNumero(double numero, int casasDecimais) { NumberFormat formatador = NumberFormat.getInstance(); formatador.setMinimumFractionDigits(casasDecimais); formatador.setMaximumFractionDigits(casasDecimais); String numeroFormatado = formatador.format(numero); return Double.parseDouble(numeroFormatado.trim().replace(",", ".")); } public void retornaHora(String minutos) { // DateTimeFormatter format = DateTimeFormat.forPattern("HH:mm"); LocalTime hora = LocalTime.parse(minutos, DateTimeFormat.forPattern("HH:mm")); } public void atalhosTeclas() { //tecla de Atalho para o botao NAO - fecha a tela se pressionar esc //Action para o botao NAO Action actionTeclaNao = new AbstractAction() { @Override public void actionPerformed(ActionEvent arg0) { //simula o click no boto jButtonOK.doClick(); } }; //Associa o listener com a tecla N para que seja disparado toda vez, mesmo quando o foco no est no boto KeyStroke keyStrokeNao = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); String actionNameNao = "TECLA_ESC"; InputMap inputMapNao = jButtonOK.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMapNao.put(keyStrokeNao, actionNameNao); ActionMap actionMapNao = jButtonOK.getActionMap(); actionMapNao.put(actionNameNao, actionTeclaNao); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jLabelMensagem = new javax.swing.JLabel(); jButtonOK = new javax.swing.JButton(); jPanel1 = new javax.swing.JPanel(); jLImagem = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); jLabelMensagem.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N jLabelMensagem.setText( "Voc est lanando uma quantidade (texto) do que o esperado para produzir este produto neste tempo."); jButtonOK.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N jButtonOK.setText("OK"); jButtonOK.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonOKActionPerformed(evt); } }); jButtonOK.addFocusListener(new java.awt.event.FocusAdapter() { public void focusLost(java.awt.event.FocusEvent evt) { jButtonOKFocusLost(evt); } }); jButtonOK.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent evt) { jButtonOKKeyTyped(evt); } }); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup().addContainerGap() .addComponent(jLImagem, javax.swing.GroupLayout.DEFAULT_SIZE, 58, Short.MAX_VALUE) .addContainerGap())); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap() .addComponent(jLImagem, javax.swing.GroupLayout.DEFAULT_SIZE, 53, Short.MAX_VALUE) .addContainerGap())); jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N jLabel2.setForeground(new java.awt.Color(255, 0, 0)); jLabel2.setText("Ateno:"); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap() .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabelMensagem, javax.swing.GroupLayout.DEFAULT_SIZE, 703, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup().addGap(282, 282, 282) .addComponent(jButtonOK, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE))))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addGap(20, 20, 20) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabelMensagem).addComponent(jLabel2)) .addGap(18, 18, 18).addComponent(jButtonOK, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup().addContainerGap().addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); pack(); }// </editor-fold>//GEN-END:initComponents private void jButtonOKFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jButtonOKFocusLost }//GEN-LAST:event_jButtonOKFocusLost private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed this.setVisible(false); }//GEN-LAST:event_jButtonOKActionPerformed private void jButtonOKKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jButtonOKKeyTyped if (evt.getKeyChar() == KeyEvent.VK_ENTER) { if (evt.getSource() == jButtonOK) { this.setVisible(false); } } }//GEN-LAST:event_jButtonOKKeyTyped /** * @param args the command line arguments */ /* public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { MensagemTempoMaiorProducao dialog = new MensagemTempoMaiorProducao(new javax.swing.JFrame(), true); dialog.addWindowListener(new java.awt.event.WindowAdapter() { @Override public void windowClosing(java.awt.event.WindowEvent e) { System.exit(0); } }); dialog.setVisible(true); } }); }*/ // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButtonOK; private javax.swing.JLabel jLImagem; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabelMensagem; private javax.swing.JPanel jPanel1; // End of variables declaration//GEN-END:variables }