
このプログラムは、ユーザーが決定した形状を取り、入力に基づいてそのサイズを変更するように設計されています。
2 つの問題があります。1 つは、ユーザーが文字列として入力する必要がありますが、サイズの値は整数です。整数を文字列に変換すると、変換時に null 例外が発生します。(java.lang.Integer.parseInt(Unknown Source)Exception))
もう 1 つの問題は、actionPerfomed メソッドに何を追加すればよいかわからないことです。すべての情報は paint メソッドに渡すだけでよいためです。整数値を Paint メソッドに転送するにはどうすればよいですか。
import java.io.*;
import java.util.*;
import java.text.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.applet.Applet;
public class ChangeSize extends Applet
    implements ActionListener
{
    Button bttn1 = new Button ("Circle");
    Button bttn2 = new Button ("Square");
    Button bttn3 = new Button ("Triangle");
    Button bttn4 = new Button ("Rectangle");
    Label lab1; // text within applet
    TextField t1; // where user inputs text
    String input;
    int choice;
    public void init ()
    {
        this.setSize (500, 300);
        setBackground (Color.lightGray);
        lab1 = new Label ("Insert the size of the shape:");
        //int Size = Integer.parseInt (input);
        add (lab1);
        t1 = new TextField ();
        add (t1);
        bttn1.addActionListener (this); // circle button
        bttn2.addActionListener (this); // square button
        bttn3.addActionListener (this); // triangle button
        bttn4.addActionListener (this); // rectangle button
        add (bttn1);
        add (bttn2);
        add (bttn3);
        add (bttn4);
    }
    public void paint (Graphics g)
    {
        int xpoints[] = {25, 145, 25, 145, 25}; \
        int ypoints[] = {25, 25, 145, 145, 25};
        int npoints = 5;
        switch (choice)
        {
            case 1:
                if (choice == 1)
                    g.setColor (Color.red);
                g.fillOval (30, 40, 20, 20); // I want it to be (30,40, 20, size). Instead
            case 2:
                if (choice == 2)
                    g.fillRect (20, 40, 100, 100);
            case 3:
                if (choice == 3)
                    g.fillPolygon (xpoints, ypoints, npoints);
            case 4:
                if (choice == 4)
                    g.fillRect (20, 40, 50, 100);
                break;
        }
        showStatus ("Please seclect an option.");
    }
    public void actionPerformed (ActionEvent evt)
    {
        if (evt.getSource () == bttn1)
            choice = 1;
        else if (evt.getSource () == bttn2)
            choice = 2;
        else if (evt.getSource () == bttn3)
            choice = 3;
        else if (evt.getSource () == bttn4)
            choice = 4;
          Size = t1.getText ();
          // I dont know what to put here
        repaint ();
    }
}