Код:
Код: Выделить всё
package com.example.inputoutputgui;
import java.awt.FlowLayout; //Imports classes for creating graphical user interfaces (GUIs).
import java.awt.event.ActionEvent; //Provides classes for creating and managing graphical user interface components.
import java.awt.event.ActionListener; //Provides interfaces for handling events, such as button clicks.
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
//Class Declaration
//----------------------------------------
//InputOutputGUI: The name of the class.
//extends JFrame: Inherits from the JFrame class, which is the base class for creating window-based applications
//implements ActionListener: Implements the ActionListener interface to handle button click events.
public class InputOutputGUI extends JFrame implements ActionListener {
private JTextField inputTextField; //Class Variable: A text field for user input.
private JButton generateButton; //Class Variable: A button to trigger the generation of output.
private JLabel outputLabel; //Class Variable: Provides interfaces for handling events, such as button clicks.
//Constructor
public InputOutputGUI() {
super("Generate hello message including your name"); //Sets the title of the window.
setLayout(new FlowLayout()); //Sets the layout manager for the window to FlowLayout, which arranges components horizontally.
//Component Creation and Initialization
//Creates instances of JTextField, JButton, and JLabel.
inputTextField = new JTextField(20);
generateButton = new JButton("Generate"); ////Sets the text of the button to "Generate".
outputLabel = new JLabel();
//Adds an action listener to the button, which will call the actionPerformed method when the button is clicked.
generateButton.addActionListener(this);
//Adding Components to the Frame
//Adds the text field, button, and label to the frame.
add(inputTextField);
add(generateButton);
add(outputLabel);
//Frame Configuration
setSize(300, 150); //Sets the size of the frame.
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Specifies that the application should exit when the frame is closed.
setVisible(true); //Makes the frame visible.
}
//Action Listener Method
//This method is called when the button is clicked.
//Gets the text from the input text field.
//Sets the text of the output label to a greeting message including the input text.
public void actionPerformed(ActionEvent e) {
String input = inputTextField.getText();
outputLabel.setText("Hello, " + input + "!");
}
//Main Method
//Creates an instance of the InputOutputGUI class, which starts the application.
public static void main(String[] args) {
new InputOutputGUI();
}
}
Код: Выделить всё
Hello-App/
src/
main/
java/
com/
example/
InputOutputGUI/
InputOutputGUI.java
я не нашел его

JDK установлен
Пакет расширений Java установлен

Домашняя страница Java:

Подробнее здесь: https://stackoverflow.com/questions/788 ... ing-vscode