Hallo Community,
Warum zeigt das Label nichts an ?
Ich probiere jetzt schon eine Stunde daran rum, komme jedoch zu keiner Lösung;(
Danke
Warum zeigt das Label nichts an ?
Ich probiere jetzt schon eine Stunde daran rum, komme jedoch zu keiner Lösung;(
Java:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Geradengleichungv4 extends JFrame implements ActionListener {
JFrame Fenster;
Container Container;
JPanel Panelmiddle,Panelsouth,Panelnorth,Panelno;
JLabel Label1,Label2,Label3,Label4;
JButton Button1,Button2,Button3,Button4;
int Ax = 0,Ay = 0, Bx =0, By = 0, Cx=0,Cy=0;
double ab=0,ab1=0;
public Geradengleichungv4 (){
Fenster = new JFrame ();
Fenster.setTitle("Geradengleichung V4");
Fenster.setLayout(new GridLayout(9,800));
Container = Fenster.getContentPane();
Panelmiddle = new JPanel();
Panelsouth = new JPanel();
Panelnorth = new JPanel();
Panelno = new JPanel();
Button1 = new JButton ("Gleichung AB");
Button1.addActionListener (this);
Button2 = new JButton ("Gleichung BC");
Button2.addActionListener (this);
Button3 = new JButton ("Gleichung AC");
Button3.addActionListener (this);
Button4 = new JButton ("Alle Gleichungen");
Button4.addActionListener (this);
Label1 = new JLabel ();
//Label2 = new JLabel ();
//Label3 = new JLabel ();
//Label4 = new JLabel ();
Panelsouth.add(Button1);
Panelsouth.add(Button2);
Panelsouth.add(Button3);
Panelsouth.add(Button4);
Panelnorth.add(Label1);
//Panelnorth.add(Label2);
//Panelnorth.add(Label3);
//Panelno.add(Label4);
//Container.add(Panelmiddle, BorderLayout.CENTER);
//Container.add(Panelsouth, BorderLayout.SOUTH);
//Container.add(Panelnorth, BorderLayout.NORTH);
Fenster.add(Panelmiddle,BorderLayout.CENTER);
Fenster.add(Panelsouth, BorderLayout.SOUTH);
Fenster.add(Panelnorth, BorderLayout.NORTH);
//Fenster.add(Panelno,BorderLayout.NORTH);
Fenster.pack();
Fenster.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Fenster.setVisible(true);
}
public static void main(String[] args) {
new Geradengleichungv4();
String Eingabe1= JOptionPane.showInputDialog("Bitte Ax eingeben");
double Ax= Integer.parseInt(Eingabe1);
String Eingabe2= JOptionPane.showInputDialog("Bitte Ay eingeben");
double Ay= Integer.parseInt(Eingabe2);
String Eingabe3= JOptionPane.showInputDialog("Bitte Bx eingeben");
double Bx= Integer.parseInt(Eingabe3);
String Eingabe4= JOptionPane.showInputDialog("Bitte By eingeben");
double By= Integer.parseInt(Eingabe4);
String Eingabe5= JOptionPane.showInputDialog("Bitte Cx eingeben");
double Cx= Integer.parseInt(Eingabe5);
String Eingabe6= JOptionPane.showInputDialog("Bitte Cy eingeben");
double Cy= Integer.parseInt(Eingabe6);
}
public void actionPerformed(ActionEvent Ereignis) {
Object Quelle= Ereignis.getSource();
if (Quelle == Button1){
if (Ax<Bx)
{
ab1 = ((By-Ay)/(Bx-Ax));
ab = (ab1*(-Ax))+Ay;
//System.out.println(ab1+"x + "+ab);
}
if (Ax>Bx)
{
ab1=((Ay-By)/(Ax-Bx));
ab=(ab1*(-Ax))+Ay;
//System.out.println("klammer2");
}
if (ab1>0){
Label1
.setText("AB = y = "+Double.toString(ab1)+ " x + "+Double.toString(ab));
}
if (ab1<0){
Label1
.setText("AB = y = "+Double.toString(ab1)+ " x - "+Double.toString(ab));
}
}
}
}