Amigos, bom dia! Estou tendo problema em implemantar excecão para o caso abaixo. Como devo proceder!
A caixa de texto para a entrada da placa do veículo. O grupo deve gerar um classe de exceção para placas diferentes do formato LLNNNN para carros e caminhões e LLNNN para motos. Onde L significa letra e N números. No caso de levantar uma exceção, o sistema informa ao usuário através de uma caixa de diálogo e limpa a caixa de texto. O evento deve ser tratado assim que o operador teclar
Em seguida, o operador escolhe o tipo de veículo que está passando em sua cabine, selecionando um dos radioButtons (Moto, Carro de Passeio ou Caminhão). No caso de um caminhai estar passando, outra caixa de diálogo deverá ser aberta para que ele digite de quantos eixos é composta esse caminhão.
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import org.dyno.visual.swing.layouts.Constraints;
import org.dyno.visual.swing.layouts.GroupLayout;
import org.dyno.visual.swing.layouts.Leading;
//VS4E -- DO NOT REMOVE THIS LINE!
public class test extends JFrame {
private static final long serialVersionUID = 1L;
private JTextField jTextField0;
private JRadioButton jRadioButton0;
private JRadioButton jRadioButton1;
private JRadioButton jRadioButton2;
private JButton jButton0;
private JButton jButton1;
private JButton jButton2;
private JLabel jLabel0;
private JLabel jLabel1;
private static final String PREFERRED_LOOK_AND_FEEL = "javax.swing.plaf.metal.MetalLookAndFeel";
public test() {
initComponents();
}
private void initComponents() {
setLayout(new GroupLayout());
add(getJRadioButton0(), new Constraints(new Leading(18, 10, 10), new Leading(109, 10, 10)));
add(getJButton0(), new Constraints(new Leading(18, 12, 12), new Leading(188, 10, 10)));
add(getJButton1(), new Constraints(new Leading(81, 12, 12), new Leading(188, 12, 12)));
add(getJButton2(), new Constraints(new Leading(204, 12, 12), new Leading(188, 12, 12)));
add(getJRadioButton1(), new Constraints(new Leading(76, 126, 8, 8), new Leading(109, 8, 8)));
add(getJRadioButton2(), new Constraints(new Leading(206, 85, 10, 10), new Leading(109, 8, 8)));
add(getJLabel1(), new Constraints(new Leading(21, 10, 10), new Leading(72, 10, 10)));
add(getJLabel0(), new Constraints(new Leading(21, 106, 12, 12), new Leading(36, 10, 10)));
add(getJTextField0(), new Constraints(new Leading(129, 95, 10, 10), new Leading(31, 27, 12, 12)));
setSize(440, 240);
}
private JLabel getJLabel1() {
if (jLabel1 == null) {
jLabel1 = new JLabel();
jLabel1.setText("Tipo de Veículo:");
}
return jLabel1;
}
private JLabel getJLabel0() {
if (jLabel0 == null) {
jLabel0 = new JLabel();
jLabel0.setText("Placa do Veículo:");
}
return jLabel0;
}
private JButton getJButton2() {
if (jButton2 == null) {
jButton2 = new JButton();
jButton2.setText("Sair");
jButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
jButton2ActionActionPerformed(event);
}
});
}
return jButton2;
}
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setText("Gerar relatorio");
}
return jButton1;
}
private JButton getJButton0() {
if (jButton0 == null) {
jButton0 = new JButton();
jButton0.setText("OK");
}
return jButton0;
}
private JRadioButton getJRadioButton2() {
if (jRadioButton2 == null) {
jRadioButton2 = new JRadioButton();
jRadioButton2.setSelected(true);
jRadioButton2.setText("Caminhão");
}
return jRadioButton2;
}
private JRadioButton getJRadioButton1() {
if (jRadioButton1 == null) {
jRadioButton1 = new JRadioButton();
jRadioButton1.setSelected(true);
jRadioButton1.setText("Carro de passeio");
}
return jRadioButton1;
}
private JRadioButton getJRadioButton0() {
if (jRadioButton0 == null) {
jRadioButton0 = new JRadioButton();
jRadioButton0.setSelected(true);
jRadioButton0.setText("Moto");
}
return jRadioButton0;
}
private JTextField getJTextField0() {
if (jTextField0 == null) {
jTextField0 = new JTextField();
}
return jTextField0;
}
/**
* Main entry of the class.
* Note: This class is only created so that you can easily preview the result at runtime.
* It is not expected to be managed by the designer.
* You can modify it as you like.
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
test frame = new test();
frame.setDefaultCloseOperation(test.EXIT_ON_CLOSE);
frame.setTitle("Sistema de Cobrança de Pedágio");
frame.getContentPane().setPreferredSize(frame.getSize());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
private void jButton2ActionActionPerformed(ActionEvent event) {
System.exit(EXIT_ON_CLOSE);
}
}