Olá pessoal, eu tenho a seguinte classe:
package icons;
import javax.swing.*;
import java.awt.*;
public class Icon{
//public Icon(){
// Ícones usados na GUI
public static final ImageIcon calculadora = new ImageIcon(Icon.class.getResource("/icons/calculator.png"));
public static final ImageIcon titularicon = new ImageIcon(Icon.class.getResource("/icons/titulart.png"));
public static final ImageIcon contaicon = new ImageIcon(Icon.class.getResource("/icons/contac.png"));
public static final ImageIcon eventos = new ImageIcon(Icon.class.getResource("/icons/eventos.png"));
public static final ImageIcon ajuda = new ImageIcon(Icon.class.getResource("/icons/ajuda.png"));
public static final ImageIcon encontrar = new ImageIcon(Icon.class.getResource("/icons/encontrar.png"));
public static final ImageIcon loginicon = new ImageIcon(Icon.class.getResource("/icons/login.png"));
public static final ImageIcon novacontaicon = new ImageIcon(Icon.class.getResource("/icons/novaconta.png"));
public static final ImageIcon minhacontaicon = new ImageIcon(Icon.class.getResource("/icons/minhaconta.png"));
public static final ImageIcon planejamentoicon = new ImageIcon(Icon.class.getResource("/icons/planejamento.png"));
public static final ImageIcon geriricon = new ImageIcon(Icon.class.getResource("/icons/gerir.png"));
public static final ImageIcon balancaicon = new ImageIcon(Icon.class.getResource("/icons/balança.png"));
public static final ImageIcon moedasicon = new ImageIcon(Icon.class.getResource("/icons/moedas.png"));
public static final ImageIcon usuarioicon = new ImageIcon(Icon.class.getResource("/icons/usuario.png"));
public static final ImageIcon graficoicon = new ImageIcon(Icon.class.getResource("/icons/grafico.png"));
public static final ImageIcon ferramentasicon = new ImageIcon(Icon.class.getResource("/icons/ferramentas.png"));
public static final ImageIcon fluxoicon = new ImageIcon(Icon.class.getResource("/icons/fluxo.png"));
public static final ImageIcon amigosicon = new ImageIcon(Icon.class.getResource("/icons/amigos.png"));
public static final ImageIcon pesquisaricon = new ImageIcon(Icon.class.getResource("/icons/pesquisar.png"));
public static final ImageIcon propriedadesicon = new ImageIcon(Icon.class.getResource("/icons/propriedades.png"));
//}
}
Tenho uma outra classe, que vai usar os ícones da classe do pacote acima:
package gui;
/*
* Autor: Amarildo J. C. Lucas (rasinc)
* CEO: Real Arts Studio.ins
* WebSite: www.realarts3d.blogspot.com
* Descrição: Desenvolver uma janela de cadastro de contas
* Obs: Deverá ser o mais customizável possível
*/
//import home.rasinc.ras.0.RealProgrammingDeveloper.inc/PacotesemDesenvolvimento/Classes/icons;
import java.awt.*;
import javax.swing.*;
import icons.Icon;
public class CadastroContas extends JFrame{
private String pessoal = "Pessoal";
private String corporacao = "Corporação";
private String publico = "Público";
private String privado = "Privado";
public CadastroContas(){
setTitle ("Nova Conta");
/*String[] colunasDaTable = {"Nome", "Tipo Conta", "Restrição", "Conta", "Estado", "Saldo"};
Object[][] dados = {"Anônimo", "Pessoal", "Privado", "AB12342-CD", "Activo", "$ 12000.00"};
JTable tabela = new JTable(dados, colunasDaTable);
DefaultTableModel modelo = (DefaultTableModel) (new DefaultTableModel(){
public boolean isCellEditable(int row, int columns){
return false;
}
});
modelo.setColumnsIdentifiers(colunas);
modelo.setRowCount(4);
modelo.addRow(dados);
tabela.setModel(modelo);
*/
Container c = new Container();
c = getContentPane();
c.setLayout(new GridBagLayout());
// Jlabels
JLabel lbltitular = new JLabel("Titular");
JLabel lblconta = new JLabel("Conta");
JLabel lblquantia = new JLabel("Quantia");
// JButtons
JButton btnsalvar = new JButton("Salvar");
JButton btncancelar = new JButton("Cancelar");
JButton btnexcluir = new JButton("Excluir");
JButton btnrelatorio = new JButton("Relatório");
JButton btnimprimir = new JButton("Imprimir");
JButton btntitular = new JButton();
btntitular.setIcon(Icon.titularicon);
btntitular.setBorderPainted(false);
JButton btnconta = new JButton();
btnconta.setIcon(Icon.contaicon);
btnconta.setBorderPainted(false);
// JTextFields
JTextField txftitular = new JTextField(15);
txftitular.setPreferredSize(new Dimension(20, 27));
JTextField txfconta = new JTextField(15);
txfconta.setPreferredSize(new Dimension(0, 27));
JTextField txfquantia = new JTextField(5);
txfconta.setPreferredSize(new Dimension(0, 27));
// RadioButtons
JRadioButton jrbPessoal = new JRadioButton(pessoal);
jrbPessoal.setActionCommand(pessoal);
JRadioButton jrbCorporacao = new JRadioButton(corporacao);
jrbCorporacao.setActionCommand(corporacao);
JRadioButton jrbPublico = new JRadioButton(publico);
jrbPublico.setActionCommand(publico);
JRadioButton jrbPrivado = new JRadioButton(privado);
jrbPrivado.setActionCommand(privado);
// Grupo dos RadioButtons
ButtonGroup grupo = new ButtonGroup();
ButtonGroup grupo2 = new ButtonGroup();
grupo.add(jrbPessoal);
grupo.add(jrbCorporacao);
grupo2.add(jrbPublico);
grupo2.add(jrbPrivado);
// Paineis
JPanel titledPainel = new JPanel();
titledPainel.setLayout(new GridBagLayout());
JPanel txfPainel = new JPanel();
txfPainel.setLayout(new GridBagLayout());
JPanel titledRestricaoPainel = new JPanel();
titledRestricaoPainel.setLayout(new GridBagLayout());
JPanel titledSaldoPainel = new JPanel();
titledSaldoPainel.setLayout(new GridBagLayout());
JPanel botoesPainel = new JPanel();
botoesPainel.setLayout(new GridBagLayout());
titledPainel.setBorder(BorderFactory.createTitledBorder("Tipo da Conta"));
txfPainel.setBorder(BorderFactory.createTitledBorder("Dados da Conta"));
titledPainel.add(jrbPessoal, new GridBagConstraints(1,0,2,1,0,0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(20,20,0,5),0,0));
titledPainel.add(jrbCorporacao, new GridBagConstraints(1,1,2,2,0,0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0,20,0,5),0,0));
titledRestricaoPainel.setBorder(BorderFactory.createTitledBorder("Restrição"));
titledRestricaoPainel.add(jrbPublico, new GridBagConstraints(1,0,2,1,0,0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0,30,5,50),0,0));
titledRestricaoPainel.add(jrbPrivado, new GridBagConstraints(1,1,2,2,0,0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0,30,5,50),0,0));
titledPainel.add(titledRestricaoPainel, new GridBagConstraints(3,0,4,2,0,0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, new Insets(15,40,5,30),0,0));
titledSaldoPainel.setBorder(BorderFactory.createTitledBorder("Saldo"));
titledSaldoPainel.add(lblquantia, new GridBagConstraints(0,0,1,1,0,0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10,5,5,5),0,0));
titledSaldoPainel.add(txfquantia, new GridBagConstraints(1,0,2,1,0,0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, new Insets(15,5,5,5),0,0));
txfPainel.add(lbltitular, new GridBagConstraints(0,0,1,1,0,0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10,5,5,5),0,0));
txfPainel.add(txftitular, new GridBagConstraints(1,0,3,1,0,0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, new Insets(15,5,5,0),0,0));
txfPainel.add(btntitular, new GridBagConstraints(3,0,4,0,0,0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, new Insets(7,200,190,5),0,0));
txfPainel.add(lblconta, new GridBagConstraints(0,1,1,2,0,0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10,5,5,5),0,0));
txfPainel.add(txfconta, new GridBagConstraints(1,1,3,2,0,0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, new Insets(15,5,5,5),0,0));
txfPainel.add(btnconta, new GridBagConstraints(3,0,4,0,0,0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, new Insets(50,210,150,0),0,0));
txfPainel.add(titledSaldoPainel, new GridBagConstraints(0,2,3,2,0,0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10,50,0,5),0,0));
botoesPainel.add(btnsalvar, new GridBagConstraints(0,0,1,1,0,0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10,5,5,5),0,0));
botoesPainel.add(btncancelar, new GridBagConstraints(1,0,2,1,0,0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10,5,5,5),0,0));
botoesPainel.add(btnexcluir, new GridBagConstraints(3,0,3,1,0,0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10,5,5,5),0,0));
botoesPainel.add(btnrelatorio, new GridBagConstraints(4,0,4,1,0,0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10,120,5,5),0,0));
botoesPainel.add(btnimprimir, new GridBagConstraints(5,0,6,1,0,0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, new Insets(10,225,5,5),0,0));
c.add(titledPainel, new GridBagConstraints(0,0,3,1,0,0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(40,10,5,5),0,0));
c.add(txfPainel, new GridBagConstraints(0,1,3,0,0,0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5,10,100,0),0,0));
c.add(botoesPainel, new GridBagConstraints(0,2,3,0,0,0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(250,5,50,0),0,0));
setSize(530, 440);
setLocationRelativeTo(null);
setVisible(true);
}
public static void main(String[] args){
try {
// select Look and Feel
//UIManager.setLookAndFeel("com.jtattoo.plaf.smart.SmartLookAndFeel");
//UIManager.setLookAndFeel("com.birosoft.liquid.LiquidLookAndFeel");
//UIManager.setLookAndFeel( new com.nilo.plaf.nimrod.NimRODLookAndFeel());
//UIManager.setLookAndFeel(new rpdinc.realartsinc.realfinance.Login.SubstanceLookAndFeel());
UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
// start application
CadastroContas conta = new CadastroContas();
conta.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}
Elas compilam sem erro algum, mas ao executar dá a seguinte excepção:
java.lang.ExceptionInInitializerError
at gui.CadastroContas.(CadastroContas.java:65)
at gui.CadastroContas.main(CadastroContas.java:170)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:271)
Preciso de help, porfavor… obrigado.