Первая прога на Java
Формулировка задачи:
Всем привет! Начал изучать джаву и пока очень плохо разбираюсь, не могу собрать прогу из книжки java для детей, там вообще не описано что библиотеки надо добавлять. вот скрин. Помогите разобраться, пока не могу продвигаться дальше, без практики это бесполезно, не художественную литературу читаю.
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The type javax.swing.JComponent cannot be resolved. It is indirectly referenced from required .class files
The method setLayout(FlowLayout) is undefined for the type JPanel
The method add(JLabel) is undefined for the type JPanel
The method add(JTextField) is undefined for the type JPanel
The method add(JLabel) is undefined for the type JPanel
The method add(JTextField) is undefined for the type JPanel
The method add(JLabel) is undefined for the type JPanel
The method add(JTextField) is undefined for the type JPanel
The method add(JButton) is undefined for the type JPanel
The method setContentPane(Container) in the type JFrame is not applicable for the arguments (JPanel)
at SimpleCalculator001.main(SimpleCalculator001.java:15)
не могу скрин вставить, форум радикал блокирует.
вот код
import javax.swing.*; import java.awt.FlowLayout;// public class SimpleCalculator001 { /** * @param args */ public static void main(String[] args) { // Создаём панель JPanel windowContent= new JPanel(); // Задаём менеджер отображения для этой панели FlowLayout fl = new FlowLayout(); windowContent.setLayout(fl); // Создаём компоненты в памяти JLabel label1 = new JLabel("Number 1:"); JTextField field1 = new JTextField(10); JLabel label2 = new JLabel("Number 2:"); JTextField field2 = new JTextField(10); JLabel label3 = new JLabel("Sum:"); JTextField result = new JTextField(10); JButton go = new JButton("Add"); // Добавляем компоненты на панель windowContent.add(label1); windowContent.add(field1); windowContent.add(label2); windowContent.add(field2); windowContent.add(label3); windowContent.add(result); windowContent.add(go); // Создаём фрейм и задаём для него панель JFrame frame = new JFrame("My First Calculator"); frame.setContentPane(windowContent); // задаём и размер и делаем фрейм видимым frame.setSize(400,100); frame.setVisible(true); }
Решение задачи: «Первая прога на Java»
textual
Листинг программы
import java.awt.*;
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д