Hallo
ich hab folgenden code schon mal hinbekomen
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class CFunkPlotter extends JFrame {
CMeineCanvas m_malflaeche;
int aktFunktion = 0;
public static void main(String[] args) {
CFunkPlotter fenster = new CFunkPlotter(„Funktionenplotter“);
fenster.pack();
fenster.setSize(350,400);
fenster.setResizable(false);
fenster.setVisible(true);
}
CFunkPlotter(String titel) {
super(titel);
setLayout(new FlowLayout());
m_malflaeche = new CMeineCanvas();
add(m_malflaeche);
JButton f1 = new JButton(„tan(x)“);
JButton f2 = new JButton(„x^3“);
JButton f3 = new JButton(„sin(x)“);
JButton f4 = new JButton(„cos(x)“);
JButton f5 = new JButton(„cotangens(x)“);
add(f1);
add(f2);
add(f3);
add(f4);
add(f5);
class CMeinActionLauscher implements ActionListener {
public void actionPerformed(ActionEvent e) {
String label;
label = e.getActionCommand();
if(label.equals(„tan(x)“))
aktFunktion = 2;
else if (label.equals(„x^3“))
aktFunktion = 1;
else if (label.equals(„sin(x)“))
aktFunktion = 3;
else if (label.equals(„cos(x)“))
aktFunktion = 4;
m_malflaeche.repaint();
}
}
f1.addActionListener(new CMeinActionLauscher());
f2.addActionListener(new CMeinActionLauscher());
f3.addActionListener(new CMeinActionLauscher());
f4.addActionListener(new CMeinActionLauscher());
f5.addActionListener(new CMeinActionLauscher());
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
class CMeineCanvas extends Canvas {
CMeineCanvas() {
setBackground(Color.black);
setForeground(Color.green);
}
public void paint(Graphics g) {
double x,y;
int xpos,ypos;
g.translate(150,150);
g.setColor(Color.red);
g.drawLine(0,-150,0,150);
g.drawLine(-150,0,150,0);
g.drawString("-3",-150,12);
g.drawString("-3",4,147);
g.drawString("+3",135,12);
g.drawString("+3",4,-140);
g.setColor(new Color(255,255,0));
if(aktFunktion == 0)
return;
for(x= -3.0; x