I created
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
public class Painter extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(new Color(100,100,100));
g.drawLine(0, 0, 200, 200);
System.out.println("heir3");
System.out.println(Main.Array[0]);
if (Main.Array[0] == 1){
g.drawOval(100, 100, Main.Radint, Main.Radint);
System.out.println("heir8");
} else {
g.drawString("2", 150, 100);
}
}
}
This class which should be able to draw something on a Label. At the beginning, it´s just drawing a Line and the 2. But unfortunately I'm not able to call this class a second time to draw the the Oval?
So how am I able to call this class a second time and update or renew the JPanel
it's on ?
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class Buttons implements ActionListener {
public JButton Kreis = new JButton();
public JTextField Text = new JTextField();
Frame Fr = new Frame();
public JButton Kreis(){
Kreis.setText("Kreis");
Kreis.addActionListener(this);
return Kreis;
}
public JTextField TextField(){
Text.setPreferredSize(new Dimension(100,20));
return Text;
}
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (Kreis == source){
Main.Radius = Text.getText();
Main.Radint = Integer.parseInt(Main.Radius);
Main.Array[0] = 1;
Main.Array[1] = Main.Radint;
System.out.println("hier");
JPanel paint = new Painter();
Fr.changeFrame(paint);
System.out.println("hier");
}
}
}
It´s this one @GojiraDeMonstah