番号付きボタンのいずれかをクリックするまで、テキスト フィールドを非表示にしようとしています。これは初期の大まかな草案であるため、スペースの不足やコメントの欠如は無視してください。テキスト フィールドは inputField1 と呼ばれ、1 というラベルの付いたボタンをクリックすると表示されるように設定します。ありがとうございます。
import java.lang.String.*;
import java.lang.Exception.*;
import java.util.EventObject;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Airplanes extends JFrame implements ActionListener {
private static final int FRAME_WIDTH = 330;
private static final int FRAME_HEIGHT = 300;
private static final int FRAME_X_ORIGIN = 150;
private static final int FRAME_Y_ORIGIN = 300;
private static final int BUTTON_WIDTH = 50;
private static final int BUTTON_HEIGHT = 30;
private JTextField inputLine1;
private JButton oneButton;
private JButton twoButton;
private JButton threeButton;
private JButton fourButton;
private JButton fiveButton;
private JButton sixButton;
private JButton sevenButton;
private JButton eightButton;
private JButton nineButton;
private JButton tenButton;
private JButton elevenButton;
private JButton twelveButton;
public static void main(String[] args) {
Airplanes airplanes = new Airplanes();
airplanes.setVisible(true);
}
@SuppressWarnings("null")
public Airplanes() {
Container contentPane;
setSize(FRAME_WIDTH, FRAME_HEIGHT);
setResizable(false);
setTitle("Island Airways");
setLocation(FRAME_X_ORIGIN, FRAME_Y_ORIGIN);
contentPane = getContentPane();
contentPane.setLayout(null);
contentPane.setBackground(Color.white);
oneButton = new JButton("1");
oneButton.setBounds(10, 100, BUTTON_WIDTH, BUTTON_HEIGHT);
contentPane.add(oneButton);
twoButton = new JButton("2");
twoButton.setBounds(10, 140, BUTTON_WIDTH, BUTTON_HEIGHT);
contentPane.add(twoButton);
threeButton = new JButton("3");
threeButton.setBounds(60, 100, BUTTON_WIDTH, BUTTON_HEIGHT);
contentPane.add(threeButton);
fourButton = new JButton("4");
fourButton.setBounds(60, 140, BUTTON_WIDTH, BUTTON_HEIGHT);
contentPane.add(fourButton);
fiveButton = new JButton("5");
fiveButton.setBounds(110, 100, BUTTON_WIDTH, BUTTON_HEIGHT);
contentPane.add(fiveButton);
sixButton = new JButton("6");
sixButton.setBounds(110, 140, BUTTON_WIDTH, BUTTON_HEIGHT);
contentPane.add(sixButton);
sevenButton = new JButton("7");
sevenButton.setBounds(160, 100, BUTTON_WIDTH, BUTTON_HEIGHT);
contentPane.add(sevenButton);
eightButton = new JButton("8");
eightButton.setBounds(160, 140, BUTTON_WIDTH, BUTTON_HEIGHT);
contentPane.add(eightButton);
nineButton = new JButton("9");
nineButton.setBounds(210, 100, BUTTON_WIDTH, BUTTON_HEIGHT);
contentPane.add(nineButton);
tenButton = new JButton("10");
tenButton.setBounds(210, 140, BUTTON_WIDTH, BUTTON_HEIGHT);
contentPane.add(tenButton);
elevenButton = new JButton("11");
elevenButton.setBounds(260, 100, BUTTON_WIDTH, BUTTON_HEIGHT);
contentPane.add(elevenButton);
JButton twelveButton = new JButton("12");
twelveButton.setBounds(260, 140, BUTTON_WIDTH, BUTTON_HEIGHT);
contentPane.add(twelveButton);
JButton firstClass = new JButton("First Class");
firstClass.setBounds(50, 30, 100, 30);
contentPane.add(firstClass);
JButton coach = new JButton("Coach");
coach.setBounds(175, 30, 100, 30);
contentPane.add(coach);
inputLine1 = new JTextField();
inputLine1.setBounds(70, 200, 135, 30);
contentPane.add(inputLine1);
inputLine1.setVisible(false);
}
public void actionPerformed(ActionEvent event) {
if (event.getSource() instanceof JButton) {
JButton clickedButton = (JButton) event.getSource();
String buttonText = clickedButton.getText();
if (buttonText.equals("First Class")) {
inputLine1.setVisible(true);
if (buttonText.equals("1")) {
}
}
}
}
}