Hallo liebe Forengemeinde,
nach stundenlanger Suche stecke ich in einem großen Problem fest.
Ich habe ein JTabbedPane mit drei unterschiedlichen Chartpaneln (JFreeChart).
Beim ersten Programmaufruf wird alles perfekt generiert, das Programm arbeitet genauso, wie es soll.
Das Problem entsteht, wenn ich neue Werte eingebe und das Pane quasi zum ersten mal aktualisieren will.
Es wird zwar korrekt gezeichnet, aber wenn ich auf ein Panel klicke, schaltet es sofort zum zuerst generierten um.... Woran kann das liegen?
Bitte verzeiht mir unter Umständen schwerwiegende Anfängerfehler.
Beste Grüße
nach stundenlanger Suche stecke ich in einem großen Problem fest.
Ich habe ein JTabbedPane mit drei unterschiedlichen Chartpaneln (JFreeChart).
Beim ersten Programmaufruf wird alles perfekt generiert, das Programm arbeitet genauso, wie es soll.
Das Problem entsteht, wenn ich neue Werte eingebe und das Pane quasi zum ersten mal aktualisieren will.
Es wird zwar korrekt gezeichnet, aber wenn ich auf ein Panel klicke, schaltet es sofort zum zuerst generierten um.... Woran kann das liegen?
Bitte verzeiht mir unter Umständen schwerwiegende Anfängerfehler.
Beste Grüße
Java:
package de.vogella.jfreechart.swing.pie;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.EventQueue;
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.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.function.PolynomialFunction2D;
import org.jfree.data.general.DatasetUtilities;
import org.jfree.data.xy.XYDataset;
import Jama.Matrix;
import javax.swing.JLayeredPane;
public class Window extends JFrame implements ActionListener{
/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTextField txt_s0;
private JTextField txt_s1;
private JTextField txt_erg;
private JTextField txt_erg2;
private JPanel panel1e;
private int zahl1 = 0;
private JLabel lblNewLabel;
private JLabel lblEingabeS;
private JTextField txt_v0;
private JTextField txt_v1;
private JLabel lblWertA;
private JTextField txt_a0;
private JLabel lblWertA_1;
private JTextField txt_a1;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Window frame = new Window();
//UIManager
//.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Window() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 701, 402);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JButton btnNewButton = new JButton("New button");
btnNewButton.setBounds(339, 324, 97, 29);
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
int s0, s1, v0, v1, a0, a1, erg ;
long Ka, Kb, Kc, Kd, Ke ,Kf, func;
char i;
s0=0;
s1=0;
v0=0;
v1=0;
a0=0;
a1=0;
erg=0;
Ka=0;Kb=0;Kc=0;Kd=0;Ke=0;Kf=0;
try
{
s0=Integer.parseInt(txt_s0.getText());
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "Keine Zahl im Feld s(0)", "ERROR", JOptionPane.ERROR_MESSAGE);
}
try
{
s1=Integer.parseInt(txt_s1.getText());
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "Keine Zahl im Feld s(1)", "ERROR", JOptionPane.ERROR_MESSAGE);
}
try
{
v0=Integer.parseInt(txt_v0.getText());
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "Keine Zahl im Feld v(0)", "ERROR", JOptionPane.ERROR_MESSAGE);
}
try
{
v1=Integer.parseInt(txt_v1.getText());
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "Keine Zahl im Feld v(1)", "ERROR", JOptionPane.ERROR_MESSAGE);
}
try
{
a0=Integer.parseInt(txt_a0.getText());
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "Keine Zahl im Feld a(0)", "ERROR", JOptionPane.ERROR_MESSAGE);
}
try
{
a1=Integer.parseInt(txt_a1.getText());
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "Keine Zahl im Feld a(1)", "ERROR", JOptionPane.ERROR_MESSAGE);
}
double[][] lhsArray = {{1, 0, 0, 0, 0, 0}, {0, 1, 0, 0, 0, 0}, {0, 0, 2, 0, 0, 0},
{1, 1, 1, 1, 1, 1}, {0, 1, 2, 3, 4, 5}, {0, 0, 2, 6, 12, 20}};
double[] rhsArray = {s0, v0, a0, s1, v1, a1};
//Creating Matrix Objects with arrays
Matrix lhs = new Matrix(lhsArray);
Matrix rhs = new Matrix(rhsArray, 6);
//Calculate Solved Matrix
Matrix ans = lhs.solve(rhs);
//Printing Answers
Ka=Math.round(ans.get(0, 0));
Kb=Math.round(ans.get(1, 0));
Kc=Math.round(ans.get(2, 0));
Kd=Math.round(ans.get(3, 0));
Ke=Math.round(ans.get(4, 0));
Kf=Math.round(ans.get(5, 0));
String str= ""+Ka +""+"+"+Kb+"*x^2"+"+"+Kc+"*x^3";
erg=s0*s0;
txt_erg.setText(""+erg);
//Chart-Beginn
PolynomialFunction2D normal1 = new PolynomialFunction2D(new double[] {Ka, Kb, Kc, Kd, Ke, Kf});
PolynomialFunction2D normal2 = new PolynomialFunction2D(new double[] {Kb,2*Kc,3*Kd,4*Ke,5*Kf});
PolynomialFunction2D normal3 = new PolynomialFunction2D(new double[] {2*Kc, 6*Kd, 12*Ke, 20*Kf});
XYDataset dataset1 = DatasetUtilities.sampleFunction2D(normal1, 0, 1, 100,"Function");
XYDataset dataset2 = DatasetUtilities.sampleFunction2D(normal2, 0, 1, 100,"Function");
XYDataset dataset3 = DatasetUtilities.sampleFunction2D(normal3, 0, 1, 100,"Function");
final JFreeChart chart1 = ChartFactory.createXYLineChart(
"",
"",
"s",
dataset1,
PlotOrientation.VERTICAL,
false,
true,
false
);
final JFreeChart chart2 = ChartFactory.createXYLineChart(
"",
"",
"v",
dataset2,
PlotOrientation.VERTICAL,
false,
true,
false
);
final JFreeChart chart3 = ChartFactory.createXYLineChart(
"",
"",
"a",
dataset3,
PlotOrientation.VERTICAL,
false,
true,
false
);
final ChartPanel chartPanel1 = new ChartPanel(chart1);
final ChartPanel chartPanel2 = new ChartPanel(chart2);
final ChartPanel chartPanel3 = new ChartPanel(chart3);
chartPanel1.setLayout(new CardLayout(0, 0));
chartPanel1.setPreferredSize(new java.awt.Dimension(350, 300));
JTabbedPane Funktionsverlauf1e = new JTabbedPane(JTabbedPane.TOP);
Funktionsverlauf1e.setBounds(78, 23, 590, 314);
Funktionsverlauf1e.add("Hubverlauf", chartPanel1);
Funktionsverlauf1e.add("Geschwindigkeitsverlauf", chartPanel2);
Funktionsverlauf1e.add("Beschleunigungsverlauf", chartPanel3);
Funktionsverlauf1e.add("Funktionen", null);
contentPane.add(Funktionsverlauf1e);
Funktionsverlauf1e.repaint();
}
});
contentPane.add(btnNewButton);
lblNewLabel = new JLabel("Wert s(0)");
lblNewLabel.setBounds(6, 20, 86, 16);
contentPane.add(lblNewLabel);
txt_s0 = new JTextField();
txt_s0.setBounds(6, 35, 60, 28);
contentPane.add(txt_s0);
txt_s0.setColumns(10);
lblEingabeS = new JLabel("Wert s(1)\n");
lblEingabeS.setBounds(6, 65, 86, 16);
contentPane.add(lblEingabeS);
txt_s1 = new JTextField();
txt_s1.setBounds(6, 80, 60, 28);
contentPane.add(txt_s1);
txt_s1.setColumns(10);
JLabel lblEingabeV = new JLabel("Wert v(0)");
lblEingabeV.setBounds(6, 130, 60, 16);
contentPane.add(lblEingabeV);
txt_v0 = new JTextField();
txt_v0.setBounds(6, 145, 60, 28);
contentPane.add(txt_v0);
txt_v0.setColumns(10);
JLabel lblWertV = new JLabel("Wert v(1)");
lblWertV.setBounds(6, 175, 60, 16);
contentPane.add(lblWertV);
txt_v1 = new JTextField();
txt_v1.setBounds(6, 190, 60, 28);
contentPane.add(txt_v1);
txt_v1.setColumns(10);
lblWertA = new JLabel("Wert a(0)");
lblWertA.setBounds(6, 240, 60, 16);
contentPane.add(lblWertA);
txt_a0 = new JTextField();
txt_a0.setBounds(6, 255, 60, 28);
contentPane.add(txt_a0);
txt_a0.setColumns(10);
lblWertA_1 = new JLabel("Wert a(1)");
lblWertA_1.setBounds(6, 285, 60, 16);
contentPane.add(lblWertA_1);
txt_a1 = new JTextField();
txt_a1.setBounds(6, 300, 60, 28);
contentPane.add(txt_a1);
txt_a1.setColumns(10);
txt_erg = new JTextField();
txt_erg.setBounds(140, 324, 134, 28);
contentPane.add(txt_erg);
txt_erg.setColumns(10);
}
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
}
}
Zuletzt bearbeitet: