Bom dia . Ao executar classe java, onde exibirei um gráfico, é apresentada a seguinte mensagem :
“Exception in thread “AWT-EventQueue-0” java.lang.NoClassDefFoundError: org/jfree/util/PublicCloneable”
Confesso que não sei como resolver .
Bibliotecas que fazem parte do projeto:
jcommon.jar.jar , jfreechart-1.0.19.jar, swtgraphics2d.jar
Código da classe :
"
/*
- 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.
*/
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
/**
*
-
@author efer_
*/
public class exercicio_forca_iso_bilateral extends javax.swing.JFrame {// Variáveis globais
DefaultListModel lm = new DefaultListModel();
serial s = new serial();
ArrayList valores = new ArrayList();
// -------------------------------------------/**
- Creates new form principal
*/
public exercicio_forca_iso_bilateral() {
initComponents();
}
/**
-
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”)
//
private void initComponents() {jScrollPane1 = new javax.swing.JScrollPane();
jList1 = new javax.swing.JList<>();
jButton1 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jLabel11 = new javax.swing.JLabel();
txtData = new javax.swing.JTextField();setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jScrollPane1.setViewportView(jList1);
jButton1.setText(“Iniciar”);
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton1MouseClicked(evt);
}
});jButton4.setText(“Parar”);
jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton4MouseClicked(evt);
}
});jLabel1.setText(“Máximo:”);
jLabel2.setText(“0”);
jLabel3.setText(“Mínimo:”);
jLabel4.setText(“0”);
jLabel5.setText(“Média:”);
jLabel6.setText("-");
jLabel7.setText(“Tempo:”);
jLabel8.setText(“00:00”);
jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel9.setText(“Dados:”);jLabel10.setText(“BILATERAL”);
jLabel11.setText(“DATA:”);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(22, 22, 22)
.addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel1)
.addComponent(jLabel3)
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel5)
.addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel7)
.addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 34, Short.MAX_VALUE)
.addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 505, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(32, 32, 32))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(344, 344, 344)
.addComponent(jLabel10))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel11)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(txtData, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel10)
.addGap(35, 35, 35)
.addComponent(jLabel9)
.addGap(26, 26, 26)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel11)
.addComponent(txtData, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(35, 35, 35)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 297, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton1)
.addGap(8, 8, 8)
.addComponent(jButton4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel7)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel8)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel6)))
.addGap(0, 0, Short.MAX_VALUE))
.addComponent(jScrollPane1))
.addContainerGap())
);pack();
}//
Thread t = new Thread(new Runnable() {
@Override
public void run() {
char ch = s.lerCOM();
int escolha = JOptionPane.showConfirmDialog(null, “Pronto para começar?”, “Confirmar”, JOptionPane.YES_NO_OPTION);
if (escolha != JOptionPane.NO_OPTION) {
long inicio = System.currentTimeMillis();
while (true) { // loop infinito !!!
// Cronometro
long atual = System.currentTimeMillis();
long tempo = (atual - inicio);
jLabel8.setText(new SimpleDateFormat(“mm:ss”).format(new Date(atual - inicio)));
jLabel8.updateUI();
// ----------
boolean continuar = true;
String palavra = “”;
while (continuar) {
ch = s.lerCOM();
System.out.print(ch);
if (ch != ‘\n’) {
palavra += ch;
} else {
// Para limpar e só mostrar os valores vamos usar o try … catch …
try {
Double.parseDouble(palavra); // Tenta converter para double, se não der vai para o catch e ignora o valor
lm.addElement(palavra);
} catch (Exception e) {}
continuar = false;
}
jList1.setModel(lm);
jList1.updateUI();
}
// Manter o valor máximo encontrado atualizado
try {
if (Double.parseDouble(palavra) > Double.parseDouble(jLabel2.getText())) {
jLabel2.setText(palavra);
jLabel2.updateUI();
}
} catch (Exception e) {
}
// Manter o valor mínimo encontrado atualizado
try {
if (Double.parseDouble(palavra) < Double.parseDouble(jLabel4.getText())) {
jLabel4.setText(palavra);
jLabel4.updateUI();
}
} catch (Exception e) {
}
}
}
}
});private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
jButton1.setEnabled(false); // Desabilita o botão
s.selecionaCOM(“COM3”);
lm.removeAllElements();
t.start(); // Inicia a Thread
}DefaultCategoryDataset pegaDados() {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
String t = “0”;
for (int i = 0; i < lm.getSize(); i++) {
try {
dataset.addValue(Double.parseDouble(lm.getElementAt(i).toString()), “exercício”, t); // Pega o valor e adiciona no gráfico para gerar a linha
int temp = Integer.parseInt(t);
temp++;
t = Integer.toString(temp);
valores.add(Double.parseDouble(lm.getElementAt(i).toString()));
} catch (Exception e) {
}
}
return dataset;
}private void jButton4MouseClicked(java.awt.event.MouseEvent evt) {
t.stop(); // Para a Thread
jButton1.setEnabled(true); // Habilita o botão
s.fecharCOM(); // Fechar porta COM//JFreeChart grafico_Linha = ChartFactory.createAreaChart("Isometria", "Tempo", "Força", pegaDados()); JFreeChart grafico_Linha = ChartFactory.createLineChart("Isometria", "Tempo", "Força", pegaDados(), PlotOrientation.VERTICAL, true, true, false); File fl = new File("C:\\Users\\efer_\\Desktop\\teste.jpg"); try { ChartUtilities.saveChartAsJPEG(fl, grafico_Linha, jButton3.getWidth(), jButton3.getHeight()); // fl é o arquivo onde vai ser salvo // grafico_Linha é o gráfico // valor, valor é o tamanho } catch (IOException ex) { Logger.getLogger(exercicio_forca_iso_bilateral.class.getName()).log(Level.SEVERE, null, ex); } // Coloca o arquivo como imagem no botão Icon i = new ImageIcon("C:\\Users\\efer_\\Desktop\\teste.jpg"); jButton3.setIcon(i); // ------------------------------------- // Achar maior e menor valor double min = 0, max = 0, soma = 0; int j = 0; for (j = 0; j < valores.size(); j++) { if ((double) valores.get(j) > max) { max = (double) valores.get(j); } if ((double) valores.get(j) < min) { min = (double) valores.get(j); } soma += (double) valores.get(j); } jLabel2.setText(Double.toString(max)); jLabel4.setText(Double.toString(min)); String num = String.format("%.2f", soma / j); jLabel6.setText(num); // -------------------------------------
}
/**
-
@param args the command line arguments
/
public static void main(String args[]) {
/ Set the Nimbus look and feel /
//
/ If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.- For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if (“Nimbus”.equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(exercicio_forca_iso_bilateral.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(exercicio_forca_iso_bilateral.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(exercicio_forca_iso_bilateral.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(exercicio_forca_iso_bilateral.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//
//
//
//
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new exercicio_forca_iso_bilateral().setVisible(true);
}
});
} - For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JList jList1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextField txtData;
// End of variables declaration
} - Creates new form principal
"