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 tema11; import java.awt.Toolkit; import static java.lang.Double.NaN; import javax.swing.JOptionPane; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartFrame; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.renderer.category.BarRenderer; import org.jfree.data.general.*; import org.jfree.data.xy.XYDataset; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; /** * * @author Zoli */ public class GUI extends javax.swing.JFrame { /** Creates new form GUI */ public GUI() { initComponents(); this.setTitle("Polinom calculator"); setImage(); setLocationRelativeTo(null); } /** 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() { TxPol1 = new javax.swing.JTextField(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); TxPol2 = new javax.swing.JTextField(); TxRes = new javax.swing.JTextField(); AddButton = new javax.swing.JButton(); SubButton = new javax.swing.JButton(); Deriv1Button = new javax.swing.JButton(); Deriv2Button = new javax.swing.JButton(); ValueButton1 = new javax.swing.JButton(); RootButton1 = new javax.swing.JButton(); jLabel4 = new javax.swing.JLabel(); TxValue = new javax.swing.JTextField(); jLabel5 = new javax.swing.JLabel(); TxGrad1 = new javax.swing.JTextField(); jLabel6 = new javax.swing.JLabel(); TxGrad2 = new javax.swing.JTextField(); TxInitVal = new javax.swing.JTextField(); jLabel7 = new javax.swing.JLabel(); ValueButton2 = new javax.swing.JButton(); RootButton2 = new javax.swing.JButton(); MultButton = new javax.swing.JButton(); DivButton = new javax.swing.JButton(); jLabel8 = new javax.swing.JLabel(); jLabel9 = new javax.swing.JLabel(); PlotButton1 = new javax.swing.JButton(); PlotButton2 = new javax.swing.JButton(); PlotResultButton = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); TxPol1.setNextFocusableComponent(TxGrad2); TxPol1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { TxPol1ActionPerformed(evt); } }); getContentPane().add(TxPol1, new org.netbeans.lib.awtextra.AbsoluteConstraints(320, 40, 285, -1)); jLabel1.setText("Polinom1:"); getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 40, -1, -1)); jLabel2.setText("Polinom2:"); getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 80, -1, -1)); jLabel3.setText("Result:"); getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(270, 120, -1, -1)); TxPol2.setNextFocusableComponent(TxInitVal); getContentPane().add(TxPol2, new org.netbeans.lib.awtextra.AbsoluteConstraints(320, 80, 285, -1)); TxRes.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { TxResActionPerformed(evt); } }); getContentPane().add(TxRes, new org.netbeans.lib.awtextra.AbsoluteConstraints(320, 120, 285, -1)); AddButton.setText("Add"); AddButton.setNextFocusableComponent(SubButton); AddButton.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { AddButtonMouseClicked(evt); } }); getContentPane().add(AddButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(23, 218, -1, -1)); SubButton.setText("Sub"); SubButton.setNextFocusableComponent(Deriv1Button); SubButton.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { SubButtonMouseClicked(evt); } }); getContentPane().add(SubButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(23, 259, -1, -1)); Deriv1Button.setText("Deriv1"); Deriv1Button.setNextFocusableComponent(Deriv2Button); Deriv1Button.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { Deriv1ButtonActionPerformed(evt); } }); getContentPane().add(Deriv1Button, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 220, -1, -1)); Deriv2Button.setText("Deriv2"); Deriv2Button.setNextFocusableComponent(ValueButton1); Deriv2Button.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { Deriv2ButtonActionPerformed(evt); } }); getContentPane().add(Deriv2Button, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 260, -1, -1)); ValueButton1.setText("Value1"); ValueButton1.setNextFocusableComponent(ValueButton2); ValueButton1.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { ValueButton1MouseClicked(evt); } }); getContentPane().add(ValueButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 220, -1, -1)); RootButton1.setText("Root1"); RootButton1.setNextFocusableComponent(RootButton2); RootButton1.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { RootButton1MouseClicked(evt); } }); RootButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { none(evt); } }); getContentPane().add(RootButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(410, 220, -1, -1)); jLabel4.setText("X:"); getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 160, -1, -1)); TxValue.setNextFocusableComponent(AddButton); getContentPane().add(TxValue, new org.netbeans.lib.awtextra.AbsoluteConstraints(320, 160, 285, -1)); jLabel5.setText("Grad1:"); getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 60, -1, 20)); TxGrad1.setNextFocusableComponent(TxPol1); getContentPane().add(TxGrad1, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 60, 103, -1)); TxGrad1.requestDefaultFocus(); jLabel6.setText("Grad2:"); getContentPane().add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 100, -1, -1)); TxGrad2.setNextFocusableComponent(TxPol2); getContentPane().add(TxGrad2, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 100, 103, -1)); TxInitVal.setNextFocusableComponent(TxValue); getContentPane().add(TxInitVal, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 140, 103, -1)); jLabel7.setText("Initial value:"); getContentPane().add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 140, -1, -1)); ValueButton2.setText("Value2"); ValueButton2.setNextFocusableComponent(RootButton1); ValueButton2.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { ValueButton2MouseClicked(evt); } }); getContentPane().add(ValueButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 260, -1, -1)); RootButton2.setText("Root2"); RootButton2.setNextFocusableComponent(MultButton); RootButton2.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { RootButton2MouseClicked(evt); } }); getContentPane().add(RootButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(410, 260, -1, -1)); MultButton.setText("Mult"); MultButton.setNextFocusableComponent(DivButton); MultButton.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { MultButtonMouseClicked(evt); } }); MultButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { MultButtonActionPerformed(evt); } }); getContentPane().add(MultButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(520, 220, -1, -1)); DivButton.setText("Div"); DivButton.setNextFocusableComponent(PlotButton1); DivButton.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { DivButtonMouseClicked(evt); } }); getContentPane().add(DivButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(520, 260, 53, -1)); getContentPane().add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(266, 16, 44, 21)); jLabel9.setIcon(new javax.swing.ImageIcon("C:\\Users\\Zoli\\Desktop\\alg_polynomial.png")); // NOI18N getContentPane().add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 620, 310)); PlotButton1.setText("Plot1"); PlotButton1.setNextFocusableComponent(PlotButton2); PlotButton1.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { PlotButton1MouseClicked(evt); } }); getContentPane().add(PlotButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 190, 90, -1)); PlotButton2.setText("Plot2"); PlotButton2.setNextFocusableComponent(PlotResultButton); PlotButton2.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { PlotButton2MouseClicked(evt); } }); getContentPane().add(PlotButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(410, 190, 90, -1)); PlotResultButton.setText("PlotResult"); PlotResultButton.setNextFocusableComponent(TxRes); PlotResultButton.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { PlotResultButtonMouseClicked(evt); } }); getContentPane().add(PlotResultButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(520, 190, 90, -1)); pack(); }// </editor-fold>//GEN-END:initComponents private void TxPol1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TxPol1ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_TxPol1ActionPerformed private void TxResActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TxResActionPerformed // TODO add your handling code here: }//GEN-LAST:event_TxResActionPerformed private void AddButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_AddButtonMouseClicked TxRes.setText(" "); String p1, p2 = new String(); p1 = TxPol1.getText(); p2 = TxPol2.getText(); int g1, g2; try { g1 = Integer.parseInt(TxGrad1.getText()); g2 = Integer.parseInt(TxGrad2.getText()); Polinom pol = new AddPol(PolinomOperations.parseString(p1, g1), PolinomOperations.parseString(p2, g2)); int[] rez = pol.Op(); TxRes.setText(pol.toString(rez)); } catch (NumberFormatException e) { JOptionPane.showMessageDialog(this, "Wrong polinom format", "Polinom Error", JOptionPane.ERROR_MESSAGE); } }//GEN-LAST:event_AddButtonMouseClicked private void SubButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_SubButtonMouseClicked TxRes.setText(" "); String p1, p2 = new String(); p1 = TxPol1.getText(); p2 = TxPol2.getText(); int g1, g2; try { g1 = Integer.parseInt(TxGrad1.getText()); g2 = Integer.parseInt(TxGrad2.getText()); Polinom pol = new SubPol(PolinomOperations.parseString(p1, g1), PolinomOperations.parseString(p2, g2)); int[] rez = pol.Op(); TxRes.setText(pol.toString(rez)); } catch (NumberFormatException e) { JOptionPane.showMessageDialog(this, "Wrong polinom format", "Polinom Error", JOptionPane.ERROR_MESSAGE); } }//GEN-LAST:event_SubButtonMouseClicked private void Deriv1ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Deriv1ButtonActionPerformed TxRes.setText(" "); String p1, p2 = new String(); p1 = TxPol1.getText(); p2 = TxPol2.getText(); int g1, g2; try { g1 = Integer.parseInt(TxGrad1.getText()); g2 = Integer.parseInt(TxGrad2.getText()); DerivPol pol = new DerivPol(PolinomOperations.parseString(p1, g1), PolinomOperations.parseString(p2, g2)); int[] rez = pol.deriv(PolinomOperations.parseString(p1, g1)); TxRes.setText(pol.toString(rez)); } catch (Exception e) { JOptionPane.showMessageDialog(this, "Wrong polinom format", "Polinom Error", JOptionPane.ERROR_MESSAGE); } }//GEN-LAST:event_Deriv1ButtonActionPerformed private void Deriv2ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Deriv2ButtonActionPerformed TxRes.setText(" "); String p1, p2 = new String(); p1 = TxPol1.getText(); p2 = TxPol2.getText(); int g1, g2; try { g1 = Integer.parseInt(TxGrad1.getText()); g2 = Integer.parseInt(TxGrad2.getText()); DerivPol pol = new DerivPol(PolinomOperations.parseString(p1, g1), PolinomOperations.parseString(p2, g2)); int[] rez = pol.deriv(PolinomOperations.parseString(p2, g2)); TxRes.setText(pol.toString(rez)); } catch (Exception e) { JOptionPane.showMessageDialog(this, "Wrong polinom format", "Polinom Error", JOptionPane.ERROR_MESSAGE); } }//GEN-LAST:event_Deriv2ButtonActionPerformed private void none(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_none }//GEN-LAST:event_none private void ValueButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ValueButton2MouseClicked TxRes.setText(" "); String p2 = new String(); p2 = TxPol2.getText(); int g2; int[] pol; double x; try { x = Double.parseDouble(TxValue.getText()); g2 = Integer.parseInt(TxGrad2.getText()); pol = PolinomOperations.parseString(p2, g2); TxRes.setText(String.valueOf(PolinomOperations.findValue(pol, x))); } catch (NumberFormatException e) { JOptionPane.showMessageDialog(this, "Introduceti o valoare numerica pentru X", "Polinom Error", JOptionPane.ERROR_MESSAGE); } catch (Exception e) { JOptionPane.showMessageDialog(this, e.getMessage(), "Polinom Error", JOptionPane.ERROR_MESSAGE); } }//GEN-LAST:event_ValueButton2MouseClicked private void ValueButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ValueButton1MouseClicked TxRes.setText(" "); String p1 = new String(); p1 = TxPol1.getText(); int g1; int[] pol; double x; try { x = Double.parseDouble(TxValue.getText()); g1 = Integer.parseInt(TxGrad1.getText()); pol = PolinomOperations.parseString(p1, g1); TxRes.setText(String.valueOf(PolinomOperations.findValue(pol, x))); System.out.println(PolinomOperations.findValue(pol, x)); } catch (NumberFormatException e) { JOptionPane.showMessageDialog(this, "Introduceti o valoare numerica pentru X", "Polinom Error", JOptionPane.ERROR_MESSAGE); } catch (Exception e) { JOptionPane.showMessageDialog(this, e.getMessage(), "Polinom Error", JOptionPane.ERROR_MESSAGE); } }//GEN-LAST:event_ValueButton1MouseClicked private void RootButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_RootButton1MouseClicked TxRes.setText(" "); String p1 = new String(); p1 = TxPol1.getText(); int g1; int[] pol; double init; try { init = Double.parseDouble(TxInitVal.getText()); g1 = Integer.parseInt(TxGrad1.getText()); pol = PolinomOperations.parseString(p1, g1); Func f = new Func(pol); double x; x = PolinomOperations.findRoots(f, init); if (x != NaN) { String s = String.valueOf(x); // s = s.substring(0, 4); TxRes.setText(s); } } catch (NumberFormatException e) { JOptionPane.showMessageDialog(this, "Introduceti o valoare initiala numerica", "Polinom Error", JOptionPane.ERROR_MESSAGE); } catch (Exception e) { JOptionPane.showMessageDialog(this, e.getMessage(), "Polinom Error", JOptionPane.ERROR_MESSAGE); } // System.out.println(PolinomOperations.findValue(pol, init)); }//GEN-LAST:event_RootButton1MouseClicked private void RootButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_RootButton2MouseClicked TxRes.setText(" "); String p1 = new String(); p1 = TxPol2.getText(); int g1; int[] pol; double init; try { init = Double.parseDouble(TxInitVal.getText()); g1 = Integer.parseInt(TxGrad2.getText()); pol = PolinomOperations.parseString(p1, g1); Func f = new Func(pol); double x; x = PolinomOperations.findRoots(f, init); if (x != NaN) { String s = String.valueOf(x); //s = s.substring(0, 4); TxRes.setText(s); } } catch (NumberFormatException e) { JOptionPane.showMessageDialog(this, "Introduceti o valoare initiala numerica", "Polinom Error", JOptionPane.ERROR_MESSAGE); } catch (Exception e) { JOptionPane.showMessageDialog(this, e.getMessage(), "Polinom Error", JOptionPane.ERROR_MESSAGE); } }//GEN-LAST:event_RootButton2MouseClicked private void MultButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MultButtonActionPerformed // TODO add your handling code here: }//GEN-LAST:event_MultButtonActionPerformed private void MultButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_MultButtonMouseClicked TxRes.setText(" "); String p1, p2 = new String(); p1 = TxPol1.getText(); p2 = TxPol2.getText(); int g1, g2; int[] coef1, coef2; try { g1 = Integer.parseInt(TxGrad1.getText()); g2 = Integer.parseInt(TxGrad2.getText()); coef1 = PolinomOperations.parseString(p1, g1); coef2 = PolinomOperations.parseString(p2, g2); Polinom pol = new MultPol(coef1, coef2); int[] rez = pol.Op(); TxRes.setText(pol.toString(rez)); } catch (Exception e) { JOptionPane.showMessageDialog(this, "Wrong polinom format", "Polinom Error", JOptionPane.ERROR_MESSAGE); } }//GEN-LAST:event_MultButtonMouseClicked private void DivButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_DivButtonMouseClicked TxRes.setText(" "); String p1, p2 = new String(); p1 = TxPol1.getText(); p2 = TxPol2.getText(); int g1, g2; int[] coef1, coef2; try { g1 = Integer.parseInt(TxGrad1.getText()); g2 = Integer.parseInt(TxGrad2.getText()); coef1 = PolinomOperations.parseString(p1, g1); coef2 = PolinomOperations.parseString(p2, g2); Polinom pol = new DivPol(coef1, coef2); int[] rez = pol.Op(); TxRes.setText(pol.toString(rez)); } catch (Exception e) { JOptionPane.showMessageDialog(this, "Wrong polinom format", "Polinom Error", JOptionPane.ERROR_MESSAGE); } }//GEN-LAST:event_DivButtonMouseClicked private void PlotButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_PlotButton1MouseClicked //TxRes.setText(" "); String p1, p2 = new String(); p1 = TxPol1.getText(); //p2 = TxPol2.getText(); int g1; int[] coef1; // g2 = Integer.parseInt(TxGrad2.getText()); try { g1 = Integer.parseInt(TxGrad1.getText()); coef1 = PolinomOperations.parseString(p1, g1); //coef2 = PolinomOperations.parseString(p1, g1); String chartTitle = "Object Movement Chart"; String xAxisLabel = "X"; String yAxisLabel = "Y"; XYDataset dataset = createDataset(coef1); JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, xAxisLabel, yAxisLabel, dataset); BarRenderer renderer = null; CategoryPlot plot = null; renderer = new BarRenderer(); ChartFrame myFrame = new ChartFrame("Polinom chart", chart); myFrame.setLocation(200, 200); myFrame.setSize(400, 400); myFrame.setVisible(true); } catch (Exception e) { JOptionPane.showMessageDialog(this, "Wrong polinom format", "Polinom Error", JOptionPane.ERROR_MESSAGE); } }//GEN-LAST:event_PlotButton1MouseClicked private void PlotButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_PlotButton2MouseClicked //TxRes.setText(" "); String p1, p2 = new String(); p1 = TxPol2.getText(); //p2 = TxPol2.getText(); int g1; int[] coef1; // g2 = Integer.parseInt(TxGrad2.getText()); try { g1 = Integer.parseInt(TxGrad2.getText()); coef1 = PolinomOperations.parseString(p1, g1); //coef2 = PolinomOperations.parseString(p1, g1); String chartTitle = "Object Movement Chart"; String xAxisLabel = "X"; String yAxisLabel = "Y"; XYDataset dataset = createDataset(coef1); JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, xAxisLabel, yAxisLabel, dataset); BarRenderer renderer = null; CategoryPlot plot = null; renderer = new BarRenderer(); ChartFrame myFrame = new ChartFrame("Polinom chart", chart); myFrame.setLocation(200, 200); myFrame.setSize(400, 400); myFrame.setVisible(true); } catch (Exception e) { JOptionPane.showMessageDialog(this, "Wrong polinom format", "Polinom Error", JOptionPane.ERROR_MESSAGE); } }//GEN-LAST:event_PlotButton2MouseClicked private void PlotResultButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_PlotResultButtonMouseClicked // TxRes.setText(" "); String p1, p2 = new String(); p1 = TxRes.getText(); //p2 = TxPol2.getText(); int g1, g2; int[] coef1; // g2 = Integer.parseInt(TxGrad2.getText()); try { g1 = Integer.parseInt(TxGrad1.getText()); g2 = Integer.parseInt(TxGrad2.getText()); coef1 = PolinomOperations.parseString(p1, g1 + g2); //coef2 = PolinomOperations.parseString(p1, g1); String chartTitle = "Object Movement Chart"; String xAxisLabel = "X"; String yAxisLabel = "Y"; XYDataset dataset = createDataset(coef1); JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, xAxisLabel, yAxisLabel, dataset); BarRenderer renderer = null; CategoryPlot plot = null; renderer = new BarRenderer(); ChartFrame myFrame = new ChartFrame("Result Polinom chart", chart); myFrame.setLocation(200, 200); myFrame.setSize(400, 400); myFrame.setVisible(true); } catch (Exception e) { JOptionPane.showMessageDialog(this, "Wrong polinom format! Va rog sa editati rezultatul si in locul coeficientului liber adaugati astfel coef_liberx^0 (exemplu in loc de 5 scrieti 5x^0)", "Polinom Error", JOptionPane.ERROR_MESSAGE); } }//GEN-LAST:event_PlotResultButtonMouseClicked /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* 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(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new GUI().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton AddButton; private javax.swing.JButton Deriv1Button; private javax.swing.JButton Deriv2Button; private javax.swing.JButton DivButton; private javax.swing.JButton MultButton; private javax.swing.JButton PlotButton1; private javax.swing.JButton PlotButton2; private javax.swing.JButton PlotResultButton; private javax.swing.JButton RootButton1; private javax.swing.JButton RootButton2; private javax.swing.JButton SubButton; private javax.swing.JTextField TxGrad1; private javax.swing.JTextField TxGrad2; private javax.swing.JTextField TxInitVal; private javax.swing.JTextField TxPol1; private javax.swing.JTextField TxPol2; private javax.swing.JTextField TxRes; private javax.swing.JTextField TxValue; private javax.swing.JButton ValueButton1; private javax.swing.JButton ValueButton2; private javax.swing.JLabel jLabel1; 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; // End of variables declaration//GEN-END:variables private void setImage() { setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("calc_icon.png"))); } private XYDataset createDataset(int[] a) { XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries series1 = new XYSeries("Polinom de grad max" + (a.length - 1)); // XYSeries series2 = new XYSeries("Polinom 2"); for (int i = -50; i < 50; i++) { double y = PolinomOperations.findValue(a, i); series1.add(i, y); } /* for (int i=0;i<50;i++) { double y = PolinomOperations.findValue(b, i); series2.add(i, y); }*/ dataset.addSeries(series1); // dataset.addSeries(series2); return dataset; } }