0

我建立

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);
      }
    }
  } 

这个类应该能够在标签上绘制一些东西。一开始,它只是画一条线和 2。但不幸的是,我无法第二次调用这个类来画椭圆?

那么我如何才能再次调用这个类并更新或更新JPanel它呢?


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");

        }
}
}

就是这个@GojiraDeMonstah

4

0 回答 0