A
A
AlexxTR2017-03-02 14:26:49
Java
AlexxTR, 2017-03-02 14:26:49

Why does nothing happen when trying to run a windows application via cmd with java?

Hello! I am learning to program in Java. I started reading a book that immediately asks you to configure cmd to work with Java: compiling .java into .class.
Simple text programs with conditions work fine. The class is compiled using the javac command, then run using the java command.
However, if the program needs to create a new window with buttons, then nothing happens, and the cursor simply moves to the trail. line. Is this normal or am I doing something wrong?
Sample code from the book, which should open a small window with a couple of buttons, directly from cmd:

import java.awt.*;
import java.awt.event.*;
class Party {
public void buildInvite() {
Frame f = new Frame() ;
Label l = new Label("Вечеринка у Тима");
Button b = newButton("Ваша вставка");
Button c = newButton("Сбросить");
Panel p = new Panel();
p.add(l);
}
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mercury13, 2017-03-02
@AlexxTR

Excuse me, where is the entry point? Where is main(String[])? Where is the AWT window loop run?
Well, window programs must be launched by the java program if you want to see the console, and javaw if you don’t want to.

Z
Zakharov Alexander, 2017-03-02
@AlexZaharow

Frame still needs to be shown on the screen, for example: docs.oracle.com/javase/tutorial/uiswing/components...
The "new Frame" operation does not display it on the screen. Imagine that you need to make an array of 100 frames. Is it really necessary to show them all when creating them?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question